import { GptService } from '@/services/gpt.service'; import { GptResponsePayload } from '@3cr/viewer-types-ts'; vi.mock('axios', async (importOriginal) => ({ ...(await importOriginal()), create: () => ({ post: vi.fn(), }), })); describe('GptService tests', () => { it('should instantiate', () => { expect(GptService.Instantiate()).toBeTruthy(); }); it('should generate response', async () => { const data: GptResponsePayload = { GptResponse: 'test', FollowupQuestions: [], }; const service = GptService.Instantiate(); vi.spyOn(service.client, 'post').mockResolvedValue({ data }); const response = await service.GenerateAnnotations('test', 0); expect(response).toBeDefined(); expect(response).toStrictEqual({ data }); }); it('should generate response as localhost', async () => { vi.spyOn(window, 'location', 'get').mockReturnValue({ href: 'https://localhost', } as Location); const data: GptResponsePayload = { GptResponse: 'test', FollowupQuestions: [], }; const service = GptService.Instantiate(); const spy = vi.spyOn(service.client, 'post').mockResolvedValue({ data }); const response = await service.GenerateAnnotations('test'); expect(response).toBeDefined(); expect(response).toStrictEqual({ data }); expect(spy).toHaveBeenCalledWith( 'https://test.api.singular.health/api/GPT/Smart/Annotation', null, expect.anything(), ); }); it('should generate response as test', async () => { vi.spyOn(window, 'location', 'get').mockReturnValue({ href: 'https://test.playground', } as Location); const data: GptResponsePayload = { GptResponse: 'test', FollowupQuestions: [], }; const service = GptService.Instantiate(); const spy = vi.spyOn(service.client, 'post').mockResolvedValue({ data }); const response = await service.GenerateAnnotations('test'); expect(response).toBeDefined(); expect(response).toStrictEqual({ data }); expect(spy).toHaveBeenCalledWith( 'https://test.api.singular.health/api/GPT/Smart/Annotation', null, expect.anything(), ); }); it('should generate response as next', async () => { vi.spyOn(window, 'location', 'get').mockReturnValue({ href: 'https://next.playground', } as Location); const data: GptResponsePayload = { GptResponse: 'test', FollowupQuestions: [], }; const service = GptService.Instantiate(); const spy = vi.spyOn(service.client, 'post').mockResolvedValue({ data }); const response = await service.GenerateAnnotations('test'); expect(response).toBeDefined(); expect(response).toStrictEqual({ data }); expect(spy).toHaveBeenCalledWith( 'https://test.api.singular.health/api/GPT/Smart/Annotation', null, expect.anything(), ); }); it('should generate response as prod', async () => { vi.spyOn(window, 'location', 'get').mockReturnValue({ href: 'https://playground', } as Location); const data: GptResponsePayload = { GptResponse: 'test', FollowupQuestions: [], }; const service = GptService.Instantiate(); const spy = vi.spyOn(service.client, 'post').mockResolvedValue({ data }); const response = await service.GenerateAnnotations('test'); expect(response).toBeDefined(); expect(response).toStrictEqual({ data }); expect(spy).toHaveBeenCalledWith( 'https://api.singular.health/api/GPT/Smart/Annotation', null, expect.anything(), ); }); });