From 9294fec84739d0f3a0f7822f669e8b8e1a3fa4ee Mon Sep 17 00:00:00 2001 From: Lee Date: Wed, 18 Oct 2023 16:50:21 +0200 Subject: [PATCH] feat(moved over more tests from original repo) Co-authored-by: Sebastian Palmqvist --- .../lib/parse/__tests__/calendar.test.ts | 74 ++++ .../lib/parse/__tests__/children.test.ts | 43 +++ .../lib/parse/__tests__/classmates.test.ts | 72 ++++ .../lib/parse/__tests__/index.test.ts | 32 ++ .../lib/parse/__tests__/menu.test.ts | 91 +++++ .../lib/parse/__tests__/news.test.ts | 330 ++++++++++++++++++ .../lib/parse/__tests__/notifications.test.ts | 64 ++++ .../lib/parse/__tests__/schedule.test.ts | 47 +++ .../parse/__tests__/schoolContacts.test.ts | 50 +++ .../lib/parse/__tests__/teachers.test.ts | 68 ++++ .../lib/parse/__tests__/timetable.test.ts | 147 ++++++++ .../lib/parse/__tests__/user.test.ts | 27 ++ 12 files changed, 1045 insertions(+) create mode 100644 apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/calendar.test.ts create mode 100644 apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/children.test.ts create mode 100644 apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/classmates.test.ts create mode 100644 apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/index.test.ts create mode 100644 apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/menu.test.ts create mode 100644 apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/news.test.ts create mode 100644 apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/notifications.test.ts create mode 100644 apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/schedule.test.ts create mode 100644 apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/schoolContacts.test.ts create mode 100644 apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/teachers.test.ts create mode 100644 apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/timetable.test.ts create mode 100644 apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/user.test.ts diff --git a/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/calendar.test.ts b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/calendar.test.ts new file mode 100644 index 000000000..3556621a8 --- /dev/null +++ b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/calendar.test.ts @@ -0,0 +1,74 @@ +import { EtjanstResponse } from '../' +import { calendar } from '../calendar' + +let response: EtjanstResponse + +beforeEach(() => { + response = { + Success: true, + Error: null, + Data: [ + { + Title: 'Jullov', + Id: 29, + Description: 'hello', + Location: null, + EventDate: '2020-12-21', + EventDateTime: '09:00', + LongEventDateTime: '2020-12-21 09:00', + EndDate: '2021-01-08', + EndDateTime: '10:00', + LongEndDateTime: '2021-01-08 10:00', + EventDateDayNumber: '21', + EventDateMonthName: 'dec', + EventDateMonthFullName: 'december', + FullDateDescription: '2020-12-21 09:00 - 2021-01-08 10:00', + IsSameDay: false, + AllDayEvent: false, + ListId: null, + Mentor: null, + }, + { + Title: 'Utvecklingsdag, förskolorna är stängda', + Id: 5, + Description: null, + Location: null, + EventDate: '2021-05-28', + EventDateTime: '', + LongEventDateTime: '2021-05-28', + EndDate: '2021-05-28', + EndDateTime: '', + LongEndDateTime: '2021-05-28', + EventDateDayNumber: '28', + EventDateMonthName: 'maj', + EventDateMonthFullName: 'maj', + FullDateDescription: '2021-05-28 - 2021-05-28', + IsSameDay: true, + AllDayEvent: true, + ListId: null, + Mentor: null, + }, + ], + } +}) + +it('parses calendar correctly', () => { + const [firstEvent] = calendar(response) + + expect(firstEvent).toEqual({ + id: 29, + location: null, + title: 'Jullov', + description: 'hello', + startDate: '2020-12-21T08:00:00.000Z', + endDate: '2021-01-08T09:00:00.000Z', + allDay: false, + }) +}) + +it('parses start and end date without time', () => { + const [, secondEvent] = calendar(response) + + expect(secondEvent.startDate).toEqual('2021-05-27T22:00:00.000Z') + expect(secondEvent.endDate).toEqual('2021-05-27T22:00:00.000Z') +}) diff --git a/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/children.test.ts b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/children.test.ts new file mode 100644 index 000000000..d685f59ac --- /dev/null +++ b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/children.test.ts @@ -0,0 +1,43 @@ +import { EtjanstResponse } from '../' +import { children } from '../children' + +let response: EtjanstResponse + +beforeEach(() => { + response = { + Success: true, + Error: null, + Data: [ + { + Name: 'Some name', + Id: '42C3997E-D772-423F-9290-6FEEB3CB2DA7', + SDSId: '786E3393-F044-4660-9105-B444DEB289AA', + Status: 'GR', + UserType: 'Student', + SchoolId: 'DE2E1293-0F40-4B91-9D91-1E99355DC257', + SchoolName: null, + GroupId: null, + GroupName: null, + Classes: + 'VHsidan_0495CABC-77DB-41D7-824B-8B4D63E50D15;Section_AD1BB3B2-C1EE-4DFE-8209-CB6D42CE23D7;Section_0E67D0BF-594C-4C1B-9291-E753926DCD40;VHsidan_1C94EC54-9798-401C-B973-2454246D95DA', + isSameSDSId: false, + ResultUnitId: null, + ResultUnitName: null, + UnitId: null, + UnitName: null, + }, + ], + } +}) + +it('parses children correctly', () => { + expect(children(response)).toEqual([ + { + name: 'Some name', + id: '42C3997E-D772-423F-9290-6FEEB3CB2DA7', + sdsId: '786E3393-F044-4660-9105-B444DEB289AA', + schoolId: 'DE2E1293-0F40-4B91-9D91-1E99355DC257', + status: 'GR', + }, + ]) +}) diff --git a/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/classmates.test.ts b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/classmates.test.ts new file mode 100644 index 000000000..a86f1ad9b --- /dev/null +++ b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/classmates.test.ts @@ -0,0 +1,72 @@ +import { EtjanstResponse } from '../' +import { classmates } from '../classmates' + +let response: EtjanstResponse + +beforeEach(() => { + response = { + Success: true, + Error: null, + Data: [ + { + ID: 0, + BATCH: null, + SIS_ID: '22F0CFC7-09C7-45DC-9388-AE9A9EA1356B', + USERNAME: null, + SCHOOL_SIS_ID: null, + EMAILADDRESS: null, + STATUS: null, + ERRORCODE: 0, + PRIMARY_SCHOOL_SIS_ID: null, + MENTOR_SIS_ID: null, + FIRSTNAME: 'Bo', + LASTNAME: 'Burström', + ACTIVE: false, + Guardians: [ + { + SOCIALNUMBER: null, + DISPLAYNAME: null, + FIRSTNAME: 'Allan', + LASTNAME: 'Fridell', + ADDRESS: 'Hult södregård', + CITY: null, + POCODE: null, + TELHOME: null, + TELMOBILE: '0690-6346216', + EMAILHOME: 'allan.fridell@mailinater.com', + SECTION_NAME: null, + SECTION_ID: null, + TERM_STARTDATE: null, + TERM_ENDDATE: null, + GROUPTYPE: null, + STUDENT_FIRSTNAME: null, + STUDENT_LASTNAME: null, + STUDENT_ID: null, + }, + ], + ClassName: '7C', + ClassId: 'B2BF465B-581B-43AC-9CA7-F11BB0ED4646', + }, + ], + } +}) + +it('parses class mates correctly', () => { + expect(classmates(response)).toEqual([ + { + sisId: '22F0CFC7-09C7-45DC-9388-AE9A9EA1356B', + firstname: 'Bo', + lastname: 'Burström', + className: '7C', + guardians: [ + { + firstname: 'Allan', + lastname: 'Fridell', + address: 'Hult södregård', + mobile: '0690-6346216', + email: 'allan.fridell@mailinater.com', + }, + ], + }, + ]) +}) diff --git a/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/index.test.ts b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/index.test.ts new file mode 100644 index 000000000..794370b6c --- /dev/null +++ b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/index.test.ts @@ -0,0 +1,32 @@ +import * as parse from '../' + +let response: parse.EtjanstResponse + +describe('etjanst', () => { + beforeEach(() => { + response = { + Success: true, + Error: null, + Data: [ + { + Name: 'Some name', + }, + ], + } + }) + + it('returns data on success', () => { + expect(parse.etjanst(response)).toBeInstanceOf(Array) + }) + + it('throws error on Error', () => { + response.Success = false + response.Error = 'b0rk' + expect(() => parse.etjanst(response)).toThrowError('b0rk') + }) + + it('camelCases data keys', () => { + const parsed = parse.etjanst(response) + expect(parsed[0].name).toEqual(response.Data[0].Name) + }) +}) diff --git a/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/menu.test.ts b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/menu.test.ts new file mode 100644 index 000000000..157d9b2f6 --- /dev/null +++ b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/menu.test.ts @@ -0,0 +1,91 @@ +import { EtjanstResponse } from '../' +import { menu, menuList } from '../menu' + +let response: EtjanstResponse + +describe('menu', () => { + beforeEach(() => { + response = { + Success: true, + Error: null, + Data: [ + { + Title: 'Måndag - Vecka 52', + Description: 'Körrfärsrätt .
Veg färs', + }, + ], + } + }) + it(' menu correctly', () => { + expect(menu(response)).toEqual([ + { + title: 'Måndag - Vecka 52', + description: 'Körrfärsrätt .\nVeg färs', + }, + ]) + }) +}) + +describe('menu-list', () => { + beforeEach(() => { + response = { + Success: true, + Error: null, + Data: { + SelectedWeek: 12, + Menus: [ + { + Week: '12', + Mon: 'Köttfärslimpa med sås och potatis', + Tue: 'Curryfisk med ris', + Wed: 'Tagliatelle med vegetarisk sås', + Thu: 'Chorizo med stuvad potatis', + Fri: 'Ört och vitlöksinbakad fisk, potatis', + }, + { + Week: '19', + Mon: 'FISKGRATÄNG WALEWSKA', + Tue: 'STEKT FLÄSK MED RAGGMUNK', + Wed: 'PENNEPASTA MED TONFISK', + Thu: 'KÖTTGRYTA MED POTATIS', + Fri: 'GRÖNSAKSGRATÄNG MED TZATZIKI', + }, + { + Week: '20', + Mon: 'SPAGHETTI SALMONE ', + Tue: 'STEKT FALUKORV MED SENAPSSÅS OCH POTATIS', + Wed: 'SOPPA MED RISONI OCH HEMBAKAT BRÖD', + Thu: 'PANERAD FISK MED SKAGEN OCH POTATIS', + Fri: 'TACOS', + }, + ], + }, + } + }) + it(' menu correctly', () => { + const result = menuList(response) + + expect(result).toEqual([ + { + title: 'Måndag - Vecka 12', + description: 'Köttfärslimpa med sås och potatis', + }, + { + title: 'Tisdag - Vecka 12', + description: 'Curryfisk med ris', + }, + { + title: 'Onsdag - Vecka 12', + description: 'Tagliatelle med vegetarisk sås', + }, + { + title: 'Torsdag - Vecka 12', + description: 'Chorizo med stuvad potatis', + }, + { + title: 'Fredag - Vecka 12', + description: 'Ört och vitlöksinbakad fisk, potatis', + }, + ]) + }) +}) diff --git a/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/news.test.ts b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/news.test.ts new file mode 100644 index 000000000..a652de83a --- /dev/null +++ b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/news.test.ts @@ -0,0 +1,330 @@ +import { EtjanstResponse } from '../' +import { news, newsItemDetails } from '../news' + +let response: EtjanstResponse + +describe('news', () => { + describe('parsing', () => { + beforeEach(() => { + response = { + Success: true, + Error: null, + Data: { + CurrentChild: null, + NewsItems: [ + { + NewsId: 'news id', + SiteId: + 'elevstockholm.sharepoint.com,27892ACC-BA2E-4DEC-97B8-25F7098C3BF6,A239466A-9A52-42FF-8A3F-D94C342F2700', + NewsListId: '3EC323A1-EA16-4D24-84C8-DAA49E76F9F4', + NewsItemId: + 'elevstockholm.sharepoint.com,27892ACC-BA2E-4DEC-97B8-25F7098C3BF6,A239466A-9A52-42FF-8A3F-D94C342F2700_99', + Header: + 'Problemet med att se betyg i bild, slöjd och teknik löst!', + PublicationDate: '/Date(1608304542000)/', + PubDateSE: '18 december 2020 16:15', + ModifiedDate: '/Date(1608304680000)/', + ModDateSE: '18 december 2020 16:18', + Source: 'Livets hårda skolklasser', + Preamble: + 'Hej,Nu är problemet löst! Alla betyg syns som de ska.God jul!...', + BannerImageUrl: 'A703552D-DBF3-45B0-8E67-6E062105A0C5.jpeg', + BannerImageGuid: 'A703552D-DBF3-45B0-8E67-6E062105A0C5', + BannerImageListId: 'FFBE49E9-BDE1-4C75-BA0E-D98D4E2FCF21', + Body: '

Hej,

Nu är problemet löst! Alla betyg syns som de ska. 

God jul!

', + BodyNoHtml: null, + AuthorDisplayName: 'Eva-Lotta Rönnberg', + altText: 'Nyhetsbild. Bildtext ej tillgänglig.', + }, + ], + ViewGlobalTranslations: {}, + ViewLocalTranslations: {}, + Children: null, + Status: null, + GlobalTranslationIds: [ + 'InformationalHeader', + 'ContactUsMessageLabel', + 'Send', + 'RequiredFieldMessageInfo', + 'Sex', + 'Male', + 'Female', + 'SSN', + 'FirstName', + 'LastName', + 'Email', + 'Zip', + 'Address', + 'ValidationRequiredFieldMessage', + 'ValidationErrorMessage', + ], + LocalTranslationIds: ['IndexPageHeading1'], + }, + } + }) + it(' news items (except body) correctly', () => { + const [item] = news(response) + + expect(item.id).toEqual('news id') + expect(item.author).toEqual('Eva-Lotta Rönnberg') + expect(item.header).toEqual( + 'Problemet med att se betyg i bild, slöjd och teknik löst!' + ) + expect(item.imageUrl).toEqual('A703552D-DBF3-45B0-8E67-6E062105A0C5.jpeg') + expect(item.fullImageUrl).toEqual( + 'https://etjanst.stockholm.se/Vardnadshavare/inloggad2/NewsBanner?url=A703552D-DBF3-45B0-8E67-6E062105A0C5.jpeg' + ) + expect(item.imageAltText).toEqual('Nyhetsbild. Bildtext ej tillgänglig.') + expect(item.intro).toEqual( + 'Hej, Nu är problemet löst! Alla betyg syns som de ska. God jul!...' + ) + expect(item.modified).toEqual('2020-12-18T15:18:00.000Z') + expect(item.published).toEqual('2020-12-18T15:15:42.000Z') + }) + it(' body correctly', () => { + const [item] = news(response) + + const expected = + 'Hej, Nu är problemet löst! Alla betyg syns som de ska. God jul!' + const trimmed = (item.body || '') + .split('\n') + .map((t) => t.trim()) + .join(' ') + expect(trimmed).toEqual(expected) + }) + }) + describe('sorting', () => { + beforeEach(() => { + response = { + Success: true, + Error: null, + Data: { + CurrentChild: null, + NewsItems: [ + { + NewsId: 'news id', + SiteId: + 'elevstockholm.sharepoint.com,27892ACC-BA2E-4DEC-97B8-25F7098C3BF6,A239466A-9A52-42FF-8A3F-D94C342F2700', + NewsListId: '3EC323A1-EA16-4D24-84C8-DAA49E76F9F4', + NewsItemId: + 'elevstockholm.sharepoint.com,27892ACC-BA2E-4DEC-97B8-25F7098C3BF6,A239466A-9A52-42FF-8A3F-D94C342F2700_99', + Header: + 'Problemet med att se betyg i bild, slöjd och teknik löst!', + PublicationDate: '/Date(1608304542000)/', + PubDateSE: '18 december 2020 16:15', + ModifiedDate: '/Date(1608304680000)/', + ModDateSE: '18 december 2020 16:18', + Source: 'Livets hårda skolklasser', + Preamble: + 'Hej,Nu är problemet löst! Alla betyg syns som de ska.God jul!...', + BannerImageUrl: 'A703552D-DBF3-45B0-8E67-6E062105A0C5.jpeg', + BannerImageGuid: 'A703552D-DBF3-45B0-8E67-6E062105A0C5', + BannerImageListId: 'FFBE49E9-BDE1-4C75-BA0E-D98D4E2FCF21', + Body: '

Hej,

Nu är problemet löst! Alla betyg syns som de ska. 

God jul!

', + BodyNoHtml: null, + AuthorDisplayName: 'Eva-Lotta Rönnberg', + altText: 'Nyhetsbild. Bildtext ej tillgänglig.', + }, + { + NewsId: 'news id updated', + SiteId: + 'elevstockholm.sharepoint.com,27892ACC-BA2E-4DEC-97B8-25F7098C3BF6,A239466A-9A52-42FF-8A3F-D94C342F2700', + NewsListId: '3EC323A1-EA16-4D24-84C8-DAA49E76F9F4', + NewsItemId: + 'elevstockholm.sharepoint.com,27892ACC-BA2E-4DEC-97B8-25F7098C3BF6,A239466A-9A52-42FF-8A3F-D94C342F2700_99', + Header: + 'Problemet med att se betyg i bild, slöjd och teknik löst!', + PublicationDate: '/Date(1608304542000)/', + PubDateSE: '18 november 2021 16:15', + ModifiedDate: '/Date(1608304680000)/', + ModDateSE: '18 december 2020 16:18', + Source: 'Livets hårda skolklasser', + Preamble: + 'Hej,Nu är problemet löst! Alla betyg syns som de ska.God jul!...', + BannerImageUrl: 'A703552D-DBF3-45B0-8E67-6E062105A0C5.jpeg', + BannerImageGuid: 'A703552D-DBF3-45B0-8E67-6E062105A0C5', + BannerImageListId: 'FFBE49E9-BDE1-4C75-BA0E-D98D4E2FCF21', + Body: '

Hej,

Nu är problemet löst! Alla betyg syns som de ska. 

God jul!

', + BodyNoHtml: null, + AuthorDisplayName: 'Eva-Lotta Rönnberg', + altText: 'Nyhetsbild. Bildtext ej tillgänglig.', + }, + ], + ViewGlobalTranslations: {}, + ViewLocalTranslations: {}, + Children: null, + Status: null, + GlobalTranslationIds: [ + 'InformationalHeader', + 'ContactUsMessageLabel', + 'Send', + 'RequiredFieldMessageInfo', + 'Sex', + 'Male', + 'Female', + 'SSN', + 'FirstName', + 'LastName', + 'Email', + 'Zip', + 'Address', + 'ValidationRequiredFieldMessage', + 'ValidationErrorMessage', + ], + LocalTranslationIds: ['IndexPageHeading1'], + }, + } + }) + it('sorts by modified date desc', () => { + const [item] = news(response) + + expect(item.id).toEqual('news id updated') + }) + }) +}) + +describe('newsItem', () => { + beforeEach(() => { + response = { + Success: true, + Error: null, + Data: { + CurrentNewsItem: { + NewsId: '123', + SiteId: + 'elevstockholm.sharepoint.com,d112c398-71d4-468f-9a59-84d806751b08,3addab10-546a-4551-8076-72c9cd67f961', + NewsListId: '95df7d70-fbf0-470d-9926-e4e633f77f27', + NewsItemId: + 'elevstockholm.sharepoint.com,d112c398-71d4-468f-9a59-84d806751b08,3addab10-546a-4551-8076-72c9cd67f961_40', + Header: 'Avlusningsdagarna 5-7 februari 2021', + PublicationDate: '/Date(1612445471000)/', + PubDateSE: '4 februari 2021 14:31', + ModifiedDate: '/Date(1612445852000)/', + ModDateSE: '14 februari 2021 14:37', + Source: 'Södra Ängby skola', + Preamble: 'Kära vårdnadshavare!I helgen är det avlusningsdagar!', + BannerImageUrl: '123123.jpeg', + BannerImageGuid: '7a8142d9d9d54cf090e8457e4c629227', + BannerImageListId: 'a88c22e8-7094-4a71-b4fd-8792c62a7b4a', + Body: '

Kära vårdnadshavare!

I helgen är det avlusningsdagar! Ta tillfället i akt att luskamma ditt barn

Du finner all info du behöver på 1177 hemsida ​​​​​​​

Trevlig helg!

​​​​​​​

', + BodyNoHtml: null, + AuthorDisplayName: 'Tieto Evry', + altText: null, + OriginalSourceUrl: null, + }, + CurrentChild: null, + ViewGlobalTranslations: {}, + ViewLocalTranslations: {}, + Children: null, + Status: null, + GlobalTranslationIds: [ + 'InformationalHeader', + 'ContactUsMessageLabel', + 'Send', + 'RequiredFieldMessageInfo', + 'Sex', + 'Male', + 'Female', + 'SSN', + 'FirstName', + 'LastName', + 'Email', + 'Zip', + 'Address', + 'ValidationRequiredFieldMessage', + 'ValidationErrorMessage', + ], + LocalTranslationIds: ['IndexPageHeading1'], + }, + } + }) + + it(' news details (except body) correctly', () => { + const item = newsItemDetails(response) + + expect(item.id).toEqual('123') + expect(item.header).toEqual('Avlusningsdagarna 5-7 februari 2021') + expect(item.imageUrl).toEqual('123123.jpeg') + expect(item.intro).toEqual( + 'Kära vårdnadshavare! I helgen är det avlusningsdagar!' + ) + expect(item.published).toEqual('2021-02-04T13:31:11.000Z') + expect(item.modified).toEqual('2021-02-04T13:37:32.000Z') + expect(item.author).toEqual('Tieto Evry') + }) + + it(' body correctly', () => { + const item = newsItemDetails(response) + + const expected = + '[1177 hemsida](https://www.1177.se/sjukdomar--besvar/hud-har-och-naglar/harbotten-och-harsackar/huvudloss/)' + expect(item.body).toContain(expected) + expect(item.body).toContain(' **tillfället** ') + }) +}) + +describe('newsItem', () => { + beforeEach(() => { + response = { + Success: true, + Error: null, + Data: { + CurrentNewsItem: { + NewsId: '123', + SiteId: + 'elevstockholm.sharepoint.com,d112c398-71d4-468f-9a59-84d806751b08,3addab10-546a-4551-8076-72c9cd67f961', + NewsListId: '95df7d70-fbf0-470d-9926-e4e633f77f27', + NewsItemId: + 'elevstockholm.sharepoint.com,d112c398-71d4-468f-9a59-84d806751b08,3addab10-546a-4551-8076-72c9cd67f961_40', + Header: 'Avlusningsdagarna 5-7 februari 2021', + PublicationDate: '/Date(1612445471000)/', + PubDateSE: '4 februari 2021 14:31', + ModifiedDate: '/Date(1612445852000)/', + ModDateSE: '14 februari 2021 14:37', + Source: 'Södra Ängby skola', + Preamble: 'Kära vårdnadshavare!I helgen är det avlusningsdagar!', + BannerImageUrl: '123123.jpeg', + BannerImageGuid: '7a8142d9d9d54cf090e8457e4c629227', + BannerImageListId: 'a88c22e8-7094-4a71-b4fd-8792c62a7b4a', + Body: 'italic bold emphasis
strongnbsp ', + BodyNoHtml: null, + AuthorDisplayName: 'Tieto Evry', + altText: null, + OriginalSourceUrl: null, + }, + CurrentChild: null, + ViewGlobalTranslations: {}, + ViewLocalTranslations: {}, + Children: null, + Status: null, + GlobalTranslationIds: [ + 'InformationalHeader', + 'ContactUsMessageLabel', + 'Send', + 'RequiredFieldMessageInfo', + 'Sex', + 'Male', + 'Female', + 'SSN', + 'FirstName', + 'LastName', + 'Email', + 'Zip', + 'Address', + 'ValidationRequiredFieldMessage', + 'ValidationErrorMessage', + ], + LocalTranslationIds: ['IndexPageHeading1'], + }, + } + }) + it(' emphasizes correctly', () => { + const item = newsItemDetails(response) + + expect(item.body).toContain('*italic*') + expect(item.body).toContain('**bold**') + expect(item.body).toContain('*emphasis*') + expect(item.body).toContain('**strong**') + expect(item.body).toContain('**nbsp**') + }) +}) diff --git a/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/notifications.test.ts b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/notifications.test.ts new file mode 100644 index 000000000..567f7b30e --- /dev/null +++ b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/notifications.test.ts @@ -0,0 +1,64 @@ +import { EtjanstResponse } from '../' +import { notifications } from '../notifications' + +let response: EtjanstResponse + +beforeEach(() => { + response = { + Success: true, + Error: null, + Data: [ + { + Notification: { + Messageid: 'E2E3A567-307F-4859-91BA-31B1F4522A7B', + Messagecorrelationid: 'BB54DC8E-BB02-49A5-9806-4A2433031AA7', + Message: + '{"messages":{"message":{"messageid":"E2E3A567-307F-4859-91BA-31B1F4522A7B","messagecorrelationid":"BB54DC8E-BB02-49A5-9806-4A2433031AA7","messagetext":"Betygen är publicerade.","messagesubject":"Betyg klara","messagetime":"2020-12-18T15:59:43.195","linkbackurl":"https://elevdokumentation.stockholm.se/loa3/gradesStudent.do","sender":{"name":"Elevdokumentation"},"recipient":{"recipient":"195709227283","role":"Guardian"},"messagetype":{"type":"webnotify"},"system":"Elevdokumentation","participant":"BB7DE89D-D714-4EB2-85CD-36F9991E7C34"}}}', + Readreceipt: false, + Recipient: '195709227283', + Id: 5880387, + DateCreated: '2020-12-18T15:59:46.34', + DateModified: '/Date(1608307186340)/', + Role: 'Guardian', + Participant: 'BB7DE89D-D714-4EB2-85CD-36F9991E7C34', + }, + NotificationMessage: { + Messages: { + Message: { + Messageid: 'E2E3A567-307F-4859-91BA-31B1F4522A7B', + Messagecorrelationid: 'BB54DC8E-BB02-49A5-9806-4A2433031AA7', + Messagetext: 'Betygen är publicerade.', + Messagetime: '/Date(1608303583195)/', + Linkbackurl: + 'https://elevdokumentation.stockholm.se/loa3/gradesStudent.do', + Category: null, + Sender: { Name: 'Elevdokumentation' }, + Recipient: { + RecipientRecipient: '195709227283', + Role: 'Guardian', + Schooltype: null, + }, + Messagetype: { Type: 'webnotify' }, + System: 'Elevdokumentation', + }, + }, + }, + }, + ], + } +}) + +it(' notifications correctly', () => { + expect(notifications(response)).toEqual([ + { + id: 'E2E3A567-307F-4859-91BA-31B1F4522A7B', + message: 'Betygen är publicerade.', + sender: 'Elevdokumentation', + url: 'https://elevdokumentation.stockholm.se/loa3/gradesStudent.do', + dateCreated: '2020-12-18T14:59:46.340Z', + dateModified: '2020-12-18T15:59:46.340Z', + category: null, + type: 'webnotify', + }, + ]) +}) diff --git a/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/schedule.test.ts b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/schedule.test.ts new file mode 100644 index 000000000..4f5633ac0 --- /dev/null +++ b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/schedule.test.ts @@ -0,0 +1,47 @@ +import { EtjanstResponse } from '../' +import { schedule } from '../schedule' + +let response: EtjanstResponse + +beforeEach(() => { + response = { + Success: true, + Error: null, + Data: [ + { + Title: 'Canceled: Julavslutning 8C', + Id: 0, + Description: 'Nåt kul', + Location: 'Lakritskolan', + EventDate: '2020-12-14', + EventDateTime: '14:10', + LongEventDateTime: '2020-12-14 14:10', + EndDate: '2020-12-14', + EndDateTime: '14:40', + LongEndDateTime: '2020-12-14 14:40', + EventDateDayNumber: '14', + EventDateMonthName: 'dec', + EventDateMonthFullName: 'december', + FullDateDescription: '2020-12-14 14:10 - 2020-12-14 14:40', + IsSameDay: true, + AllDayEvent: false, + ListId: null, + Mentor: null, + }, + ], + } +}) + +it('parses schedule correctly', () => { + expect(schedule(response)).toEqual([ + { + title: 'Canceled: Julavslutning 8C', + description: 'Nåt kul', + location: 'Lakritskolan', + startDate: '2020-12-14T13:10:00.000Z', + endDate: '2020-12-14T13:40:00.000Z', + oneDayEvent: true, + allDayEvent: false, + }, + ]) +}) diff --git a/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/schoolContacts.test.ts b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/schoolContacts.test.ts new file mode 100644 index 000000000..b2d5cdc28 --- /dev/null +++ b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/schoolContacts.test.ts @@ -0,0 +1,50 @@ +import { EtjanstResponse } from '../' +import { schoolContacts } from '../schoolContacts' + +let response: EtjanstResponse + +beforeEach(() => { + response = { + Success: true, + Error: null, + Data: [ + { + Title: 'Expedition', + Name: null, + Phone: '508 000 00', + Email: '', + SchoolName: 'Påhittade skolan', + ClassName: null, + }, + { + Title: 'Rektor', + Name: 'Andersson, Anna Bella Cecilia', + Phone: '08-508 000 00', + Email: 'anna.anderssonn@edu.stockholm.se', + SchoolName: null, + ClassName: null, + }, + ], + } +}) + +it('parses teachers correctly', () => { + expect(schoolContacts(response)).toEqual([ + { + title: 'Expedition', + name: null, + phone: '508 000 00', + email: '', + schoolName: 'Påhittade skolan', + className: null, + }, + { + title: 'Rektor', + name: 'Andersson, Anna Bella Cecilia', + phone: '08-508 000 00', + email: 'anna.anderssonn@edu.stockholm.se', + schoolName: null, + className: null, + }, + ]) +}) diff --git a/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/teachers.test.ts b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/teachers.test.ts new file mode 100644 index 000000000..cda0583b1 --- /dev/null +++ b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/teachers.test.ts @@ -0,0 +1,68 @@ +import { EtjanstResponse } from '../' +import { teachers } from '../teachers' + +let response: EtjanstResponse + +beforeEach(() => { + response = { + Success: true, + Error: null, + Data: [ + { + ID: 156735, + BATCH: 'GR', + SIS_ID: 'F154239A-EA4A-4C6C-A112-0B9581132E3D', + USERNAME: 'anna.andersson', + SCHOOL_SIS_ID: 'DE2E1293-0F40-4B91-9D91-1E99355DC257', + EMAILADDRESS: null, + STATUS: ' GR', + ERRORCODE: 0, + FIRSTNAME: 'Anna', + LASTNAME: 'Andersson', + ACTIVE: true, + TELWORK: '08 508 0000000', + }, + { + ID: 156690, + BATCH: 'GR', + SIS_ID: '9EC59FCA-80AD-4774-AABD-427040207E33', + USERNAME: 'gunnar.grymm', + SCHOOL_SIS_ID: 'DE2E1293-0F40-4B91-9D91-1E99355DC257', + EMAILADDRESS: 'gunnar.grymm@edu.stockholm.se', + STATUS: ' F', + ERRORCODE: 0, + FIRSTNAME: 'Gunnar', + LASTNAME: 'Grymm', + ACTIVE: true, + TELWORK: null, + }, + ], + } +}) + +it('parses teachers correctly', () => { + expect(teachers(response)).toEqual([ + { + id: 156735, + sisId: 'F154239A-EA4A-4C6C-A112-0B9581132E3D', + firstname: 'Anna', + lastname: 'Andersson', + email: null, + phoneWork: '08 508 0000000', + active: true, + status: ' GR', + timeTableAbbreviation: 'AAN', + }, + { + id: 156690, + sisId: '9EC59FCA-80AD-4774-AABD-427040207E33', + firstname: 'Gunnar', + lastname: 'Grymm', + email: 'gunnar.grymm@edu.stockholm.se', + phoneWork: null, + active: true, + status: ' F', + timeTableAbbreviation: 'GGR', + }, + ]) +}) diff --git a/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/timetable.test.ts b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/timetable.test.ts new file mode 100644 index 000000000..4ab1511ff --- /dev/null +++ b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/timetable.test.ts @@ -0,0 +1,147 @@ +import { timetable, timetableEntry, TimetableResponse } from '../' + +let response: TimetableResponse + +describe('Timetable', () => { + beforeEach(() => { + response = { + error: null, + data: { + textList: [ + { + x: 11, + y: 64, + fColor: '#000000', + fontsize: 14, + text: '8:30', + bold: false, + italic: false, + id: 9, + parentId: 6, + type: 'ClockAxisBox', + }, + { + x: 11, + y: 125, + fColor: '#000000', + fontsize: 14, + text: '9:00', + bold: false, + italic: false, + id: 12, + parentId: 6, + type: 'ClockAxisBox', + }, + ], + boxList: [ + { + x: 0, + y: 950, + width: 1226, + height: 112, + bColor: '#FFFFFF', + fColor: '#FFFFFF', + id: 0, + parentId: null, + type: 'Footer', + lessonGuids: null, + }, + { + x: 56, + y: 0, + width: 223, + height: 34, + bColor: '#FFFFFF', + fColor: '#000000', + id: 1, + parentId: null, + type: 'HeadingDay', + lessonGuids: null, + }, + ], + lineList: [ + { + p1x: 51, + p1y: 34, + p2x: 56, + p2y: 34, + color: '#000000', + id: 7, + parentId: 6, + type: 'ClockAxisGradiation', + }, + { + p1x: 0, + p1y: 64, + p2x: 56, + p2y: 64, + color: '#000000', + id: 8, + parentId: 6, + type: 'ClockAxisGradiation', + }, + ], + lessonInfo: [ + { + guidId: 'N2FjMDc1NjYtZmM2Yy0wZDQyLTY3M2YtZWI5NGNiZDA3ZGU4', + texts: ['Lunch', '', 'Ö5'], + timeStart: '11:40:00', + timeEnd: '12:05:00', + dayOfWeekNumber: 1, + blockName: '', + }, + { + guidId: 'ZTQ1NWE0N2EtNzAwOS0wZTAzLTQ1ZDYtNTA1NWI4Y2JhNDYw', + texts: ['BL', 'KUr', '221'], + timeStart: '09:40:00', + timeEnd: '11:35:00', + dayOfWeekNumber: 1, + blockName: 'block', + }, + ], + }, + exception: null, + validation: [], + } + }) + describe('timetableEntry', () => { + it('parses basic timeTableEntry data correctly', () => { + const entry = timetableEntry(response.data.lessonInfo[1], 2021, 15, 'sv') + + expect(entry.id).toEqual( + 'ZTQ1NWE0N2EtNzAwOS0wZTAzLTQ1ZDYtNTA1NWI4Y2JhNDYw' + ) + expect(entry.code).toEqual('BL') + expect(entry.name).toEqual('Bild') + expect(entry.teacher).toEqual('KUr') + expect(entry.location).toEqual('221') + expect(entry.timeStart).toEqual('09:40:00') + expect(entry.timeEnd).toEqual('11:35:00') + expect(entry.dayOfWeek).toEqual(1) + expect(entry.blockName).toEqual('block') + }) + it('parses dates correctly', () => { + const entry = timetableEntry(response.data.lessonInfo[1], 2021, 15, 'sv') + + expect(entry.dateStart).toEqual('2021-04-12T09:40:00.000+02:00') + expect(entry.dateEnd).toEqual('2021-04-12T11:35:00.000+02:00') + }) + }) + describe('timetable', () => { + it('throws error', () => { + response.error = 'b0rk' + expect(() => timetable(response, 2021, 15, 'sv')).toThrow('b0rk') + }) + it('parses lessonInfo', () => { + const table = timetable(response, 2021, 15, 'sv') + + expect(table).toHaveLength(2) + expect(table[0].id).toEqual( + 'N2FjMDc1NjYtZmM2Yy0wZDQyLTY3M2YtZWI5NGNiZDA3ZGU4' + ) + expect(table[1].id).toEqual( + 'ZTQ1NWE0N2EtNzAwOS0wZTAzLTQ1ZDYtNTA1NWI4Y2JhNDYw' + ) + }) + }) +}) diff --git a/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/user.test.ts b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/user.test.ts new file mode 100644 index 000000000..a8685f5ce --- /dev/null +++ b/apps/skolplattformen-app-new/libs/api-skolplattformen/lib/parse/__tests__/user.test.ts @@ -0,0 +1,27 @@ +import { user } from '../user' + +let response: any + +beforeEach(() => { + response = { + socialSecurityNumber: '197106171635', + isAuthenticated: true, + userFirstName: 'Per-Ola', + userLastName: 'Assarsson', + userEmail: 'per-ola.assarsson@dodgit.com', + notificationId: + 'B026594053D44299AB64ED81990B49C04D32F635C9A3454A84030439BFDDEF04', + } +}) + +it('parses user correctly', () => { + expect(user(response)).toEqual({ + personalNumber: '197106171635', + firstName: 'Per-Ola', + lastName: 'Assarsson', + email: 'per-ola.assarsson@dodgit.com', + isAuthenticated: true, + notificationId: + 'B026594053D44299AB64ED81990B49C04D32F635C9A3454A84030439BFDDEF04', + }) +})