Skip to content

Commit

Permalink
test(api): moving api tests with fixture into the src directory
Browse files Browse the repository at this point in the history
  • Loading branch information
KhaledMohamedP committed Jul 1, 2017
1 parent 85c23a5 commit 814b68c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
10 changes: 5 additions & 5 deletions __tests__/api/general.spec.js → lib/__tests__/general.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// eslint-disable-next-line import/no-unresolved, import/no-extraneous-dependencies
const {mockDataObject} = require('mock-data'); // Note mock-data live under __mocks__ dir
const Translate = require('../../lib/translate-json-object');
const Translate = require('../translate-json-object');
const mock = require('../fixture/data.fixture');

const TJO = new Translate();
const init = jest.fn(TJO.init);
Expand Down Expand Up @@ -33,23 +33,23 @@ describe('Translate Module TJO: ', () => {

it('should fail to translate() using unkown service', () => {
init({unkownApiService: 'apiToken'});
return translate(mockDataObject, 'ar')
return translate(mock.dataObject, 'ar')
.catch(err => {
expect(err).toBeDefined();
});
});

it('Should fail to translate because of a missing language param: fail', () => {
init({yandexApiKey: 'apiToken'});
return translate(mockDataObject)
return translate(mock.dataObject)
.catch(err => {
expect(err).toBeDefined();
});
});

it('should TJO.translate fails, becuase of missing google/yandex token', () => {
init();
return translate(mockDataObject, 'ar')
return translate(mock.dataObject, 'ar')
.catch(err => {
expect(err).toBeDefined();
});
Expand Down
8 changes: 4 additions & 4 deletions __tests__/api/google.spec.js → lib/__tests__/google.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// eslint-disable-next-line import/no-unresolved, import/no-extraneous-dependencies
const {mockDataObject, transaltedES} = require('mock-data'); // Note mock-data live under __mocks__ dir
const Translate = require('../../lib/translate-json-object');
const Translate = require('../translate-json-object');
const mock = require('../fixture/data.fixture');

const TJO = new Translate();
const init = jest.fn(TJO.init);
Expand All @@ -9,9 +9,9 @@ const translate = jest.fn(TJO.translate);
describe('TJO Google Translate Service', () => {
it('Should transalte object: sucess', () => {
init({googleApiKey: 'apiToken'});
return translate(mockDataObject, 'es')
return translate(mock.dataObject, 'es')
.then(e => {
expect(e).toEqual(transaltedES);
expect(e).toEqual(mock.transaltedES);
});
});

Expand Down
8 changes: 4 additions & 4 deletions __tests__/api/yandex.spec.js → lib/__tests__/yandex.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// eslint-disable-next-line import/no-unresolved, import/no-extraneous-dependencies
const {mockDataObject, transaltedES} = require('mock-data');
const Translate = require('../../lib/translate-json-object');
const Translate = require('../translate-json-object');
const mock = require('../fixture/data.fixture');

const TJO = new Translate();
const init = jest.fn(TJO.init);
Expand All @@ -9,10 +9,10 @@ const translate = jest.fn(TJO.translate);
describe('TJO Yandex Translate Service', () => {
it('Should transalte object: success', () => {
init({yandexApiKey: 'apiToken'});
return translate(mockDataObject, 'es')
return translate(mock.dataObject, 'es')
.then(e => {
expect(e).toBeDefined();
expect(e).toEqual(transaltedES);
expect(e).toEqual(mock.transaltedES);
});
});

Expand Down
5 changes: 2 additions & 3 deletions __mocks__/mock-data.js → lib/fixture/data.fixture.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

const mockDataObject = {name: 'name', some: [{name: 'j'}], addressField: ['city', 'state', 'zipdecode'], bool: true, num: 33, badBool: false, nully: null, undefin: undefined};
const dataObject = {name: 'name', some: [{name: 'j'}], addressField: ['city', 'state', 'zipdecode'], bool: true, num: 33, badBool: false, nully: null, undefin: undefined};
const transaltedES = {name: 'name-es', some: [{name: 'j-es'}], addressField: ['city-es', 'state-es', 'zipdecode-es'], bool: true, num: 33, badBool: false, nully: null, undefin: undefined};

module.exports = {
mockDataObject,
dataObject,
transaltedES
};

0 comments on commit 814b68c

Please sign in to comment.