test(user): use relative future dates

This commit is contained in:
Ali BARIN
2024-12-05 11:46:38 +00:00
parent feba2a32f9
commit 26b095b835

View File

@@ -996,21 +996,9 @@ describe('User model', () => {
const user = await createUser(); const user = await createUser();
const presentDate = DateTime.fromObject(
{ year: 2024, month: 11, day: 17, hour: 11, minute: 30 },
{ zone: 'UTC+0' }
);
vi.setSystemTime(presentDate);
await user.startTrialPeriod(); await user.startTrialPeriod();
const futureDate = DateTime.fromObject( vi.setSystemTime(DateTime.now().plus({ month: 1 }));
{ year: 2025, month: 1, day: 1 },
{ zone: 'UTC+0' }
);
vi.setSystemTime(futureDate);
const refetchedUser = await user.$query(); const refetchedUser = await user.$query();
@@ -1118,7 +1106,9 @@ describe('User model', () => {
const user = await createUser(); const user = await createUser();
expect(() => user.getPlanAndUsage()).rejects.toThrow('NotFoundError'); await expect(() => user.getPlanAndUsage()).rejects.toThrow(
'NotFoundError'
);
}); });
}); });
@@ -1189,7 +1179,7 @@ describe('User model', () => {
}); });
it('should throw not found error when user role does not exist', async () => { it('should throw not found error when user role does not exist', async () => {
expect(() => await expect(() =>
User.registerUser({ User.registerUser({
fullName: 'Sample user', fullName: 'Sample user',
email: 'user@automatisch.io', email: 'user@automatisch.io',
@@ -1257,6 +1247,8 @@ describe('User model', () => {
describe('createUsageData', () => { describe('createUsageData', () => {
it('should create usage data if Automatisch is a cloud installation', async () => { it('should create usage data if Automatisch is a cloud installation', async () => {
vi.useFakeTimers();
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(true); vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(true);
const user = await createUser({ const user = await createUser({
@@ -1264,10 +1256,14 @@ describe('User model', () => {
email: 'user@automatisch.io', email: 'user@automatisch.io',
}); });
vi.setSystemTime(DateTime.now().plus({ month: 1 }));
const usageData = await user.createUsageData(); const usageData = await user.createUsageData();
const currentUsageData = await user.$relatedQuery('currentUsageData'); const currentUsageData = await user.$relatedQuery('currentUsageData');
expect(usageData).toStrictEqual(currentUsageData); expect(usageData).toStrictEqual(currentUsageData);
vi.useRealTimers();
}); });
it('should not create usage data if Automatisch is not a cloud installation', async () => { it('should not create usage data if Automatisch is not a cloud installation', async () => {