hmpo-countries-lib
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -12,3 +12,3 @@ 'use strict'; | ||
this._residentCountries = []; | ||
this._overseasCountries = []; | ||
this._countriesById = {}; | ||
@@ -59,4 +59,4 @@ this._countriesBySlug = {}; | ||
getResidentCountries() { | ||
return this._residentCountries; | ||
getOverseasCountries() { | ||
return this._overseasCountries; | ||
} | ||
@@ -67,3 +67,3 @@ | ||
let countries = this._countryCache.get('data'); | ||
this._residentCountries = _.filter( | ||
this._overseasCountries = _.filter( | ||
countries, | ||
@@ -110,5 +110,18 @@ country => country.id !== 'UK' | ||
isRestrictedById(id) { | ||
let data = this.getCountryDataById(id); | ||
return data && data.contentType === 7; | ||
} | ||
isActiveById(id) { | ||
let data = this.getCountryDataById(id); | ||
return data && data.status === 'ACTIVE'; | ||
} | ||
getSlugById(id) { | ||
let data = this.getCountryById(id); | ||
return data && data.slug; | ||
} | ||
} | ||
module.exports = CountriesCachedModel; |
{ | ||
"name": "hmpo-countries-lib", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Country lists", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -30,6 +30,6 @@ 'use strict'; | ||
let policyData = [ | ||
{ id: 'UK', channel: 'ONLINE', contentType: 1 }, | ||
{ id: 'FO', channel: 'ONLINE', contentType: 2 }, | ||
{ id: 'BA', channel: 'NA', contentType: 7 }, | ||
{ id: 'NA', channel: 'ONLINE', contentType: 7 } | ||
{ id: 'UK', channel: 'ONLINE', contentType: 1, status: 'ACTIVE' }, | ||
{ id: 'FO', channel: 'ONLINE', contentType: 2, status: 'INACTIVE' }, | ||
{ id: 'BA', channel: 'NA', contentType: 7, status: 'INACTIVE' }, | ||
{ id: 'NA', channel: 'ONLINE', contentType: 7, status: 'INACTIVE' } | ||
]; | ||
@@ -188,12 +188,12 @@ | ||
describe('getResidentCountries', () => { | ||
describe('getOverseasCountries', () => { | ||
it('should be a function', () => { | ||
instance.getResidentCountries.should.be.a('function'); | ||
instance.getOverseasCountries.should.be.a('function'); | ||
}); | ||
it('should return the value of the _residentCountries array', () => { | ||
instance._residentCountries = [ | ||
it('should return the value of the _overseasCountries array', () => { | ||
instance._overseasCountries = [ | ||
{ id: 'FO', slug: 'foo' } | ||
]; | ||
instance.getResidentCountries().should.deep.equal([ | ||
instance.getOverseasCountries().should.deep.equal([ | ||
{ id: 'FO', slug: 'foo' } | ||
@@ -209,5 +209,5 @@ ]); | ||
it('should set _residentCountries to all countries except the UK', () => { | ||
it('should set _overseasCountries to all countries except the UK', () => { | ||
instance._indexCountries(); | ||
instance._residentCountries.should.deep.equal([ | ||
instance._overseasCountries.should.deep.equal([ | ||
{ id: 'FO', slug: 'foo' }, | ||
@@ -248,6 +248,6 @@ { id: 'BA', slug: 'bar' }, | ||
instance._policiesById.should.deep.equal({ | ||
UK: { id: 'UK', channel: 'ONLINE', contentType: 1 }, | ||
FO: { id: 'FO', channel: 'ONLINE', contentType: 2 }, | ||
BA: { id: 'BA', channel: 'NA', contentType: 7 }, | ||
NA: { id: 'NA', channel: 'ONLINE', contentType: 7 } | ||
UK: { id: 'UK', channel: 'ONLINE', contentType: 1, status: 'ACTIVE' }, | ||
FO: { id: 'FO', channel: 'ONLINE', contentType: 2, status: 'INACTIVE' }, | ||
BA: { id: 'BA', channel: 'NA', contentType: 7, status: 'INACTIVE' }, | ||
NA: { id: 'NA', channel: 'ONLINE', contentType: 7, status: 'INACTIVE' } | ||
}); | ||
@@ -312,3 +312,9 @@ }); | ||
instance.getCountryDataById('UK').should.deep.equal( | ||
{ id: 'UK', slug: 'united-kingdom', channel: 'ONLINE', contentType: 1 } | ||
{ | ||
id: 'UK', | ||
slug: 'united-kingdom', | ||
status: 'ACTIVE', | ||
channel: 'ONLINE', | ||
contentType: 1 | ||
} | ||
); | ||
@@ -341,2 +347,3 @@ }); | ||
channel: 'ONLINE', | ||
status: 'ACTIVE', | ||
contentType: 1 | ||
@@ -353,2 +360,3 @@ }); | ||
instance._indexCountries(); | ||
instance._indexPolicies(); | ||
delete instance._policiesById['UK']; | ||
@@ -358,2 +366,67 @@ expect(instance.getCountryDataBySlug('united-kingdom')).to.equal(null); | ||
}); | ||
describe('getSlugById', () => { | ||
it('should be a function', () => { | ||
instance.getSlugById.should.be.a('function'); | ||
}); | ||
it('should get country slug when the id is given', () => { | ||
instance._indexCountries(); | ||
instance.getSlugById('UK').should.equal('united-kingdom'); | ||
}); | ||
it('should return undefined if country is not found', () => { | ||
instance._indexCountries(); | ||
expect(instance.getSlugById('??')).to.equal(undefined); | ||
}); | ||
}); | ||
describe('isRestrictedById', () => { | ||
it('should be a function', () => { | ||
instance.isRestrictedById.should.be.a('function'); | ||
}); | ||
it('should return true for a country that is restricted', () => { | ||
instance._indexCountries(); | ||
instance._indexPolicies(); | ||
instance.isRestrictedById('NA').should.equal(true); | ||
}); | ||
it('should return false for a country that is not restricted', () => { | ||
instance._indexCountries(); | ||
instance._indexPolicies(); | ||
instance.isRestrictedById('UK').should.equal(false); | ||
}); | ||
it('should return undefined if country is not found', () => { | ||
instance._indexCountries(); | ||
instance._indexPolicies(); | ||
expect(instance.isRestrictedById('??')).to.equal(undefined); | ||
}); | ||
}); | ||
describe('isActiveById', () => { | ||
it('should be a function', () => { | ||
instance.isActiveById.should.be.a('function'); | ||
}); | ||
it('should return true for a country that is active', () => { | ||
instance._indexCountries(); | ||
instance._indexPolicies(); | ||
instance.isActiveById('UK').should.equal(true); | ||
}); | ||
it('should return false for a country that is not active', () => { | ||
instance._indexCountries(); | ||
instance._indexPolicies(); | ||
instance.isActiveById('NA').should.equal(false); | ||
}); | ||
it('should return undefined if country is not found', () => { | ||
instance._indexCountries(); | ||
instance._indexPolicies(); | ||
expect(instance.isActiveById('??')).to.equal(undefined); | ||
}); | ||
}); | ||
}); |
22538
466