Merge pull request #2204 from automatisch/aut-1350-hasActiveSubscription
test(user): write tests for hasActiveSubscription
This commit is contained in:
@@ -26,6 +26,7 @@ import { createPermission } from '../../test/factories/permission.js';
|
|||||||
import { createFlow } from '../../test/factories/flow.js';
|
import { createFlow } from '../../test/factories/flow.js';
|
||||||
import { createStep } from '../../test/factories/step.js';
|
import { createStep } from '../../test/factories/step.js';
|
||||||
import { createExecution } from '../../test/factories/execution.js';
|
import { createExecution } from '../../test/factories/execution.js';
|
||||||
|
import { createSubscription } from '../../test/factories/subscription.js';
|
||||||
|
|
||||||
describe('User model', () => {
|
describe('User model', () => {
|
||||||
it('tableName should return correct name', () => {
|
it('tableName should return correct name', () => {
|
||||||
@@ -1004,4 +1005,33 @@ describe('User model', () => {
|
|||||||
vi.useRealTimers();
|
vi.useRealTimers();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('hasActiveSubscription', () => {
|
||||||
|
it('should return true if current subscription is valid', async () => {
|
||||||
|
const user = await createUser();
|
||||||
|
await createSubscription({ userId: user.id, status: 'active' });
|
||||||
|
|
||||||
|
expect(await user.hasActiveSubscription()).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false if current subscription is not valid', async () => {
|
||||||
|
const user = await createUser();
|
||||||
|
|
||||||
|
await createSubscription({
|
||||||
|
userId: user.id,
|
||||||
|
status: 'deleted',
|
||||||
|
cancellationEffectiveDate: DateTime.now().minus({ day: 1 }).toString(),
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(await user.hasActiveSubscription()).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false if Automatisch is not a cloud installation', async () => {
|
||||||
|
const user = new User();
|
||||||
|
|
||||||
|
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(false);
|
||||||
|
|
||||||
|
expect(await user.hasActiveSubscription()).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user