Skip to content

Commit

Permalink
test(dedupe): additional test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
missinglink authored and orangejulius committed Mar 12, 2021
1 parent 4ce1e10 commit d7f7b16
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
1 change: 1 addition & 0 deletions helper/diffPlaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,5 @@ function normalizeString(str){

module.exports.isDifferent = isDifferent;
module.exports.layerPreferences = layerPreferences;
module.exports.isNameDifferent = isNameDifferent;
module.exports.normalizeString = normalizeString;
79 changes: 77 additions & 2 deletions test/unit/helper/diffPlaces.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const isDifferent = require('../../../helper/diffPlaces').isDifferent;
const isNameDifferent = require('../../../helper/diffPlaces').isNameDifferent;
const normalizeString = require('../../../helper/diffPlaces').normalizeString;

module.exports.tests = {};
Expand Down Expand Up @@ -338,8 +339,83 @@ module.exports.tests.dedupe = function(test, common) {
});
};

module.exports.tests.normalizeString = function (test, common) {
module.exports.tests.isNameDifferent = function (test, common) {
test('missing names', function (t) {
t.false(isNameDifferent({}, {}), 'both have no name');
t.false(isNameDifferent({ name: { default: 'a' } }, {}), 'B has no name');
t.false(isNameDifferent({}, { name: { default: 'b' } }), 'A has no name');
t.end();
});
test('basic matching', function (t) {
t.false(isNameDifferent(
{ name: { default: 'a' } },
{ name: { default: 'a' } }
), 'basic match');

t.false(isNameDifferent(
{ name: { default: 'a' } },
{ name: { default: ['a'] } }
), 'basic match - different types');

t.false(isNameDifferent(
{ name: { default: ['a'] } },
{ name: { default: 'a' } }
), 'basic match - different types - inverse');

t.false(isNameDifferent(
{ name: { default: 'a' } },
{ name: { default: ['b','a'] } }
), 'basic match - different positions');

t.false(isNameDifferent(
{ name: { default: ['b', 'a'] } },
{ name: { default: 'a' } }
), 'basic match - different positions - inverse');

t.end();
});
test('inter-language matching', function (t) {
t.false(isNameDifferent(
{ name: { default: 'a' } },
{ name: { foo: 'a' } }
), 'match default with any lang');

t.false(isNameDifferent(
{ name: { foo: 'a' } },
{ name: { default: 'a' } }
), 'match default with any lang - inverse');

t.false(isNameDifferent(
{ name: { bar: 'a' } },
{ name: { foo: 'a' } },
'bar'
), 'match using request lang');

t.false(isNameDifferent(
{ name: { bar: 'a' } },
{ name: { foo: 'a' } },
'foo'
), 'match using request lang - inverse');

// note: this returns true
t.true(isNameDifferent(
{ name: { foo: 'a' } },
{ name: { bar: 'a' } }
), 'different lang');

t.end();
});
test('real-world tests', function (t) {
t.false(isNameDifferent(
{ name: { default: 'Malmoe', eng: 'Malmo' } },
{ name: { default: 'Malmö', eng: 'Malmo' } }
), 'Malmö');

t.end();
});
};

module.exports.tests.normalizeString = function (test, common) {
test('lowercase', function (t) {
t.equal(normalizeString('Foo Bar'), 'foo bar');
t.equal(normalizeString('FOOBAR'), 'foobar');
Expand All @@ -359,7 +435,6 @@ module.exports.tests.normalizeString = function (test, common) {
t.equal(normalizeString('àáâãäåấắæầằçḉèéêëếḗềḕ'), 'aaaaaaaaaeaacceeeeeeee');
t.end();
});

};

module.exports.all = function (tape, common) {
Expand Down

0 comments on commit d7f7b16

Please sign in to comment.