From 8b5875f6ae8b12d58d0caaf08dc79ce46a60682a Mon Sep 17 00:00:00 2001 From: missinglink Date: Wed, 9 Oct 2019 13:00:20 +0200 Subject: [PATCH] test(dedupe): additional test coverage --- helper/diffPlaces.js | 1 + test/unit/helper/diffPlaces.js | 79 +++++++++++++++++++++++++++++++++- 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/helper/diffPlaces.js b/helper/diffPlaces.js index 90f40be62..418d38d1d 100644 --- a/helper/diffPlaces.js +++ b/helper/diffPlaces.js @@ -235,4 +235,5 @@ function normalizeString(str){ module.exports.isDifferent = isDifferent; module.exports.layerPreferences = layerPreferences; +module.exports.isNameDifferent = isNameDifferent; module.exports.normalizeString = normalizeString; diff --git a/test/unit/helper/diffPlaces.js b/test/unit/helper/diffPlaces.js index c37a5cd4b..a966943a7 100644 --- a/test/unit/helper/diffPlaces.js +++ b/test/unit/helper/diffPlaces.js @@ -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 = {}; @@ -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'); @@ -359,7 +435,6 @@ module.exports.tests.normalizeString = function (test, common) { t.equal(normalizeString('àáâãäåấắæầằçḉèéêëếḗềḕ'), 'aaaaaaaaaeaacceeeeeeee'); t.end(); }); - }; module.exports.all = function (tape, common) {