Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #20801 from jmcanterafonseca/fix_sim_dups_another
Browse files Browse the repository at this point in the history
Bug 1028106 - Invalid information of automated merged contacts and conta...
  • Loading branch information
jmcanterafonseca committed Jun 23, 2014
2 parents 919d4a2 + 09a1a3e commit 5a737b5
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 24 deletions.
75 changes: 61 additions & 14 deletions apps/communications/contacts/test/unit/contacts_matcher_test.js
Expand Up @@ -345,19 +345,19 @@ suite('Test Contacts Matcher', function() {

suite('SIM Contacts Matching', function() {
var existingSimContact = {
id: '1B',
category: ['sim'],
name: ['Juan Ramón del SIM'],
givenName: ['Juan Ramón del SIM'],
tel: [{
type: ['home'],
value: '676767671'
}],
email: [{
type: ['personal'],
value: 'jj@jj.com'
}]
};
id: '1B',
category: ['sim'],
name: ['Juan Ramón del SIM'],
givenName: ['Juan Ramón del SIM'],
tel: [{
type: ['home'],
value: '676767671'
}],
email: [{
type: ['personal'],
value: 'jj@jj.com'
}]
};

var incomingSimContact = {
id: '678',
Expand Down Expand Up @@ -451,7 +451,54 @@ suite('Test Contacts Matcher', function() {
MockFindMatcher.setData(contact);
done();
});
}); // Test
});

test('SIM Contact. Multiple names matching. Only one by SIM url',
function(done) {
var existing1 = Object.create(existingSimContact);
existing1.url = [
{
type: ['sim', 'source'],
value: '12345-6789'
}
];
// Avoiding matching by other criteria
existing1.tel = null;
existing1.email = null;

var incoming = Object.create(incomingSimContact);
incoming.url = [
{
type: ['sim', 'source'],
value: '6666-9999'
}
];
incoming.name = existing1.name;
incoming.givenName = existing1.givenName;
incoming.familyName = existing1.familyName;

var existing2 = Object.create(incoming);
existing2.id = 'vtrew12';

MockFindMatcher.setData(null);
MockFindMatcher.setFoundData([existing1, existing2]);

var callbacks = {
onmatch: function(results) {
var resultList = Object.keys(results);
assert.equal(resultList.length, 1);
assert.equal(results[resultList[0]].matchingContact.id,
existing2.id);
MockFindMatcher.setData(contact);
MockFindMatcher.setFoundData(null);
done();
},
onmismatch: function() {
done('error');
}
};
contacts.Matcher.match(incoming, 'passive', callbacks);
}); // Test
}); // SIM Suite
}); // Passive Merge Suite

Expand Down
13 changes: 13 additions & 0 deletions apps/communications/contacts/test/unit/mock_find_matcher.js
Expand Up @@ -5,6 +5,15 @@
var MockFindMatcher = {
find: function(options) {
this.result = [];

if (!this.data && Array.isArray(this.foundData)) {
return {
result: this.foundData,
set onsuccess(cb) {
cb();
}
};
}

var value;

Expand Down Expand Up @@ -91,5 +100,9 @@ var MockFindMatcher = {

setData: function(data) {
this.data = data;
},

setFoundData: function(data) {
this.foundData = data;
}
};
28 changes: 18 additions & 10 deletions shared/js/contacts/contacts_matcher.js
Expand Up @@ -232,10 +232,10 @@ contacts.Matcher = (function() {
};
matchByTel(aContact, localCbs, options);
}

function getSourceSimUrl(aContact) {
var out;

if (Array.isArray(aContact.category) &&
aContact.category.indexOf('sim') !== -1 && Array.isArray(aContact.url)) {
for (var j = 0; j < aContact.url.length; j++) {
Expand All @@ -246,17 +246,17 @@ contacts.Matcher = (function() {
}
}
}

return out;
}

// Implements the silent mode matching
function doMatchPassive(aContact, callbacks) {
if (!hasName(aContact)) {
notifyMismatch(callbacks);
return;
}

// SIM Contacts are detected and matched accordingly
// We try to match by name and then try to see if they correspond to
// the same SIM contact. In that case matching is reported
Expand All @@ -268,20 +268,28 @@ contacts.Matcher = (function() {
performPassiveMatch(aContact, callbacks);
}
}

function performPassiveMatchForSimContact(simUrl, aContact, callbacks) {
var localCbs = {
onmatch: function(results) {
var matchingFound = false;

Object.keys(results).forEach(function(aResultId) {
var matchingContact = results[aResultId].matchingContact;
var matchingUrl = getSourceSimUrl(matchingContact);
if (matchingUrl && matchingUrl === simUrl) {
callbacks.onmatch(results);
}
else {
performPassiveMatch(aContact, callbacks);
matchingFound = true;
var matchings = {};
matchings[aResultId] = {
matchingContact: matchingContact
};
callbacks.onmatch(matchings);
return;
}
});
if (!matchingFound) {
performPassiveMatch(aContact, callbacks);
}
},
onmismatch: function() {
performPassiveMatch(aContact, callbacks);
Expand Down

0 comments on commit 5a737b5

Please sign in to comment.