Merge pull request #2197 from automatisch/aut-1350-isInvitationTokenValid
test(user): write tests for isInvitationTokenValid
This commit is contained in:
@@ -792,4 +792,48 @@ describe('User model', () => {
|
|||||||
|
|
||||||
vi.useRealTimers();
|
vi.useRealTimers();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isInvitationTokenValid', () => {
|
||||||
|
it('should return truen when invitationTokenSentAt is within the next four hours', async () => {
|
||||||
|
vi.useFakeTimers();
|
||||||
|
|
||||||
|
const date = DateTime.fromObject(
|
||||||
|
{ year: 2024, month: 11, day: 14, hour: 14, minute: 30 },
|
||||||
|
{ zone: 'UTC+0' }
|
||||||
|
);
|
||||||
|
|
||||||
|
vi.setSystemTime(date);
|
||||||
|
|
||||||
|
const user = new User();
|
||||||
|
user.invitationTokenSentAt = '2024-11-14T13:31:00.000Z';
|
||||||
|
|
||||||
|
expect(user.isInvitationTokenValid()).toBe(true);
|
||||||
|
|
||||||
|
vi.useRealTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false when there is no invitationTokenSentAt', async () => {
|
||||||
|
const user = new User();
|
||||||
|
|
||||||
|
expect(user.isInvitationTokenValid()).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false when invitationTokenSentAt is older than seventy two hours', async () => {
|
||||||
|
vi.useFakeTimers();
|
||||||
|
|
||||||
|
const date = DateTime.fromObject(
|
||||||
|
{ year: 2024, month: 11, day: 14, hour: 14, minute: 30 },
|
||||||
|
{ zone: 'UTC+0' }
|
||||||
|
);
|
||||||
|
|
||||||
|
vi.setSystemTime(date);
|
||||||
|
|
||||||
|
const user = new User();
|
||||||
|
user.invitationTokenSentAt = '2024-11-11T14:20:00.000Z';
|
||||||
|
|
||||||
|
expect(user.isInvitationTokenValid()).toBe(false);
|
||||||
|
|
||||||
|
vi.useRealTimers();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user