-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add "Google" provider. - Fix "Unit Tests" workflow on main branch.
- Loading branch information
Showing
18 changed files
with
380 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
version: "2" | ||
checks: | ||
method-complexity: | ||
config: | ||
threshold: 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,8 @@ jobs: | |
uses: paambaati/[email protected] | ||
env: | ||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} | ||
DEEPL_API_KEY: ${{ secrets.DEEPL_API_KEY }} | ||
MYMEMORY_API_KEY: ${{ secrets.MYMEMORY_API_KEY }} | ||
with: | ||
coverageCommand: yarn test | ||
debug: true |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,25 @@ | ||
import ProviderBase from '../../providers/ProviderBase' | ||
import DeeplProvider from '../../providers/DeeplProvider' | ||
import { config } from 'dotenv' | ||
import ProviderTester from './ProviderTester'; | ||
|
||
config() | ||
|
||
describe('DeeplProvider', () => { | ||
test('should get correct translation', async () => { | ||
const provider: ProviderBase = | ||
new DeeplProvider(process.env.DEEPL_API_KEY || '') | ||
const translations = await provider.translate('Poem', 'en-uk') | ||
expect(translations.length).toEqual(1) | ||
expect(translations[0]).toEqual('Вірш') | ||
}) | ||
let providerTester: ProviderTester | ||
|
||
test('should fail because of invalid lang', async () => { | ||
const provider: ProviderBase = | ||
beforeAll(() => { | ||
providerTester = new ProviderTester( | ||
new DeeplProvider(process.env.DEEPL_API_KEY || '') | ||
try { | ||
await provider.translate('Evening', 'en-abc123') | ||
} catch (e) { | ||
expect(e).toBeTruthy() | ||
return | ||
} | ||
throw new Error('Request should fail due to unknown target language') | ||
) | ||
}) | ||
|
||
test( | ||
'should get correct translation', | ||
async () => providerTester.positive() | ||
) | ||
|
||
test( | ||
'should fail because of invalid lang', | ||
async () => providerTester.negative() | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,24 @@ | ||
import FunTranslationsProvider from '../../providers/FunTranslationsProvider' | ||
import ProviderBase, { ProviderError } from '../../providers/ProviderBase' | ||
import ProviderTester from './ProviderTester' | ||
|
||
describe('FunTranslationsProvider', () => { | ||
test('should get correct translation', async () => { | ||
const provider: ProviderBase = new FunTranslationsProvider() | ||
try { | ||
const translations = await provider.translate('Evening', 'vulcan') | ||
expect(translations.length).toEqual(1) | ||
expect(translations[0]).toEqual('Khru') | ||
} catch (e: unknown) { | ||
if (!(e instanceof ProviderError)) { | ||
const { statusCode } = e as never | ||
if (statusCode !== 429) { | ||
throw e | ||
} | ||
} | ||
} | ||
}) | ||
let providerTester: ProviderTester | ||
|
||
test('should fail because of invalid lang', async () => { | ||
const provider: ProviderBase = new FunTranslationsProvider() | ||
try { | ||
await provider.translate('Evening', 'abc123') | ||
} catch (e) { | ||
expect(e).toBeTruthy() | ||
return | ||
} | ||
fail() | ||
beforeAll(() => { | ||
providerTester = new ProviderTester( | ||
new FunTranslationsProvider() | ||
) | ||
}) | ||
|
||
test( | ||
'should get correct translation', | ||
async () => providerTester.positive({ | ||
text: 'Evening', lang: 'vulcan', expected: 'Khru' | ||
}) | ||
) | ||
|
||
test( | ||
'should fail because of invalid lang', | ||
async () => providerTester.negative() | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import GoogleProvider from '../../providers/GoogleProvider' | ||
import ProviderTester from './ProviderTester' | ||
|
||
describe('GoogleProvider', () => { | ||
let providerTester: ProviderTester | ||
|
||
beforeAll(() => { | ||
providerTester = new ProviderTester( | ||
new GoogleProvider() | ||
) | ||
}) | ||
|
||
test( | ||
'should get correct translation', | ||
async () => providerTester.positive() | ||
) | ||
|
||
test( | ||
'should fail because of invalid lang', | ||
async () => providerTester.negative() | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,22 @@ | ||
import LinguaToolsProvider from '../../providers/LinguaToolsProvider' | ||
import ProviderBase, { ProviderError } from '../../providers/ProviderBase' | ||
import ProviderTester from './ProviderTester' | ||
|
||
describe('LinguaToolsProvider', () => { | ||
test.skip('should get correct translation', async () => { | ||
const provider: ProviderBase = new LinguaToolsProvider() | ||
const translations = await provider.translate('Evening', 'en-de') | ||
expect(translations.length).toEqual(1) | ||
expect(translations[0]).toEqual('Abend') | ||
}) | ||
let providerTester: ProviderTester | ||
|
||
test.skip('should fail because of invalid lang', async () => { | ||
const provider: ProviderBase = new LinguaToolsProvider() | ||
try { | ||
await provider.translate('Evening', 'abc123') | ||
} catch (e: unknown) { | ||
const { status } = e as ProviderError | ||
if (status === 404) { | ||
throw e | ||
} | ||
expect(e).toBeTruthy() | ||
return | ||
} | ||
throw new Error('Request should fail due to unknown lang') | ||
beforeAll(() => { | ||
providerTester = new ProviderTester( | ||
new LinguaToolsProvider() | ||
) | ||
}) | ||
|
||
test.skip( | ||
'should get correct translation', | ||
async () => providerTester.positive() | ||
) | ||
|
||
test.skip( | ||
'should fail because of invalid lang', | ||
async () => providerTester.negative() | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,58 @@ | ||
import itParam from 'mocha-param' | ||
import MyMemoryProvider from '../../providers/MyMemoryProvider' | ||
import ProviderBase from '../../providers/ProviderBase' | ||
import { config } from 'dotenv' | ||
import ProviderTester from './ProviderTester' | ||
|
||
config() | ||
|
||
type ProviderTesterWrapper = { | ||
providerTester: ProviderTester, | ||
type: string | ||
} | ||
|
||
describe('MyMemoryProvider', () => { | ||
itParam<string | undefined>('should get correct translation', | ||
[undefined, process.env.MYMEMORY_API_KEY], async (apiKey) => { | ||
const provider: ProviderBase = new MyMemoryProvider(apiKey) | ||
const translations = await provider.translate('Evening', 'en|pt') | ||
expect(translations.length).toBeGreaterThan(0) | ||
expect(translations[0]).toEqual('NOITE') | ||
}) | ||
const fixture: ProviderTesterWrapper[] = [{ | ||
providerTester: new ProviderTester(new MyMemoryProvider()), | ||
type: 'Free' | ||
}, { | ||
providerTester: new ProviderTester( | ||
new MyMemoryProvider(process.env.MYMEMORY_API_KEY) | ||
), | ||
type: 'Registered' | ||
}] | ||
|
||
itParam<ProviderTesterWrapper>( | ||
'[${value.type}] should get correct translation', | ||
fixture, | ||
async ({ providerTester }: ProviderTesterWrapper) => | ||
providerTester.positive({ | ||
text: 'Evening', lang: 'en|pt', expected: 'NOITE' | ||
}) | ||
) | ||
|
||
itParam<ProviderTesterWrapper>( | ||
'[${value.type}] should fail because of invalid lang', | ||
fixture, | ||
async ({ providerTester }: ProviderTesterWrapper) => | ||
providerTester.negative() | ||
) | ||
|
||
test('should fail because of invalid lang', async () => { | ||
const provider: ProviderBase = new MyMemoryProvider() | ||
try { | ||
await provider.translate('Evening', 'abc123') | ||
} catch (e) { | ||
expect(e).toBeTruthy() | ||
return | ||
} | ||
fail() | ||
}) | ||
// itParam<string | undefined>('should get correct translation', | ||
// [undefined, process.env.MYMEMORY_API_KEY], async (apiKey) => { | ||
// const provider: ProviderBase = new MyMemoryProvider(apiKey) | ||
// const translations = await provider.translate('Evening', 'en|pt') | ||
// expect(translations.length).toBeGreaterThan(0) | ||
// expect(translations[0]).toEqual('NOITE') | ||
// }) | ||
// | ||
// test('should fail because of invalid lang', async () => { | ||
// const provider: ProviderBase = new MyMemoryProvider() | ||
// try { | ||
// await provider.translate('Evening', 'abc123') | ||
// } catch (e) { | ||
// expect(e).toBeTruthy() | ||
// return | ||
// } | ||
// fail() | ||
// }) | ||
}) |
Oops, something went wrong.