-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactor eligibility helper for test.
- Loading branch information
1 parent
054bb8b
commit 4a2c8d1
Showing
3 changed files
with
104 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache(); | ||
var sinon = require('sinon'); | ||
var almaAddressHelper = require('../../mocks/helpers/almaAddressHelper'); | ||
|
||
var logger = { | ||
getLogger: function () { | ||
return { | ||
info: sinon.stub() | ||
}; | ||
} | ||
}; | ||
|
||
|
||
function proxyModel() { | ||
return proxyquire( | ||
'../../../cartridges/int_alma/cartridge/scripts/helpers/almaEligibilityHelper', | ||
{ | ||
'dw/system/Logger': logger, | ||
'*/cartridge/scripts/helpers/almaAddressHelper': almaAddressHelper | ||
} | ||
); | ||
} | ||
module.exports = { | ||
almaEligibilityHelperMocks: proxyModel(), | ||
logger: logger | ||
}; |
58 changes: 58 additions & 0 deletions
58
test/unit/int_alma/scripts/helpers/almaEligibilityHelperTest.js
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,58 @@ | ||
'use strict'; | ||
|
||
// almaEligibilityHelper.js unit tests | ||
|
||
var assert = require('chai').assert; | ||
var expect = require('chai').expect; | ||
var almaEligibilityHelperMocks = require('../../../../mocks/helpers/almaEligibilityHelperMocks').almaEligibilityHelperMocks; | ||
var basketMock = require('../../../../mocks/dw/order/BasketMgr'); | ||
|
||
var baseReturn = | ||
{ | ||
purchase_amount: 25000, | ||
queries: [], | ||
locale: 'fr_FR', | ||
billing_address: { | ||
title: 'address.jobTitle', | ||
first_name: 'address.lastName', | ||
last_name: 'address.firstName', | ||
company: 'address.companyName', | ||
line1: 'address.address1', | ||
line2: 'address.address2', | ||
postal_code: 'address.postalCode', | ||
city: 'address.city', | ||
country: 'address.countryCode.value', | ||
state_province: 'address.stateCode', | ||
phone: 'address.phone' | ||
}, | ||
shipping_address: { | ||
title: 'address.jobTitle', | ||
first_name: 'address.lastName', | ||
last_name: 'address.firstName', | ||
company: 'address.companyName', | ||
line1: 'address.address1', | ||
line2: 'address.address2', | ||
postal_code: 'address.postalCode', | ||
city: 'address.city', | ||
country: 'address.countryCode.value', | ||
state_province: 'address.stateCode', | ||
phone: 'address.phone' | ||
} | ||
}; | ||
|
||
var baseBasket = basketMock.getCurrentBasket(); | ||
describe('Construct eligibility payload', function () { | ||
it('return a empty array for a null current bask', function () { | ||
var params = almaEligibilityHelperMocks.getParams([], 'fr_FR', null); | ||
// eslint-disable-next-line no-unused-expressions | ||
expect(params).to.be.an('array').that.is.empty; | ||
}); | ||
it('Return full eligibility payload for a basket', function () { | ||
var params = almaEligibilityHelperMocks.getParams([], 'fr_FR', baseBasket); | ||
assert.deepEqual( | ||
params, | ||
baseReturn | ||
); | ||
}); | ||
}); | ||
|