Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/unit tests #70

Open
wants to merge 27 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a11f830
fixed old tests
kostysh Jul 16, 2020
d239719
add tests
kostysh Jul 17, 2020
14d0911
fixed wrong GLIDER_ORGID env
kostysh Jul 19, 2020
e2e811a
added tests for parsers (used in hotels search)
kostysh Jul 19, 2020
111bdf3
added code coverage tool and configuration
kostysh Jul 20, 2020
4d1da92
added test for GliderError class
kostysh Jul 20, 2020
ba9dc90
added "code" case for the test for GliderError class
kostysh Jul 20, 2020
c49eb43
updated tests runner configuration
kostysh Jul 20, 2020
5269492
added test for searchHorel resolver
kostysh Jul 20, 2020
f8bad8f
added test for orderCreateWithOffer hotel order resolver
kostysh Jul 20, 2020
b2180f1
added test for mapFromOffer
kostysh Jul 20, 2020
eb21f7a
disabled mongo calls in testing mode
kostysh Jul 20, 2020
8e7ddca
fix lintig errors
kostysh Jul 20, 2020
edea38c
Linting enabled in CI configuration
kostysh Jul 20, 2020
cb0a918
added test for reduceContactInformation
kostysh Jul 22, 2020
647ec80
added tests for parsers: useDictionary, mergeHourAndDate
kostysh Jul 23, 2020
c303ca4
added test for parser: convertDateToAirportTime
kostysh Jul 23, 2020
4a325d4
added test for parser: reduceToProperty
kostysh Jul 23, 2020
2d003f0
added tests for parsers: roundCommissionDecimals & deepMerge
kostysh Jul 23, 2020
3ed02d9
fixed type in config; minor update for tests
kostysh Jul 23, 2020
467d9bc
added tests for utils: uniqueObjectsList & flatOneDepth
kostysh Jul 24, 2020
c5cb04d
tests structure changed
kostysh Jul 24, 2020
0929e89
tests structure update and new tests
kostysh Jul 24, 2020
5ce8f41
more tests for transformInputData
kostysh Aug 3, 2020
85f9faf
tests for transforInputData utils and soapTemplates
kostysh Aug 4, 2020
4a38881
tests for soapTemplates
kostysh Aug 18, 2020
ea08bad
more tests for soapTemplates
kostysh Aug 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added tests for utils: uniqueObjectsList & flatOneDepth
kostysh committed Jul 24, 2020
commit 467d9bc25bc48f12106ac3ea3f4ef211ef36ea7d
5 changes: 4 additions & 1 deletion helpers/jwt.js
Original file line number Diff line number Diff line change
@@ -58,7 +58,10 @@ module.exports.verifyJWT = async (type, jwt, isAdmin = false) => {
let didResult;
const cachedDidResult = JSON.parse(await redisClient.asyncGet(`didResult_${did}`));

if (cachedDidResult && typeof cachedDidResult.didDocument === 'object') {
if (!process.env.TESTING &&
cachedDidResult &&
typeof cachedDidResult.didDocument === 'object') {
/* istanbul ignore next */
didResult = cachedDidResult;
} else {
didResult = await orgIdResolver.resolve(did);
2 changes: 2 additions & 0 deletions helpers/transformInputData/utils/cardUtils.js
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ const cardCodesOTA = {
unionpay: 'CU',
electron: 'VE'
};
module.exports.cardCodesOTA = cardCodesOTA;

const cardCodesIATA = {
visa: 'VI',
@@ -23,6 +24,7 @@ const cardCodesIATA = {
jcb: 'JC',
uatp: 'TP',
};
module.exports.cardCodesIATA = cardCodesIATA;

module.exports.getCardCode = (card, type) => {
let cardCode;
128 changes: 128 additions & 0 deletions test/spec/helpers/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
const GliderError = require('../../../helpers/error');
const {
getCardCode,
cardCodesOTA,
cardCodesIATA
} = require('../../../helpers/transformInputData/utils/cardUtils');
const {
uniqueObjectsList,
flatOneDepth
} = require('../../../helpers/transformInputData/utils/collections');

require('chai').should();

describe('Helpers/**/utils', () => {

describe('#getCardCode', () => {
const cardsSet = [
{
type: 'ota',
source: cardCodesOTA
},
{
type: 'iata',
source: cardCodesIATA
}
];

it('should to throw if wrong card has been provided', async () => {
cardsSet.forEach(({ type }) => {
(() => getCardCode({
brand: undefined
}, type)).should.to.throw;
(() => getCardCode({
brand: 'UNKNOWN_CARD'
}, type)).should.to.throw;
(() => getCardCode({
brand: []
}, type)).should.to.throw;
(() => getCardCode({
brand: {}
}, type)).should.to.throw;
});
});

it('should to throw if wrong type has been provided', async () => {
cardsSet.forEach(({ source }) => {
Object.keys(source).forEach(c => {
(() => getCardCode({
brand: c
}, undefined)).should
.to.throw(GliderError, 'Missing Card Code type')
.with.property('status', 500);
(() => getCardCode({
brand: c
}, 'UNKNOWN_TYPE')).should
.to.throw(GliderError, 'Missing Card Code type')
.with.property('status', 500);
});
});
});

it('should return card codes by type', async () => {
cardsSet.forEach(({ type, source }) => {
Object.keys(source).forEach(c => {
const result = getCardCode({
brand: c
}, type);
(result).should.to.equal(source[c]);
});
});
});
});

describe('#uniqueObjectsList', () => {
const arrayOfObjects = [
{
a: 1
},
{
a: 2
},
{
c: 1
},
{
a: 1
}
];

it('should to throw if wrong array has been provided', async () => {
(() => uniqueObjectsList(undefined)).should.to.throw;
(() => uniqueObjectsList('wrongType')).should.to.throw;
(() => uniqueObjectsList({})).should.to.throw;
});

it('should return unique objects array', async () => {
const result = uniqueObjectsList(arrayOfObjects);
const uniquesSet = new Set(result);
(Array.from(uniquesSet)).should.to.deep.equal(result);
});
});

describe('#flatOneDepth', () => {
const deepArray = [
1,
2,
[ 3, 4, 5, [ 6 ] ],
[ 7 ],
8
];
const flatArray = [
1, 2, 3,
4, 5, [ 6 ],
7, 8
];

it('should to throw if wrong array has been provided', async () => {
(() => flatOneDepth(undefined)).should.to.throw;
(() => flatOneDepth('wrongType')).should.to.throw;
(() => flatOneDepth({})).should.to.throw;
});

it('should return flat array', async () => {
const result = flatOneDepth(deepArray);
(result).should.to.be.an('array').to.deep.equal(flatArray);
});
});
});