Skip to content

Commit

Permalink
add second test case
Browse files Browse the repository at this point in the history
  • Loading branch information
tikle-cap committed Dec 12, 2024
1 parent be9a08b commit 9beaadd
Showing 1 changed file with 40 additions and 28 deletions.
68 changes: 40 additions & 28 deletions src/modules/person/domain/person-time-limit-info.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,34 +69,46 @@ describe('PersonTimeLimitService', () => {
]);
});

it('should return PersonTimeLimitInfo array with earliest Koperslock', async () => {
const person: Person<true> = DoFactory.createPerson(true);
person.personalnummer = undefined;
personRepoMock.findById.mockResolvedValue(person);

const personenkontext: Personenkontext<true> = DoFactory.createPersonenkontext(true, {
createdAt: new Date('2021-01-02'),
});
const personenkontext2: Personenkontext<true> = 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<PersonTimeLimitInfo[]>([
{
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<true> = DoFactory.createPerson(true);
person.personalnummer = undefined;
personRepoMock.findById.mockResolvedValue(person);

const personenkontexte: Personenkontext<true>[] = 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<PersonTimeLimitInfo[]>([
{
occasion: TimeLimitOccasion.KOPERS,
deadline: expectedDeadline,
},
]);
},
);

it('should return empty array when person isnt found ', async () => {
personRepoMock.findById.mockResolvedValue(null);
Expand Down

0 comments on commit 9beaadd

Please sign in to comment.