-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(googleService&yandexService): Fixing unit tests and increasing c…
…overage
- Loading branch information
1 parent
e171c34
commit 325f7af
Showing
5 changed files
with
149 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
var translate = require('../google'); | ||
|
||
// Mocked external node_modules | ||
jest.mock('google-translate'); | ||
|
||
// Mocked internal public methods | ||
jest.fn(translate.init); | ||
jest.fn(translate.object); | ||
jest.fn(translate.string); | ||
|
||
describe('google service existance', () => { | ||
it('should exist', () => { | ||
expect(translate).toBeDefined(); | ||
}); | ||
|
||
it('should include init', () => { | ||
expect(translate.init).toBeDefined(); | ||
}); | ||
|
||
it('should include string', () => { | ||
expect(translate.string).toBeDefined(); | ||
}); | ||
|
||
it('should include array', () => { | ||
expect(translate.object).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('Google translate.object: ', () => { | ||
it('should fail due missing language param', () => { | ||
translate.init({googleApiKey: 'google_token'}); | ||
return translate | ||
.object(null, {}, {}, ['key1', 'key2'], ['list', 'of', 'elements']) | ||
.catch(err => { | ||
expect(err).toBe('You missed to pass the languge'); | ||
}); | ||
}); | ||
|
||
it('should fail to transalte object due to invalid value', () => { | ||
translate.init({googleApiKey: 'google_token'}); | ||
return translate | ||
.object('ar', {}, {}, [], []) | ||
.catch(err => { | ||
expect(err).toBe('Something went wrong'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Google translate.string: ', () => { | ||
it('should fail due missing language param', () => { | ||
translate.init({googleApiKey: 'google_token'}); | ||
return translate | ||
.string(null, 'key', {}, '') | ||
.catch(err => { | ||
expect(err).toBe('You missed to pass the languge'); | ||
}); | ||
}); | ||
|
||
it('should failed due to invalid value', () => { | ||
translate.init({googleApiKey: 'google_token'}); | ||
return translate | ||
.string('es', 'key', {}, null) | ||
.catch(err => { | ||
expect(err).toBe('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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
var translate = require('../yandex'); | ||
|
||
// Mocked external node_modules | ||
jest.mock('yandex-translate'); | ||
|
||
// Mocked internal public methods | ||
jest.fn(translate.init); | ||
jest.fn(translate.object); | ||
jest.fn(translate.string); | ||
|
||
describe('Yandex service public API', () => { | ||
it('should exist', () => { | ||
expect(translate).toBeDefined(); | ||
}); | ||
|
||
it('should include init', () => { | ||
expect(translate.init).toBeDefined(); | ||
}); | ||
|
||
it('should include string', () => { | ||
expect(translate.string).toBeDefined(); | ||
}); | ||
|
||
it('should include array', () => { | ||
expect(translate.object).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('Yandex translate.object: ', () => { | ||
it('should fail due missing language param', () => { | ||
translate.init({yandexApiKey: 'yandex_token'}); | ||
return translate | ||
.object(null, {}, {}, [], ['list', 'of', 'elements']) | ||
.catch(err => { | ||
expect(err.status).toBe(404); | ||
expect(err.error).toBe('Invalid language'); | ||
}); | ||
}); | ||
|
||
it('should failed due to invalid value', () => { | ||
translate.init({yandexApiKey: 'yandex_token'}); | ||
return translate | ||
.object('ar', {}, {}, [], []) | ||
.catch(err => { | ||
expect(err).toBe('Something went wrong'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Yandex translate.string: ', () => { | ||
it('should fail due missing language param', () => { | ||
translate.init({yandexApiKey: 'yandex_token'}); | ||
return translate | ||
.string(null, 'key', {}, '') | ||
.catch(err => { | ||
expect(err.status).toBe(404); | ||
expect(err.error).toBe('Invalid language'); | ||
}); | ||
}); | ||
|
||
it('should failed due to invalid value', () => { | ||
translate.init({yandexApiKey: 'yandex_token'}); | ||
return translate | ||
.string('es', 'key', {}, null) | ||
.catch(err => { | ||
expect(err).toBe('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