|
1 | 1 | const isDifferent = require('../../../helper/diffPlaces').isDifferent;
|
2 | 2 | const isNameDifferent = require('../../../helper/diffPlaces').isNameDifferent;
|
3 | 3 | const normalizeString = require('../../../helper/diffPlaces').normalizeString;
|
| 4 | +const isEquivalentIdentity = require('../../../helper/diffPlaces').isEquivalentIdentity; |
4 | 5 |
|
5 | 6 | module.exports.tests = {};
|
6 | 7 |
|
@@ -539,6 +540,94 @@ module.exports.tests.isNameDifferent = function (test, common) {
|
539 | 540 | });
|
540 | 541 | };
|
541 | 542 |
|
| 543 | +module.exports.tests.isEquivalentIdentity = function (test, common) { |
| 544 | + test('basic equivalence', function (t) { |
| 545 | + t.true(isEquivalentIdentity( |
| 546 | + { source: 'test', source_id: '1', layer: 'example' }, |
| 547 | + { source: 'test', source_id: '1', layer: 'example' } |
| 548 | + ), 'same source, source_id and layer'); |
| 549 | + |
| 550 | + t.false(isEquivalentIdentity( |
| 551 | + { source: 'test', source_id: '1', layer: 'example' }, |
| 552 | + { source: 'foo', source_id: '1', layer: 'example' } |
| 553 | + ), 'different source'); |
| 554 | + |
| 555 | + t.false(isEquivalentIdentity( |
| 556 | + { source: 'test', source_id: '1', layer: 'example' }, |
| 557 | + { source: 'test', source_id: '2', layer: 'example' } |
| 558 | + ), 'different source_id'); |
| 559 | + |
| 560 | + // two records sharing the same source, source_id but with |
| 561 | + // differing layer are considered not equal. |
| 562 | + // in practice this should be rare/never happen but if it |
| 563 | + // becomes an issue would could consider making this stricter. |
| 564 | + t.false(isEquivalentIdentity( |
| 565 | + { source: 'test', source_id: '1', layer: 'example' }, |
| 566 | + { source: 'test', source_id: '1', layer: 'foo' } |
| 567 | + ), 'same source, source_id and layer'); |
| 568 | + |
| 569 | + // if either record fails to generate a valid GID then they are |
| 570 | + // considered not equivalent. |
| 571 | + t.false(isEquivalentIdentity( |
| 572 | + { source: 'test', source_id: '1' }, |
| 573 | + { source: 'test', source_id: '1', layer: 'example' } |
| 574 | + ), 'invalid GID'); |
| 575 | + |
| 576 | + t.end(); |
| 577 | + }); |
| 578 | + |
| 579 | + test('equivalence via parent hierarchy', function (t) { |
| 580 | + t.true(isEquivalentIdentity( |
| 581 | + { source: 'foo', source_id: '1', layer: 'example' }, |
| 582 | + { source: 'bar', source_id: '2', layer: 'example', parent: { |
| 583 | + example_id: '1', |
| 584 | + example_source: 'foo' |
| 585 | + } |
| 586 | + }), 'match parent GID'); |
| 587 | + |
| 588 | + t.false(isEquivalentIdentity( |
| 589 | + { source: 'foo', source_id: '1', layer: 'example' }, |
| 590 | + { source: 'bar', source_id: '2', layer: 'example', parent: { |
| 591 | + foo_id: '1', |
| 592 | + foo_source: 'foo' |
| 593 | + } |
| 594 | + }), 'parent name must be from same layer'); |
| 595 | + |
| 596 | + t.false(isEquivalentIdentity( |
| 597 | + { source: 'foo', source_id: '1', layer: 'example' }, |
| 598 | + { source: 'bar', source_id: '2', layer: 'example', parent: { |
| 599 | + foo_id: '1', |
| 600 | + example_source: 'foo' |
| 601 | + } |
| 602 | + }), 'parent name must have the same source_id'); |
| 603 | + |
| 604 | + t.false(isEquivalentIdentity( |
| 605 | + { source: 'foo', source_id: '1', layer: 'example' }, |
| 606 | + { source: 'bar', source_id: '2', layer: 'example', parent: { |
| 607 | + example_id: '1', |
| 608 | + example_source: 'not_foo' |
| 609 | + } |
| 610 | + }), 'parent name must have the same source'); |
| 611 | + |
| 612 | + t.true(isEquivalentIdentity( |
| 613 | + { source: 'whosonfirst', source_id: '1', layer: 'example' }, |
| 614 | + { source: 'test', source_id: '2', layer: 'example', parent: { |
| 615 | + example_id: '1' |
| 616 | + } |
| 617 | + }), 'parent source defaults to "whosonfirst"'); |
| 618 | + |
| 619 | + t.true(isEquivalentIdentity( |
| 620 | + { source: 'whosonfirst', source_id: '1', layer: 'example' }, |
| 621 | + { source: 'test', source_id: '2', layer: 'example', parent: { |
| 622 | + example_id: ['1'], |
| 623 | + example_source: [null] |
| 624 | + } |
| 625 | + }), 'parent source defaults to "whosonfirst" (arrays)'); |
| 626 | + |
| 627 | + t.end(); |
| 628 | + }); |
| 629 | +}; |
| 630 | + |
542 | 631 | module.exports.tests.normalizeString = function (test, common) {
|
543 | 632 | test('lowercase', function (t) {
|
544 | 633 | t.equal(normalizeString('Foo Bar'), 'foo bar');
|
|
0 commit comments