api-server/src/modules/membership/membership.controller.spec.ts
wangdl 05cf369bee
Some checks failed
Deploy API Server / build-and-unit (push) Successful in 42s
Deploy API Server / current-integration (push) Failing after 3m6s
Deploy API Server / backward-compat (push) Successful in 17s
Deploy API Server / deploy (push) Has been skipped
feat: 本地开发环境配置 + Python 3.9 兼容修复
- 添加 docker-compose.local.yml(MySQL/Redis/Qdrant 本地基础设施)
- 添加 mysql.conf.d 本地 MySQL 低资源配置
- RAG Worker Python 3.9 兼容(from __future__ import annotations)
- 同步最新业务代码变更
2026-06-27 12:42:44 +08:00

38 lines
2.4 KiB
TypeScript

import { MembershipController } from './membership.controller';
describe('MembershipController', () => {
let ctrl: MembershipController;
let svc: any; let prisma: any;
beforeEach(() => {
svc = { compute: jest.fn(), getEntitlements: jest.fn() };
prisma = { membershipPlan: { findMany: jest.fn() } };
ctrl = new MembershipController(svc, prisma);
});
it('GET /membership/me returns effectivePlan + grants + token', async () => {
svc.compute.mockResolvedValue({ effectivePlan:'premium', grants:[{ source:'apple',status:'active',planCode:'premium',planName:'Premium',startedAt:'2026-01-01',expiresAt:null,autoRenewStatus:'on',environment:'Production' }], appAccountToken:'uuid-1' });
svc.getEntitlements.mockResolvedValue({ planCode:'premium', entitlements:{ maxKnowledgeBases:10, maxStorageBytes:10737418240, maxFileSizeBytes:52428800, monthlyOcrPages:50, monthlyVisionPages:30, monthlyChatCount:300, monthlyAiAnalysisCount:0, monthlyRecallCount:0, monthlyCardGenCount:0, monthlyQuizCount:0 } });
const r = await ctrl.getMyMembership({ user:{ id:'u1' } });
expect(r.effectivePlan).toBe('premium');
expect(r.grants).toHaveLength(1);
expect(r.appAccountToken).toBe('uuid-1');
expect(r.entitlements).toBeDefined();
});
it('GET /membership/me does not expose transactionId', async () => {
svc.compute.mockResolvedValue({ effectivePlan:'free', grants:[], appAccountToken:null });
svc.getEntitlements.mockResolvedValue({ planCode:'free', entitlements:{ maxKnowledgeBases:1, maxStorageBytes:1073741824, maxFileSizeBytes:10485760, monthlyOcrPages:0, monthlyVisionPages:0, monthlyChatCount:30, monthlyAiAnalysisCount:0, monthlyRecallCount:0, monthlyCardGenCount:0, monthlyQuizCount:0 } });
const r = await ctrl.getMyMembership({ user:{ id:'u1' } });
expect(r).not.toHaveProperty('transactionId');
expect(r).not.toHaveProperty('originalTransactionId');
});
it('GET /membership/plans returns active plans', async () => {
prisma.membershipPlan.findMany.mockResolvedValue([{ code:'free', name:'Free', maxKnowledgeBases:1, maxStorageBytes:BigInt(1073741824), maxFileSizeBytes:BigInt(10485760), monthlyOcrPages:0, monthlyVisionPages:0, monthlyChatCount:30, monthlyAiAnalysisCount:0, monthlyRecallCount:0, monthlyCardGenCount:0, monthlyQuizCount:0, priceMonthly:0, priceYearly:0 }]);
const r = await ctrl.getPlans();
expect(r.plans).toHaveLength(1);
expect(r.plans[0].planCode).toBe('free');
});
});