New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hmpo-countries-lib

Package Overview
Dependencies
Maintainers
4
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hmpo-countries-lib - npm Package Compare versions

Comparing version 4.0.3 to 5.0.0

56

lib/index.js

@@ -32,3 +32,5 @@ 'use strict';

this._countryCache.on('change', this._indexCountries.bind(this));
this.on('change', this._indexCountries.bind(this));
this.on('fail', this.onFail.bind(this));
this.on('error', this.onError.bind(this));
}

@@ -137,4 +139,56 @@

}
sortCountryList(list) {
list = _.sortBy(list, 'displayName');
let gb = _.find(list, {countryCode: 'GB'});
if (gb) {
list = _.reject(list, {countryCode: 'GB'});
list.unshift(gb);
}
return list;
}
dropdownList(list, isWelsh) {
list = this.sortCountryList(list);
return list.map(i => ({
value: i.countryCode,
text: isWelsh ? i.displayNameWelsh : i.displayName,
label: isWelsh ? i.displayNameWelsh : i.displayName
}));
}
dropdownListBirthCountries(isWelsh) {
return this.dropdownList(this.getBirthCountries(), isWelsh);
}
dropdownListOverseasBirthCountries(isWelsh) {
return this.dropdownList(this.getOverseasBirthCountries(), isWelsh);
}
dropdownListResidenceCountries(isWelsh) {
return this.dropdownList(this.getResidenceCountries(), isWelsh);
}
dropdownListOverseasResidenceCountries(isWelsh) {
return this.dropdownList(this.getOverseasResidenceCountries(), isWelsh);
}
onFail(err, data, settings, statusCode, responseTime) {
const errorText = (err && err.message) || (data && data.error) || '';
this._countryCache.logger.outbound('Countries CachedModel request failed :outVerb :outRequest :outResponseCode :outError', {
outVerb: settings.method,
outRequest: settings.url,
outResponseCode: statusCode,
outResponseTime: responseTime,
outError: errorText,
outErrorBody: this._countryCache.logger.trimHtml(err.body)
});
}
onError(err) {
this._countryCache.logger.outbound('Countries CachedModel request error :err.message', err);
}
}
module.exports = CountriesCachedModel;

16

package.json
{
"name": "hmpo-countries-lib",
"version": "4.0.3",
"version": "5.0.0",
"description": "Country lists",

@@ -21,3 +21,3 @@ "main": "./lib",

"engines": {
"node": ">=8"
"node": ">=10"
},

@@ -29,4 +29,4 @@ "bugs": {

"dependencies": {
"debug": "^4.3.1",
"hmpo-cached-model": "^3.0.3",
"debug": "^4.3.3",
"hmpo-cached-model": "^4.0.0",
"underscore": "^1.13.1"

@@ -36,8 +36,8 @@ },

"chai": "^4.3.4",
"eslint": "^7.26.0",
"mocha": "^8.4.0",
"eslint": "^8.3.0",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"proxyquire": "^2.1.3",
"sinon": "^10.0.0",
"sinon-chai": "^3.6.0"
"sinon": "^12.0.1",
"sinon-chai": "^3.7.0"
},

@@ -44,0 +44,0 @@ "nyc": {

@@ -11,5 +11,4 @@ 'use strict';

const CountriesCachedModel = require('../../lib');
const HmpoCachedModel = require('hmpo-cached-model');
let unitedKingdom = {
const unitedKingdom = {
countryCode: 'GB',

@@ -20,2 +19,3 @@ countryNameSlug: 'united-kingdom',

displayName: 'United Kingdom',
displayNameWelsh: 'Welsh United Kingdom',
channel: 'ONLINE',

@@ -25,3 +25,3 @@ contentType: 1,

};
let foo = {
const foo = {
countryCode: 'FO',

@@ -32,2 +32,3 @@ countryNameSlug: 'foo',

displayName: 'Foo',
displayNameWelsh: 'Welsh Foo',
channel: 'ONLINE',

@@ -37,3 +38,3 @@ contentType: 2,

};
let bar = {
const bar = {
countryCode: 'BA',

@@ -44,2 +45,3 @@ countryNameSlug: 'bar',

displayName: 'Bar',
displayNameWelsh: 'Welsh Bar',
channel: 'NA',

@@ -49,3 +51,3 @@ contentType: 7,

};
let narnia = {
const narnia = {
countryCode: 'NA',

@@ -56,2 +58,3 @@ countryNameSlug: 'narnia',

displayName: 'Narnia',
displayNameWelsh: 'Welsh Narnia',
channel: 'ONLINE',

@@ -62,3 +65,3 @@ contentType: 7,

let countries = [unitedKingdom, foo, bar, narnia];
const countries = [foo, unitedKingdom, bar, narnia];

@@ -70,6 +73,2 @@ describe('CountriesCachedModel', () => {

clock = sinon.useFakeTimers(1234567890000);
sinon.stub(HmpoCachedModel.prototype, 'start');
sinon.stub(HmpoCachedModel.prototype, 'stop');
sinon.stub(HmpoCachedModel.prototype, 'on');
sinon.stub(HmpoCachedModel.prototype, 'get');

@@ -87,2 +86,6 @@ stubs = {

countryCache: {
logger: {
outbound: sinon.stub(),
trimHtml: sinon.stub().returnsArg(0)
},
start: sinon.stub(),

@@ -116,6 +119,2 @@ stop: sinon.stub(),

afterEach(() => {
HmpoCachedModel.prototype.start.restore();
HmpoCachedModel.prototype.stop.restore();
HmpoCachedModel.prototype.on.restore();
HmpoCachedModel.prototype.get.restore();
clock.restore();

@@ -154,5 +153,7 @@ });

it('should attach indexers to cache change events', () => {
stubs.countryCache.on.should.have.been.calledOnce;
it('should attach loggers to failures, and indexers to cache change events', () => {
stubs.countryCache.on.should.have.been.calledThrice;
stubs.countryCache.on.should.have.been.calledWithExactly('change', sinon.match.func);
stubs.countryCache.on.should.have.been.calledWithExactly('fail', sinon.match.func);
stubs.countryCache.on.should.have.been.calledWithExactly('error', sinon.match.func);
});

@@ -362,2 +363,3 @@ });

displayName: 'United Kingdom',
displayNameWelsh: 'Welsh United Kingdom',
status: 'ACTIVE',

@@ -388,2 +390,3 @@ channel: 'ONLINE',

displayName: 'United Kingdom',
displayNameWelsh: 'Welsh United Kingdom',
countryOfBirthFlag: true,

@@ -475,3 +478,3 @@ channel: 'ONLINE',

instance._residenceCountries.should.deep.equal([
unitedKingdom, foo
foo, unitedKingdom
]);

@@ -531,2 +534,159 @@ });

});
describe('dropdownList', () => {
it('turns a list of countries into sorted drop down select box options with GB at the top', () => {
const items = instance.dropdownList(countries, false);
items.should.deep.equal([
{ value: 'GB', text: 'United Kingdom', label: 'United Kingdom' },
{ value: 'BA', text: 'Bar', label: 'Bar' },
{ value: 'FO', text: 'Foo', label: 'Foo' },
{ value: 'NA', text: 'Narnia', label: 'Narnia' }
]);
});
it('turns a list of countries into sorted drop down select box options with GB at the top using Welsh displayNames', () => {
const items = instance.dropdownList(countries, true);
items.should.deep.equal([
{ value: 'GB', text: 'Welsh United Kingdom', label: 'Welsh United Kingdom' },
{ value: 'BA', text: 'Welsh Bar', label: 'Welsh Bar' },
{ value: 'FO', text: 'Welsh Foo', label: 'Welsh Foo' },
{ value: 'NA', text: 'Welsh Narnia', label: 'Welsh Narnia' }
]);
});
});
describe('dropdownListBirthCountries', () => {
it('turns a list of countries into drop down select box options', () => {
instance._indexCountries();
const items = instance.dropdownListBirthCountries();
items.should.deep.equal([
{ value: 'GB', text: 'United Kingdom', label: 'United Kingdom' },
{ value: 'BA', text: 'Bar', label: 'Bar' }
]);
});
it('turns a list of countries into drop down select box options in welsh', () => {
instance._indexCountries();
const items = instance.dropdownListBirthCountries(true);
items.should.deep.equal([
{ value: 'GB', text: 'Welsh United Kingdom', label: 'Welsh United Kingdom' },
{ value: 'BA', text: 'Welsh Bar', label: 'Welsh Bar' }
]);
});
});
describe('dropdownListOverseasBirthCountries', () => {
it('turns a list of countries into drop down select box options', () => {
instance._indexCountries();
const items = instance.dropdownListOverseasBirthCountries();
items.should.deep.equal([
{ value: 'BA', text: 'Bar', label: 'Bar' }
]);
});
it('turns a list of countries into drop down select box options in welsh', () => {
instance._indexCountries();
const items = instance.dropdownListOverseasBirthCountries(true);
items.should.deep.equal([
{ value: 'BA', text: 'Welsh Bar', label: 'Welsh Bar' }
]);
});
});
describe('dropdownListResidenceCountries', () => {
it('turns a list of countries into drop down select box options', () => {
instance._indexCountries();
const items = instance.dropdownListResidenceCountries();
items.should.deep.equal([
{ value: 'GB', text: 'United Kingdom', label: 'United Kingdom' },
{ value: 'FO', text: 'Foo', label: 'Foo' }
]);
});
it('turns a list of countries into drop down select box options in welsh', () => {
instance._indexCountries();
const items = instance.dropdownListResidenceCountries(true);
items.should.deep.equal([
{ value: 'GB', text: 'Welsh United Kingdom', label: 'Welsh United Kingdom' },
{ value: 'FO', text: 'Welsh Foo', label: 'Welsh Foo' }
]);
});
});
describe('dropdownListOverseasResidenceCountries', () => {
it('turns a list of countries into drop down select box options', () => {
instance._indexCountries();
const items = instance.dropdownListOverseasResidenceCountries();
items.should.deep.equal([
{ value: 'FO', text: 'Foo', label: 'Foo' }
]);
});
it('turns a list of countries into drop down select box options in welsh', () => {
instance._indexCountries();
const items = instance.dropdownListOverseasResidenceCountries(true);
items.should.deep.equal([
{ value: 'FO', text: 'Welsh Foo', label: 'Welsh Foo' }
]);
});
});
describe('onFail logger', () => {
let settings;
beforeEach(() => {
settings = {
method: 'GET',
url: 'http://example.com/test/path'
};
});
it('should log the returned error message', () => {
const err = new Error('test');
err.body = '<body><tag>error text</tag></body>';
instance.onFail(err, {}, settings, 123, 1234567);
stubs.countryCache.logger.outbound.should.have.been.calledWithExactly(
'Countries CachedModel request failed :outVerb :outRequest :outResponseCode :outError',
{
outVerb: 'GET',
outRequest: 'http://example.com/test/path',
outResponseCode: 123,
outResponseTime: 1234567,
outError: 'test',
outErrorBody: '<body><tag>error text</tag></body>'
}
);
});
it('should log the data error message', () => {
instance.onFail({}, { error: 'test' }, settings, 123, 1234567);
stubs.countryCache.logger.outbound.args[0][1].outError.should.equal('test');
});
it('should log an empty string if no error is available', () => {
instance.onFail({}, {}, settings, 123, 1234567);
stubs.countryCache.logger.outbound.args[0][1].outError.should.equal('');
});
});
describe('onError logger', () => {
it('should log the returned error message', () => {
let err = new Error('test');
instance.onError(err);
stubs.countryCache.logger.outbound.should.have.been.calledWithExactly(
'Countries CachedModel request error :err.message',
err
);
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc