Skip to content

Commit

Permalink
feat(moved over more tests from original repo)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Palmqvist <[email protected]>
  • Loading branch information
coolusername244 and PalmN72 committed Oct 18, 2023
1 parent 417ea57 commit 9294fec
Show file tree
Hide file tree
Showing 12 changed files with 1,045 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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')
})
Original file line number Diff line number Diff line change
@@ -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',
},
])
})
Original file line number Diff line number Diff line change
@@ -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: '[email protected]',
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: '[email protected]',
},
],
},
])
})
Original file line number Diff line number Diff line change
@@ -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)
})
})
Original file line number Diff line number Diff line change
@@ -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 .<br/>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',
},
])
})
})
Loading

0 comments on commit 9294fec

Please sign in to comment.