Skip to content

Commit

Permalink
fix(stores): getCountryCodes returns codes sorted (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ephigenia authored Apr 17, 2022
1 parent 0b5c143 commit d39cd0d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions source/lib/stores.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ module.exports = {

/**
* Returns an array with all ISO 3166-1 alpha 2 country codes that have at
* least one store.
* least one store in alphabetical order.
* @returns {string[]} two-letter ISO 3166-2 alpha 2 country codes
*/
getCountryCodes: function() {
return Array.from(new Set(data.map(store => store.countryCode)));
return Array.from(new Set(data.map(store => store.countryCode)))
.sort((a, b) => a.localeCompare(b));
},

/**
Expand Down
4 changes: 3 additions & 1 deletion source/lib/stores.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ describe('stores', function() {
}); // getLanguageCode

describe('getCountryCodes', function() {
it('returns an array of supported country codes', () => {
it('returns an array of ordered supported country codes', () => {
const codes = stores.getCountryCodes();
expect(codes.length).to.be.gte(1);
expect(codes[0]).to.equal('at');
expect(codes[1]).to.equal('au');
});
}); // getCountryCodes
}); // suite

0 comments on commit d39cd0d

Please sign in to comment.