chore: activer ESLint sur le backend
Installe eslint, ajoute le script lint, modernise le parser (retrait de babel-eslint obsolète) et applique l'autofix (points-virgules manquants sur l'ensemble du code, conformément à la règle "semi" déjà présente dans .eslintrc mais jamais appliquée faute d'ESLint installé et d'un script pour l'exécuter).
This commit is contained in:
@@ -1,60 +1,60 @@
|
||||
import {describe, it, expect, vi, afterEach} from 'vitest'
|
||||
import {describe, it, expect, vi, afterEach} from 'vitest';
|
||||
|
||||
const {default: createService} = await import('../parole.js')
|
||||
const {default: createService} = await import('../parole.js');
|
||||
|
||||
function fakeDeeplResponse(text) {
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => ({translations: [{text}]})
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
describe('Translator (DeepL)', () => {
|
||||
const originalFetch = global.fetch
|
||||
const originalFetch = global.fetch;
|
||||
|
||||
afterEach(() => {
|
||||
global.fetch = originalFetch
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
global.fetch = originalFetch;
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('attache un timeout à la requête DeepL', async () => {
|
||||
global.fetch = vi.fn(async () => fakeDeeplResponse('hello'))
|
||||
global.fetch = vi.fn(async () => fakeDeeplResponse('hello'));
|
||||
|
||||
const strapi = {contentType: vi.fn(() => ({uid: 'api::parole.parole', kind: 'collectionType'}))}
|
||||
const service = createService({strapi})
|
||||
await service.translate('FR', 'EN', 'bonjour')
|
||||
const strapi = {contentType: vi.fn(() => ({uid: 'api::parole.parole', kind: 'collectionType'}))};
|
||||
const service = createService({strapi});
|
||||
await service.translate('FR', 'EN', 'bonjour');
|
||||
|
||||
const [, options] = global.fetch.mock.calls[0]
|
||||
expect(options.signal).toBeInstanceOf(AbortSignal)
|
||||
})
|
||||
})
|
||||
const [, options] = global.fetch.mock.calls[0];
|
||||
expect(options.signal).toBeInstanceOf(AbortSignal);
|
||||
});
|
||||
});
|
||||
|
||||
describe('translateLyrics', () => {
|
||||
const originalFetch = global.fetch
|
||||
const originalFetch = global.fetch;
|
||||
|
||||
afterEach(() => {
|
||||
global.fetch = originalFetch
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
global.fetch = originalFetch;
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('continue les autres langues quand une traduction DeepL échoue', async () => {
|
||||
global.fetch = vi.fn(async (_url, options) => {
|
||||
const {target_lang: target} = JSON.parse(options.body)
|
||||
const {target_lang: target} = JSON.parse(options.body);
|
||||
if (target === 'ES') {
|
||||
return {ok: false, status: 500, text: async () => 'boom'}
|
||||
return {ok: false, status: 500, text: async () => 'boom'};
|
||||
}
|
||||
|
||||
return fakeDeeplResponse(`traduit-${target}`)
|
||||
})
|
||||
return fakeDeeplResponse(`traduit-${target}`);
|
||||
});
|
||||
|
||||
const strapi = {
|
||||
contentType: vi.fn(() => ({uid: 'api::parole.parole', kind: 'collectionType'})),
|
||||
log: {error: vi.fn()}
|
||||
}
|
||||
const service = createService({strapi})
|
||||
const result = await service.translateLyrics('Bonjour le monde')
|
||||
};
|
||||
const service = createService({strapi});
|
||||
const result = await service.translateLyrics('Bonjour le monde');
|
||||
|
||||
expect(result.anglais).toContain('traduit-EN')
|
||||
expect(result.espagnol).toBeUndefined()
|
||||
})
|
||||
})
|
||||
expect(result.anglais).toContain('traduit-EN');
|
||||
expect(result.espagnol).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user