101 lines
3.5 KiB
JavaScript
101 lines
3.5 KiB
JavaScript
import { createPinia, setActivePinia } from 'pinia';
|
|
import CopilotConfigAPI from 'dashboard/api/copilotConfig';
|
|
import { useCaptainConfigStore } from './preferences';
|
|
|
|
vi.mock('dashboard/api/copilotConfig', () => ({
|
|
default: {
|
|
getAccountConfig: vi.fn(),
|
|
updateAccountConfig: vi.fn(),
|
|
getPlatformConfig: vi.fn(),
|
|
updatePlatformConfig: vi.fn(),
|
|
testPlatformConfig: vi.fn(),
|
|
getEmbeddingReindexStatus: vi.fn(),
|
|
startEmbeddingReindex: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
const accountPayload = {
|
|
providers: { openai: { display_name: 'OpenAI' } },
|
|
models: { 'account-model': { provider: 'openai' } },
|
|
features: {
|
|
editor: {
|
|
default: 'platform-model',
|
|
selected: 'account-model',
|
|
models: [],
|
|
},
|
|
},
|
|
behavior: { tone: 'friendly' },
|
|
provider_config: { configured: true, chat: { model: 'account-view' } },
|
|
};
|
|
|
|
describe('Copilot configuration store', () => {
|
|
beforeEach(() => {
|
|
setActivePinia(createPinia());
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it('loads account config and replaces provider details for SuperAdmin', async () => {
|
|
CopilotConfigAPI.getAccountConfig.mockResolvedValue({
|
|
data: accountPayload,
|
|
});
|
|
CopilotConfigAPI.getPlatformConfig.mockResolvedValue({
|
|
data: { configured: true, chat: { model: 'platform-model' } },
|
|
});
|
|
CopilotConfigAPI.getEmbeddingReindexStatus.mockResolvedValue({
|
|
data: { running: false, processed: 3, total: 3 },
|
|
});
|
|
const store = useCaptainConfigStore();
|
|
|
|
await store.fetch({ includePlatform: true });
|
|
|
|
expect(store.behavior.tone).toBe('friendly');
|
|
expect(store.features.editor.selected).toBe('account-model');
|
|
expect(store.providerConfig.chat.model).toBe('platform-model');
|
|
expect(CopilotConfigAPI.getPlatformConfig).toHaveBeenCalledOnce();
|
|
expect(store.embeddingReindexStatus.processed).toBe(3);
|
|
expect(store.uiFlags.isFetching).toBe(false);
|
|
});
|
|
|
|
it('does not request platform secrets for an account administrator', async () => {
|
|
CopilotConfigAPI.getAccountConfig.mockResolvedValue({
|
|
data: accountPayload,
|
|
});
|
|
const store = useCaptainConfigStore();
|
|
|
|
await store.fetch();
|
|
|
|
expect(CopilotConfigAPI.getPlatformConfig).not.toHaveBeenCalled();
|
|
expect(store.providerConfig.chat.model).toBe('account-view');
|
|
});
|
|
|
|
it('uses separate account, platform save, and provider test endpoints', async () => {
|
|
CopilotConfigAPI.updateAccountConfig.mockResolvedValue({
|
|
data: { ...accountPayload, behavior: { tone: 'formal' } },
|
|
});
|
|
CopilotConfigAPI.updatePlatformConfig.mockResolvedValue({
|
|
data: { configured: true, chat: { model: 'saved-model' } },
|
|
});
|
|
CopilotConfigAPI.testPlatformConfig.mockResolvedValue({
|
|
data: { chat: { ok: true }, embedding: { ok: true } },
|
|
});
|
|
CopilotConfigAPI.startEmbeddingReindex.mockResolvedValue({
|
|
data: { running: true, processed: 0, total: 2 },
|
|
});
|
|
const store = useCaptainConfigStore();
|
|
|
|
await store.updateAccountConfig({ behavior: { tone: 'formal' } });
|
|
await store.updatePlatformConfig({ chat: { model: 'saved-model' } });
|
|
await store.testPlatformConfig({ chat: { model: 'candidate-model' } });
|
|
await store.startEmbeddingReindex();
|
|
|
|
expect(store.behavior.tone).toBe('formal');
|
|
expect(store.providerConfig.chat.model).toBe('saved-model');
|
|
expect(store.providerTestResult.embedding.ok).toBe(true);
|
|
expect(CopilotConfigAPI.updateAccountConfig).toHaveBeenCalledOnce();
|
|
expect(CopilotConfigAPI.updatePlatformConfig).toHaveBeenCalledOnce();
|
|
expect(CopilotConfigAPI.testPlatformConfig).toHaveBeenCalledOnce();
|
|
expect(CopilotConfigAPI.startEmbeddingReindex).toHaveBeenCalledOnce();
|
|
expect(store.embeddingReindexStatus.running).toBe(true);
|
|
});
|
|
});
|