From a570b8eb7a7c38dbceb183e3659447fe3ddc4ac9 Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Fri, 15 Nov 2024 14:25:54 +0000 Subject: [PATCH] test(user): write tests for withinLimits --- packages/backend/src/models/user.test.js | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/backend/src/models/user.test.js b/packages/backend/src/models/user.test.js index 2c432d08..77204c2d 100644 --- a/packages/backend/src/models/user.test.js +++ b/packages/backend/src/models/user.test.js @@ -27,6 +27,7 @@ import { createFlow } from '../../test/factories/flow.js'; import { createStep } from '../../test/factories/step.js'; import { createExecution } from '../../test/factories/execution.js'; import { createSubscription } from '../../test/factories/subscription.js'; +import { createUsageData } from '../../test/factories/usage-data.js'; describe('User model', () => { it('tableName should return correct name', () => { @@ -1034,4 +1035,32 @@ describe('User model', () => { expect(await user.hasActiveSubscription()).toBe(false); }); }); + + describe('withinLimits', () => { + it('should return true when the consumed task count is less than the quota', async () => { + const user = await createUser(); + const subscription = await createSubscription({ userId: user.id }); + + await createUsageData({ + subscriptionId: subscription.id, + userId: user.id, + consumedTaskCount: 100, + }); + + expect(await user.withinLimits()).toBe(true); + }); + + it('should return true when the consumed task count is less than the quota', async () => { + const user = await createUser(); + const subscription = await createSubscription({ userId: user.id }); + + await createUsageData({ + subscriptionId: subscription.id, + userId: user.id, + consumedTaskCount: 10000, + }); + + expect(await user.withinLimits()).toBe(false); + }); + }); });