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
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { applyByokToConfig } from '@/lib/byok';
|
|
|
|
vi.mock('@/lib/prisma', () => ({
|
|
prisma: {
|
|
userAPIKey: { findFirst: vi.fn() },
|
|
},
|
|
}));
|
|
|
|
vi.mock('@/lib/crypto', () => ({
|
|
decryptApiKey: vi.fn(async () => 'user-sk-plaintext'),
|
|
encryptApiKey: vi.fn(async () => 'enc'),
|
|
hashApiKey: vi.fn(() => 'hash'),
|
|
}));
|
|
|
|
import { prisma } from '@/lib/prisma';
|
|
|
|
describe('applyByokToConfig', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it('injects user API key into config when active row exists', async () => {
|
|
vi.mocked(prisma.userAPIKey.findFirst).mockResolvedValue({
|
|
id: 'k1',
|
|
userId: 'u1',
|
|
provider: 'openai',
|
|
encryptedKey: 'enc',
|
|
keyHash: 'hash',
|
|
alias: '',
|
|
model: null,
|
|
isActive: true,
|
|
lastUsedAt: null,
|
|
lastUsedFor: null,
|
|
createdAt: new Date(),
|
|
updatedAt: new Date(),
|
|
} as never);
|
|
|
|
const base = { OPENAI_API_KEY: 'system-key' };
|
|
const { config, usedByok } = await applyByokToConfig('u1', 'openai', base);
|
|
|
|
expect(usedByok).toBe(true);
|
|
expect(config.OPENAI_API_KEY).toBe('user-sk-plaintext');
|
|
});
|
|
|
|
it('returns unchanged config when no BYOK row', async () => {
|
|
vi.mocked(prisma.userAPIKey.findFirst).mockResolvedValue(null);
|
|
|
|
const base = { OPENAI_API_KEY: 'system-key' };
|
|
const { config, usedByok } = await applyByokToConfig('u1', 'openai', base);
|
|
|
|
expect(usedByok).toBe(false);
|
|
expect(config.OPENAI_API_KEY).toBe('system-key');
|
|
});
|
|
});
|