@salestrip/models
Advanced tools
Comparing version
@@ -90,3 +90,6 @@ 'use strict' | ||
hotels: hotels.map(getHotelConfiguration), | ||
travelportCredentials: getTravelportConfiguration( | ||
travelportConfiguration: getTravelportConfiguration( | ||
rawConfiguration | ||
), | ||
travelportCredentials: getTravelportCredentials( | ||
rawConfiguration.travelportCredentials, | ||
@@ -115,3 +118,3 @@ encryptionKey | ||
*/ | ||
function getTravelportConfiguration(travelportCredentials, encryptionKey) { | ||
function getTravelportCredentials(travelportCredentials, encryptionKey) { | ||
if (!travelportCredentials) { | ||
@@ -131,1 +134,29 @@ return null | ||
} | ||
/** | ||
* | ||
* @param {TenancyConfiguration.RawConfiguration} travelportConfiguration | ||
* @returns | ||
*/ | ||
function getTravelportConfiguration({travelportConfiguration}) { | ||
if (!travelportConfiguration) { | ||
return null | ||
} | ||
const response = { | ||
pcc: null, | ||
queueNumber: null | ||
} | ||
if (travelportConfiguration.pcc) { | ||
response.pcc = { | ||
code: travelportConfiguration.pcc | ||
} | ||
} | ||
if (travelportConfiguration.queueNumber) { | ||
response.queueNumber = travelportConfiguration.queueNumber | ||
} | ||
return response | ||
} |
@@ -13,5 +13,5 @@ 'use strict' | ||
findById: mockFindById, | ||
updateOne: mockUpdateOne | ||
updateOne: mockUpdateOne, | ||
} | ||
}) | ||
}), | ||
} | ||
@@ -25,3 +25,3 @@ const KEY = '6XM21rKwiIS6VV1SAMG5g3SK1fzVpZ8f' | ||
describe('should get the default configuration', () => { | ||
describe('given no configuration', () => { | ||
beforeEach(() => { | ||
@@ -31,3 +31,3 @@ mockFindById.mockResolvedValueOnce({}) | ||
it('should return the configuration', async () => { | ||
it('should return default configuration', async () => { | ||
const tenancyConfig = await sut | ||
@@ -46,2 +46,3 @@ .builder(database, KEY) | ||
"paymentType": "NONE", | ||
"travelportConfiguration": null, | ||
"travelportCredentials": null, | ||
@@ -53,3 +54,3 @@ } | ||
describe('should set a tenancy configuration', () => { | ||
describe('::setTenancyConfiguration', () => { | ||
beforeEach(async () => { | ||
@@ -61,4 +62,4 @@ mockUpdateOne.mockResolvedValueOnce({}) | ||
corporateDiscounts: '4TM', | ||
provider: 'TRAVELPORT' | ||
} | ||
provider: 'TRAVELPORT', | ||
}, | ||
], | ||
@@ -69,8 +70,8 @@ paymentType: 'PAYMENT_ON_INVOICE', | ||
password: 'passwordValue', | ||
branch: 'branchValue' | ||
} | ||
branch: 'branchValue', | ||
}, | ||
}) | ||
}) | ||
it('should attempt to save the configuration', async () => { | ||
it('should save the configuration', () => { | ||
// eslint-disable-next-line jest/prefer-strict-equal | ||
@@ -84,12 +85,12 @@ expect(mockUpdateOne.mock.calls.pop()).toEqual([ | ||
corporateDiscounts: '4TM', | ||
provider: 'TRAVELPORT' | ||
} | ||
provider: 'TRAVELPORT', | ||
}, | ||
], | ||
paymentType: 'PAYMENT_ON_INVOICE', | ||
travelportCredentials: expect.stringMatching(/\w:\w/) | ||
} | ||
travelportCredentials: expect.stringMatching(/\w:\w/), | ||
}, | ||
}, | ||
{ | ||
upsert: true | ||
} | ||
upsert: true, | ||
}, | ||
]) | ||
@@ -99,3 +100,3 @@ }) | ||
describe('should get configuration', () => { | ||
describe('::getConfiguration', () => { | ||
beforeEach(() => { | ||
@@ -107,9 +108,13 @@ mockFindById.mockResolvedValueOnce({ | ||
corporateDiscounts: '4TM', | ||
provider: 'TRAVELPORT' | ||
} | ||
provider: 'TRAVELPORT', | ||
}, | ||
], | ||
paymentType: 'PAYMENT_ON_INVOICE', | ||
travelportConfiguration: { | ||
pcc: 'pccValue', | ||
queueNumber: '10', | ||
}, | ||
travelportCredentials: | ||
// eslint-disable-next-line max-len | ||
'52d2c30805d4e83cacd0142286f10ab8:aaa9b313ff7efa4ee2208e2e2aec5a5ddc91e30ef2ad52189315e56b36803091f16a264d301fb168bab67bade60864b626d8f18493e6d338329bf2a35c65f0a0de0cb4a22e517d059d54c62f5d62e788' | ||
'52d2c30805d4e83cacd0142286f10ab8:aaa9b313ff7efa4ee2208e2e2aec5a5ddc91e30ef2ad52189315e56b36803091f16a264d301fb168bab67bade60864b626d8f18493e6d338329bf2a35c65f0a0de0cb4a22e517d059d54c62f5d62e788', | ||
}) | ||
@@ -132,2 +137,8 @@ }) | ||
"paymentType": "PAYMENT_ON_INVOICE", | ||
"travelportConfiguration": Object { | ||
"pcc": Object { | ||
"code": "pccValue", | ||
}, | ||
"queueNumber": "10", | ||
}, | ||
"travelportCredentials": Object { | ||
@@ -134,0 +145,0 @@ "branch": "branchValue", |
{ | ||
"name": "@salestrip/models", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Share model management", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -38,9 +38,18 @@ declare namespace TenancyConfiguration { | ||
travelportCredentials?: TravelportCredentials | ||
travelportConfiguration?: TravelportConfiguration | ||
} | ||
interface TravelportConfiguration{ | ||
pcc?: { | ||
code: string | ||
}, | ||
queueNumber?: string | ||
} | ||
interface RawConfiguration { | ||
paymentType?: PaymentType | ||
hotels?: Hotel[] | ||
travelportCredentials?: string | ||
travelportCredentials?: string, | ||
travelportConfiguration?: TravelportConfiguration | ||
} | ||
} |
18516
6.36%502
9.85%