Bug 1081154 - Loop direct calls should attempt to call phone numbers as well as email addresses. r=mikedeboer

This commit is contained in:
Mark Banner 2014-10-16 18:58:59 +01:00
Родитель 9b7f6776df
Коммит 31882135a2
2 изменённых файлов: 91 добавлений и 3 удалений

Просмотреть файл

@ -327,10 +327,25 @@ loop.store.ConversationStore = (function() {
*/
_setupOutgoingCall: function() {
var contactAddresses = [];
var contact = this.get("contact");
this.get("contact").email.forEach(function(address) {
contactAddresses.push(address.value);
});
function appendContactValues(property, strip) {
if (contact.hasOwnProperty(property)) {
contact[property].forEach(function(item) {
if (strip) {
contactAddresses.push(item.value
.replace(/^(\+)?(.*)$/g, function(m, prefix, number) {
return (prefix || "") + number.replace(/[\D]+/g, "");
}));
} else {
contactAddresses.push(item.value);
}
});
}
}
appendContactValues("email");
appendContactValues("tel", true);
this.client.setupOutgoingCall(contactAddresses,
this.get("callType"),

Просмотреть файл

@ -276,6 +276,79 @@ describe("loop.store.ConversationStore", function () {
["fakeEmail"], sharedUtils.CALL_TYPES.AUDIO_VIDEO);
});
it("should include all email addresses in the call data", function() {
contact = {
name: [ "Mr Smith" ],
email: [{
type: "home",
value: "fakeEmail",
pref: true
},
{
type: "work",
value: "emailFake",
pref: false
}]
};
dispatcher.dispatch(
new sharedActions.GatherCallData(outgoingCallData));
sinon.assert.calledOnce(client.setupOutgoingCall);
sinon.assert.calledWith(client.setupOutgoingCall,
["fakeEmail", "emailFake"], sharedUtils.CALL_TYPES.AUDIO_VIDEO);
});
it("should include trim phone numbers for the call data", function() {
contact = {
name: [ "Mr Smith" ],
tel: [{
type: "home",
value: "+44-5667+345 496(2335)45+ 456+",
pref: true
}]
};
dispatcher.dispatch(
new sharedActions.GatherCallData(outgoingCallData));
sinon.assert.calledOnce(client.setupOutgoingCall);
sinon.assert.calledWith(client.setupOutgoingCall,
["+445667345496233545456"], sharedUtils.CALL_TYPES.AUDIO_VIDEO);
});
it("should include all email and telephone values in the call data", function() {
contact = {
name: [ "Mr Smith" ],
email: [{
type: "home",
value: "fakeEmail",
pref: true
}, {
type: "work",
value: "emailFake",
pref: false
}],
tel: [{
type: "work",
value: "01234567890",
pref: false
}, {
type: "home",
value: "09876543210",
pref: false
}]
};
dispatcher.dispatch(
new sharedActions.GatherCallData(outgoingCallData));
sinon.assert.calledOnce(client.setupOutgoingCall);
sinon.assert.calledWith(client.setupOutgoingCall,
["fakeEmail", "emailFake", "01234567890", "09876543210"],
sharedUtils.CALL_TYPES.AUDIO_VIDEO);
});
describe("server response handling", function() {
beforeEach(function() {
sandbox.stub(dispatcher, "dispatch");