From 0b01d8f434b3b19a8aaef0b95a444184eb5a7845 Mon Sep 17 00:00:00 2001 From: Moises Trigueros Date: Sat, 24 Oct 2020 01:19:59 -0600 Subject: [PATCH 1/2] Add unit test to helper module --- server/test/helper.test.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 server/test/helper.test.js diff --git a/server/test/helper.test.js b/server/test/helper.test.js new file mode 100644 index 00000000..e523254d --- /dev/null +++ b/server/test/helper.test.js @@ -0,0 +1,34 @@ +const helper = require('../routes/helpers'); +const mockHelper = require('../routes/__mocks__/helpers'); +const consts = require('./test-consts'); +const { getLanguage } = helper; + +describe('getLanguage', () => { + it('returns german when selectedLanguages is undefined', () => { + const defaultLanguage = getLanguage(undefined); + expect(defaultLanguage).toEqual('german'); + }); + + it('returns the language on list when there is only 1 language in selectedLanguages', () => { + const selectedLanguage = 'spanish'; + const language = getLanguage(selectedLanguage); + expect(language).toEqual('spanish'); + }); + + it('returns a random language inside the selectedLanguages', () => { + const selectedLanguages = "spanish,chinese,english,arabic"; + const language = getLanguage(selectedLanguages); + expect(selectedLanguages.split(',')).toEqual(expect.arrayContaining( + [language] + )); + }); + }); + +describe('getPhoto', () => { + + it ('returns a photo', () => { + mockHelper.getPhoto().then( (resultado) => { + expect(resultado).toEqual(consts.UNSPLASH_API_RET_IMAGE); + }); + }); +}); \ No newline at end of file From 9f96f70eedf2c01dc4c75e377d603834878de3f4 Mon Sep 17 00:00:00 2001 From: Moises Trigueros Date: Sat, 24 Oct 2020 12:22:39 -0600 Subject: [PATCH 2/2] Fix code according to eslint --- server/test/helper.test.js | 42 ++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/server/test/helper.test.js b/server/test/helper.test.js index e523254d..07cfb257 100644 --- a/server/test/helper.test.js +++ b/server/test/helper.test.js @@ -1,34 +1,32 @@ const helper = require('../routes/helpers'); const mockHelper = require('../routes/__mocks__/helpers'); const consts = require('./test-consts'); + const { getLanguage } = helper; describe('getLanguage', () => { - it('returns german when selectedLanguages is undefined', () => { - const defaultLanguage = getLanguage(undefined); - expect(defaultLanguage).toEqual('german'); - }); - - it('returns the language on list when there is only 1 language in selectedLanguages', () => { - const selectedLanguage = 'spanish'; - const language = getLanguage(selectedLanguage); - expect(language).toEqual('spanish'); - }); - - it('returns a random language inside the selectedLanguages', () => { - const selectedLanguages = "spanish,chinese,english,arabic"; - const language = getLanguage(selectedLanguages); - expect(selectedLanguages.split(',')).toEqual(expect.arrayContaining( - [language] - )); - }); + it('returns german when selectedLanguages is undefined', () => { + const defaultLanguage = getLanguage(undefined); + expect(defaultLanguage).toEqual('german'); + }); + it('returns the language on list when there is only 1 language in selectedLanguages', () => { + const selectedLanguage = 'spanish'; + const language = getLanguage(selectedLanguage); + expect(language).toEqual('spanish'); }); + it('returns a random language inside the selectedLanguages', () => { + const selectedLanguages = 'spanish,chinese,english,arabic'; + const language = getLanguage(selectedLanguages); + expect(selectedLanguages.split(',')).toEqual( + expect.arrayContaining([language]), + ); + }); +}); describe('getPhoto', () => { - - it ('returns a photo', () => { - mockHelper.getPhoto().then( (resultado) => { + it('returns a photo', () => { + mockHelper.getPhoto().then((resultado) => { expect(resultado).toEqual(consts.UNSPLASH_API_RET_IMAGE); }); }); -}); \ No newline at end of file +});