Merge pull request #2213 from automatisch/aut-1350-getPlanAndUsage
test(user): write tests for getPlanAndUsage
This commit is contained in:
@@ -1063,4 +1063,46 @@ describe('User model', () => {
|
|||||||
expect(await user.withinLimits()).toBe(false);
|
expect(await user.withinLimits()).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getPlanAndUsage', () => {
|
||||||
|
it('should return plan and usage', async () => {
|
||||||
|
const user = await createUser();
|
||||||
|
|
||||||
|
const subscription = await createSubscription({ userId: user.id });
|
||||||
|
|
||||||
|
expect(await user.getPlanAndUsage()).toStrictEqual({
|
||||||
|
usage: {
|
||||||
|
task: 0,
|
||||||
|
},
|
||||||
|
plan: {
|
||||||
|
id: subscription.paddlePlanId,
|
||||||
|
name: '10k - monthly',
|
||||||
|
limit: '10,000',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return trial plan and usage if no subscription exists', async () => {
|
||||||
|
const user = await createUser();
|
||||||
|
|
||||||
|
expect(await user.getPlanAndUsage()).toStrictEqual({
|
||||||
|
usage: {
|
||||||
|
task: 0,
|
||||||
|
},
|
||||||
|
plan: {
|
||||||
|
id: null,
|
||||||
|
name: 'Free Trial',
|
||||||
|
limit: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw not found when the current usage data does not exist', async () => {
|
||||||
|
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(false);
|
||||||
|
|
||||||
|
const user = await createUser();
|
||||||
|
|
||||||
|
expect(() => user.getPlanAndUsage()).rejects.toThrow('NotFoundError');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user