diff --git a/src/modules/person/domain/person-time-limit-info.service.spec.ts b/src/modules/person/domain/person-time-limit-info.service.spec.ts index f860e0e10..d415df71b 100644 --- a/src/modules/person/domain/person-time-limit-info.service.spec.ts +++ b/src/modules/person/domain/person-time-limit-info.service.spec.ts @@ -69,34 +69,46 @@ describe('PersonTimeLimitService', () => { ]); }); - it('should return PersonTimeLimitInfo array with earliest Koperslock', async () => { - const person: Person = DoFactory.createPerson(true); - person.personalnummer = undefined; - personRepoMock.findById.mockResolvedValue(person); - - const personenkontext: Personenkontext = DoFactory.createPersonenkontext(true, { - createdAt: new Date('2021-01-02'), - }); - const personenkontext2: Personenkontext = DoFactory.createPersonenkontext(true, { - createdAt: new Date('2021-01-01'), - }); - dBiamPersonenkontextServiceMock.getKopersPersonenkontexte.mockResolvedValue([ - personenkontext, - personenkontext2, - ]); - - const result: PersonTimeLimitInfo[] = await sut.getPersonTimeLimitInfo(person.id); - - const expectedDeadline: Date = new Date(personenkontext2.createdAt); - expectedDeadline.setDate(expectedDeadline.getDate() + KOPERS_DEADLINE_IN_DAYS); - - expect(result).toEqual([ - { - occasion: TimeLimitOccasion.KOPERS, - deadline: expectedDeadline, - }, - ]); - }); + it.each([ + { + personenkontextDates: ['2021-01-02', '2021-01-01'], + expectedDate: '2021-01-01', + }, + { + personenkontextDates: ['2021-01-01', '2021-01-02'], + expectedDate: '2021-01-01', + }, + ])( + 'should return PersonTimeLimitInfo array with earliest Koperslock', + async ({ + personenkontextDates, + expectedDate, + }: { + personenkontextDates: string[]; + expectedDate: string; + }) => { + const person: Person = DoFactory.createPerson(true); + person.personalnummer = undefined; + personRepoMock.findById.mockResolvedValue(person); + + const personenkontexte: Personenkontext[] = personenkontextDates.map((date: string) => + DoFactory.createPersonenkontext(true, { createdAt: new Date(date) }), + ); + dBiamPersonenkontextServiceMock.getKopersPersonenkontexte.mockResolvedValue(personenkontexte); + + const result: PersonTimeLimitInfo[] = await sut.getPersonTimeLimitInfo(person.id); + + const expectedDeadline: Date = new Date(expectedDate); + expectedDeadline.setDate(expectedDeadline.getDate() + KOPERS_DEADLINE_IN_DAYS); + + expect(result).toEqual([ + { + occasion: TimeLimitOccasion.KOPERS, + deadline: expectedDeadline, + }, + ]); + }, + ); it('should return empty array when person isnt found ', async () => { personRepoMock.findById.mockResolvedValue(null);