All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 12s
- Sidebar: dynamic brand-accent colors, brainstorm section restyled - AI chat general: popup panel with expand/collapse, hides when contextual AI open - AI chat contextual: tabs reordered (Actions first), X close button, height fix - Settings: all tabs restyled, 6 new color presets (sage, terracotta, iron, etc.) - Global color cleanup: emerald/orange hardcoded → brand-accent dynamic - Brainstorm page: orange → brand-accent throughout - PageEntry animation component added to key pages - Floating AI button: bg-brand-accent instead of hardcoded black - i18n: all 15 locales updated with new AI/billing keys - Billing: freemium quota tracking, BYOK, stripe subscription scaffolding - Admin: integrated into new design - AGENTS.md + CLAUDE.md project rules added
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { canUseFeature } from '@/lib/entitlements';
|
|
|
|
vi.mock('@/lib/redis', () => ({
|
|
redis: {
|
|
get: vi.fn(),
|
|
mget: vi.fn(),
|
|
eval: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
vi.mock('@/lib/prisma', () => ({
|
|
prisma: {
|
|
subscription: { findUnique: vi.fn() },
|
|
userAPIKey: { count: vi.fn() },
|
|
},
|
|
}));
|
|
|
|
import { redis } from '@/lib/redis';
|
|
import { prisma } from '@/lib/prisma';
|
|
|
|
describe('BYOK entitlements', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
vi.mocked(prisma.subscription.findUnique).mockResolvedValue({
|
|
userId: 'user1',
|
|
tier: 'BASIC',
|
|
status: 'ACTIVE',
|
|
currentPeriodStart: new Date(),
|
|
currentPeriodEnd: new Date(),
|
|
} as never);
|
|
});
|
|
|
|
it('returns byokConfigured=true when BYOK active but quota exhausted (bypass is per-provider in routes)', async () => {
|
|
vi.mocked(redis.get).mockResolvedValue('30');
|
|
vi.mocked(prisma.userAPIKey.count).mockResolvedValue(1);
|
|
|
|
const result = await canUseFeature('user1', 'semantic_search');
|
|
|
|
expect(result.allowed).toBe(false);
|
|
expect(result.byokConfigured).toBe(true);
|
|
});
|
|
|
|
it('denies when quota exhausted and no BYOK', async () => {
|
|
vi.mocked(redis.get).mockResolvedValue('30');
|
|
vi.mocked(prisma.userAPIKey.count).mockResolvedValue(0);
|
|
|
|
const result = await canUseFeature('user1', 'semantic_search');
|
|
|
|
expect(result.allowed).toBe(false);
|
|
expect(result.byokConfigured).toBe(false);
|
|
});
|
|
});
|