feat: add copilot impl (#6230)

fix CLOUD-22
fix CLOUD-24
This commit is contained in:
darkskygit
2024-04-10 11:15:31 +00:00
parent 46a368d7f1
commit e6a576551a
23 changed files with 669 additions and 34 deletions
+34 -16
View File
@@ -18,7 +18,7 @@ import { createTestingModule } from './utils';
const test = ava as TestFn<{
auth: AuthService;
quota: QuotaService;
storageQuota: QuotaManagementService;
quotaManager: QuotaManagementService;
module: TestingModule;
}>;
@@ -28,12 +28,12 @@ test.beforeEach(async t => {
});
const quota = module.get(QuotaService);
const storageQuota = module.get(QuotaManagementService);
const quotaManager = module.get(QuotaManagementService);
const auth = module.get(AuthService);
t.context.module = module;
t.context.quota = quota;
t.context.storageQuota = storageQuota;
t.context.quotaManager = quotaManager;
t.context.auth = auth;
});
@@ -49,7 +49,7 @@ test('should be able to set quota', async t => {
const q1 = await quota.getUserQuota(u1.id);
t.truthy(q1, 'should have quota');
t.is(q1?.feature.name, QuotaType.FreePlanV1, 'should be free plan');
t.is(q1?.feature.version, 3, 'should be version 3');
t.is(q1?.feature.version, 4, 'should be version 4');
await quota.switchUserQuota(u1.id, QuotaType.ProPlanV1);
@@ -61,35 +61,35 @@ test('should be able to set quota', async t => {
});
test('should be able to check storage quota', async t => {
const { auth, quota, storageQuota } = t.context;
const { auth, quota, quotaManager } = t.context;
const u1 = await auth.signUp('DarkSky', 'darksky@example.org', '123456');
const q1 = await storageQuota.getUserQuota(u1.id);
t.is(q1?.blobLimit, Quotas[4].configs.blobLimit, 'should be free plan');
t.is(q1?.storageQuota, Quotas[4].configs.storageQuota, 'should be free plan');
const q1 = await quotaManager.getUserQuota(u1.id);
t.is(q1?.blobLimit, Quotas[5].configs.blobLimit, 'should be free plan');
t.is(q1?.storageQuota, Quotas[5].configs.storageQuota, 'should be free plan');
await quota.switchUserQuota(u1.id, QuotaType.ProPlanV1);
const q2 = await storageQuota.getUserQuota(u1.id);
const q2 = await quotaManager.getUserQuota(u1.id);
t.is(q2?.blobLimit, Quotas[1].configs.blobLimit, 'should be pro plan');
t.is(q2?.storageQuota, Quotas[1].configs.storageQuota, 'should be pro plan');
});
test('should be able revert quota', async t => {
const { auth, quota, storageQuota } = t.context;
const { auth, quota, quotaManager } = t.context;
const u1 = await auth.signUp('DarkSky', 'darksky@example.org', '123456');
const q1 = await storageQuota.getUserQuota(u1.id);
t.is(q1?.blobLimit, Quotas[4].configs.blobLimit, 'should be free plan');
t.is(q1?.storageQuota, Quotas[4].configs.storageQuota, 'should be free plan');
const q1 = await quotaManager.getUserQuota(u1.id);
t.is(q1?.blobLimit, Quotas[5].configs.blobLimit, 'should be free plan');
t.is(q1?.storageQuota, Quotas[5].configs.storageQuota, 'should be free plan');
await quota.switchUserQuota(u1.id, QuotaType.ProPlanV1);
const q2 = await storageQuota.getUserQuota(u1.id);
const q2 = await quotaManager.getUserQuota(u1.id);
t.is(q2?.blobLimit, Quotas[1].configs.blobLimit, 'should be pro plan');
t.is(q2?.storageQuota, Quotas[1].configs.storageQuota, 'should be pro plan');
await quota.switchUserQuota(u1.id, QuotaType.FreePlanV1);
const q3 = await storageQuota.getUserQuota(u1.id);
t.is(q3?.blobLimit, Quotas[4].configs.blobLimit, 'should be free plan');
const q3 = await quotaManager.getUserQuota(u1.id);
t.is(q3?.blobLimit, Quotas[5].configs.blobLimit, 'should be free plan');
const quotas = await quota.getUserQuotas(u1.id);
t.is(quotas.length, 3, 'should have 3 quotas');
@@ -100,3 +100,21 @@ test('should be able revert quota', async t => {
t.is(quotas[1].activated, false, 'should be activated');
t.is(quotas[2].activated, true, 'should be activated');
});
test('should be able to check quota', async t => {
const { auth, quotaManager } = t.context;
const u1 = await auth.signUp('DarkSky', 'darksky@example.org', '123456');
const q1 = await quotaManager.getUserQuota(u1.id);
const freePlan = Quotas[5].configs;
t.assert(q1, 'should have quota');
t.is(q1.blobLimit, freePlan.blobLimit, 'should be free plan');
t.is(q1.storageQuota, freePlan.storageQuota, 'should be free plan');
t.is(q1.historyPeriod, freePlan.historyPeriod, 'should be free plan');
t.is(q1.memberLimit, freePlan.memberLimit, 'should be free plan');
t.is(
q1.copilotActionLimit!,
freePlan.copilotActionLimit!,
'should be free plan'
);
});