|
|
@@ -2,6 +2,7 @@ const SandboxedModule = require('sandboxed-module')
|
|
|
const assert = require('assert')
|
|
|
const path = require('path')
|
|
|
const sinon = require('sinon')
|
|
|
+const { expect } = require('chai')
|
|
|
const modulePath = path.join(
|
|
|
__dirname,
|
|
|
'../../../../app/src/infrastructure/GeoIpLookup'
|
|
|
@@ -204,62 +205,76 @@ describe('GeoIpLookup', function () {
|
|
|
describe('async', function () {
|
|
|
it('should return GBP for GB country', async function () {
|
|
|
this.request.get.callsArgWith(1, null, null, this.stubbedResponse)
|
|
|
- const currencyCode = await this.GeoIpLookup.promises.getCurrencyCode(
|
|
|
- this.ipAddress
|
|
|
- )
|
|
|
+ const {
|
|
|
+ currencyCode,
|
|
|
+ countryCode,
|
|
|
+ } = await this.GeoIpLookup.promises.getCurrencyCode(this.ipAddress)
|
|
|
currencyCode.should.equal('GBP')
|
|
|
+ countryCode.should.equal('GB')
|
|
|
})
|
|
|
|
|
|
it('should return GBP for gb country', async function () {
|
|
|
this.stubbedResponse.country_code = 'gb'
|
|
|
this.request.get.callsArgWith(1, null, null, this.stubbedResponse)
|
|
|
- const currencyCode = await this.GeoIpLookup.promises.getCurrencyCode(
|
|
|
- this.ipAddress
|
|
|
- )
|
|
|
+ const {
|
|
|
+ currencyCode,
|
|
|
+ countryCode,
|
|
|
+ } = await this.GeoIpLookup.promises.getCurrencyCode(this.ipAddress)
|
|
|
currencyCode.should.equal('GBP')
|
|
|
+ countryCode.should.equal('GB')
|
|
|
})
|
|
|
|
|
|
it('should return USD for US', async function () {
|
|
|
this.stubbedResponse.country_code = 'US'
|
|
|
this.request.get.callsArgWith(1, null, null, this.stubbedResponse)
|
|
|
- const currencyCode = await this.GeoIpLookup.promises.getCurrencyCode(
|
|
|
- this.ipAddress
|
|
|
- )
|
|
|
+ const {
|
|
|
+ currencyCode,
|
|
|
+ countryCode,
|
|
|
+ } = await this.GeoIpLookup.promises.getCurrencyCode(this.ipAddress)
|
|
|
currencyCode.should.equal('USD')
|
|
|
+ countryCode.should.equal('US')
|
|
|
})
|
|
|
|
|
|
it('should return EUR for DE', async function () {
|
|
|
this.stubbedResponse.country_code = 'DE'
|
|
|
this.request.get.callsArgWith(1, null, null, this.stubbedResponse)
|
|
|
- const currencyCode = await this.GeoIpLookup.promises.getCurrencyCode(
|
|
|
- this.ipAddress
|
|
|
- )
|
|
|
+ const {
|
|
|
+ currencyCode,
|
|
|
+ countryCode,
|
|
|
+ } = await this.GeoIpLookup.promises.getCurrencyCode(this.ipAddress)
|
|
|
currencyCode.should.equal('EUR')
|
|
|
+ countryCode.should.equal('DE')
|
|
|
})
|
|
|
|
|
|
it('should default to USD if there is an error', async function () {
|
|
|
this.request.get.callsArgWith(1, null, null, { error: true })
|
|
|
- const currencyCode = await this.GeoIpLookup.promises.getCurrencyCode(
|
|
|
- this.ipAddress
|
|
|
- )
|
|
|
+ const {
|
|
|
+ currencyCode,
|
|
|
+ countryCode,
|
|
|
+ } = await this.GeoIpLookup.promises.getCurrencyCode(this.ipAddress)
|
|
|
currencyCode.should.equal('USD')
|
|
|
+ expect(countryCode).to.be.undefined
|
|
|
})
|
|
|
|
|
|
it('should default to USD if there are no details', async function () {
|
|
|
this.request.get.callsArgWith(1, null, null, {})
|
|
|
- const currencyCode = await this.GeoIpLookup.promises.getCurrencyCode(
|
|
|
- this.ipAddress
|
|
|
- )
|
|
|
+ const {
|
|
|
+ currencyCode,
|
|
|
+ countryCode,
|
|
|
+ } = await this.GeoIpLookup.promises.getCurrencyCode(this.ipAddress)
|
|
|
currencyCode.should.equal('USD')
|
|
|
+ expect(countryCode).to.be.undefined
|
|
|
})
|
|
|
|
|
|
it('should default to USD if there is no match for their country', async function () {
|
|
|
this.stubbedResponse.country_code = 'Non existant'
|
|
|
this.request.get.callsArgWith(1, null, null, this.stubbedResponse)
|
|
|
- const currencyCode = await this.GeoIpLookup.promises.getCurrencyCode(
|
|
|
- this.ipAddress
|
|
|
- )
|
|
|
+ const {
|
|
|
+ currencyCode,
|
|
|
+ countryCode,
|
|
|
+ } = await this.GeoIpLookup.promises.getCurrencyCode(this.ipAddress)
|
|
|
currencyCode.should.equal('USD')
|
|
|
+ countryCode.should.equal('NON EXISTANT')
|
|
|
})
|
|
|
})
|
|
|
})
|