Parse phone numbers into e164 as part of schema upgrade

This commit is contained in:
Scott Nonnenberg 2018-05-08 18:03:02 -07:00
parent 8cb1f1f532
commit aa13a2c6f7
8 changed files with 87 additions and 8 deletions

View file

@ -36,6 +36,46 @@ describe('Contact', () => {
assert.deepEqual(result, message.contact[0]);
});
it('turns phone numbers to e164 format', async () => {
const upgradeAttachment = sinon
.stub()
.throws(new Error("Shouldn't be called"));
const upgradeVersion = Contact.parseAndWriteAvatar(upgradeAttachment);
const message = {
body: 'hey there!',
contact: [
{
name: {
displayName: 'Someone Somewhere',
},
number: [
{
type: 1,
value: '(202) 555-0099',
},
],
},
],
};
const expected = {
name: {
displayName: 'Someone Somewhere',
},
number: [
{
type: 1,
value: '+12025550099',
},
],
};
const result = await upgradeVersion(message.contact[0], {
message,
regionCode: 'US',
});
assert.deepEqual(result, expected);
});
it('removes contact avatar if it has no sub-avatar', async () => {
const upgradeAttachment = sinon
.stub()

View file

@ -277,6 +277,7 @@ describe('Message', () => {
assert.deepEqual(attachmentData, expectedAttachmentData);
return 'abc/abcdefg';
},
getRegionCode: () => 'US',
};
const actual = await Message.upgradeSchema(input, context);
assert.deepEqual(actual, expected);