Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robisim74 committed Mar 27, 2024
1 parent 682ae2b commit 3be8122
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export async function gptTranslateJson(options: GptTranslateJsonOptions) {

if (response?.choices) {
const content = response.choices[0].message?.content;
console.log(content);

if (content) {
const jsonContent = JSON.parse(content);
translatedTexts = [...translatedTexts, ...jsonContent]
Expand Down
4 changes: 2 additions & 2 deletions tests/add-lang.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test, describe, expect, vi } from 'vitest';

import { readdir, readFile, writeFile } from 'fs/promises';
import { normalize } from 'path';
import { OpenAIApi } from 'openai';
import OpenAI from 'openai';

import { gptTranslateJson } from '../src/index';
import { mockAddLangAsset, mockAddLangMetaTranslated, mockAddLangMetaTranslatedLangs, mockAddLangResponse, mockAddLangTranslatedAsset, mockAddTranslationMetaTranslated, mockAddTranslationMetaTranslatedLangs, mockAddTranslationTranslatedAsset } from './mock';
Expand Down Expand Up @@ -40,7 +40,7 @@ vi.mock('fs', async () => {

describe('gptTranslateJson', () => {
test('add lang', async () => {
vi.spyOn(OpenAIApi.prototype, 'createChatCompletion').mockImplementationOnce(() => Promise.resolve<any>({ data: mockAddLangResponse }));
vi.spyOn(OpenAI.Chat.Completions.prototype, 'create').mockImplementationOnce(() => Promise.resolve<any>(mockAddLangResponse));

await gptTranslateJson({
apiKey: 'openai_api_key',
Expand Down
4 changes: 2 additions & 2 deletions tests/add-translation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test, describe, expect, vi } from 'vitest';

import { readdir, readFile, writeFile } from 'fs/promises';
import { normalize } from 'path';
import { OpenAIApi } from 'openai';
import OpenAI from 'openai';

import { gptTranslateJson } from '../src/index';
import { mockAddTranslationAsset, mockAddTranslationMetaTranslated, mockAddTranslationMetaTranslatedLangs, mockAddTranslationResponse, mockAddTranslationTranslatedAsset, mockMetaTranslated, mockMetaTranslatedLangs, mockTranslatedAsset } from './mock';
Expand Down Expand Up @@ -39,7 +39,7 @@ vi.mock('fs', async () => {

describe('gptTranslateJson', () => {
test('add translation', async () => {
vi.spyOn(OpenAIApi.prototype, 'createChatCompletion').mockImplementationOnce(() => Promise.resolve<any>({ data: mockAddTranslationResponse }));
vi.spyOn(OpenAI.Chat.Completions.prototype, 'create').mockImplementationOnce(() => Promise.resolve<any>(mockAddTranslationResponse));

await gptTranslateJson({
apiKey: 'openai_api_key',
Expand Down
4 changes: 2 additions & 2 deletions tests/translate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test, describe, expect, vi } from 'vitest';

import { readdir, readFile, writeFile } from 'fs/promises';
import { normalize } from 'path';
import { OpenAIApi } from 'openai';
import OpenAI from 'openai';

import { gptTranslateJson } from '../src/index';
import { mockAsset, mockMetaTranslated, mockMetaTranslatedLangs, mockResponse, mockTranslatedAsset } from './mock';
Expand Down Expand Up @@ -31,7 +31,7 @@ vi.mock('fs', async () => {

describe('gptTranslateJson', () => {
test('translate', async () => {
vi.spyOn(OpenAIApi.prototype, 'createChatCompletion').mockImplementationOnce(() => Promise.resolve<any>({ data: mockResponse }));
vi.spyOn(OpenAI.Chat.Completions.prototype, 'create').mockImplementationOnce(() => Promise.resolve<any>(mockResponse));

await gptTranslateJson({
apiKey: 'openai_api_key',
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
Expand Down

0 comments on commit 3be8122

Please sign in to comment.