feat(sms): Add support for Austria, Germany (#5624) r=@philbooth

Both countries have a rolloutRate of 0 so they can be soft-launched
and tested by visiting the /sms link directly.

fixes #5572
This commit is contained in:
Shane Tomlinson 2017-10-26 15:18:22 +01:00 коммит произвёл GitHub
Родитель ea199fe50e
Коммит b3b9d520a4
2 изменённых файлов: 85 добавлений и 6 удалений

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

@ -60,15 +60,41 @@ define((require, exports, module) => {
return (serverPhoneNumber) => format.replace(/\$\{serverPhoneNumber\}/, serverPhoneNumber);
}
function hasPrefix (num, prefix) {
return num.indexOf(prefix) === 0;
}
function ensurePrefix (prefix) {
return function (num) {
if (hasPrefix(num, prefix)) {
return num;
}
return `${prefix}${num}`;
};
}
module.exports = {
// Austria
// https://en.wikipedia.org/wiki/Telephone_numbers_in_Austria
AT: {
format: formatter('+43 ${serverPhoneNumber}'),
normalize: ensurePrefix('+43'),
pattern: /^(?:\+43)?\d{6,}$/,
prefix: '+43',
rolloutRate: 0 // being soft launched. Testers will need to open `/sms?service=sync&country=AT`
},
// Germany
// https://en.wikipedia.org/wiki/Telephone_numbers_in_Germany
DE: {
format: formatter('+49 ${serverPhoneNumber}'),
normalize: ensurePrefix('+49'),
pattern: /^(?:\+49)?\d{6,13}$/,
prefix: '+49',
rolloutRate: 0 // being soft launched. Testers will need to open `/sms?service=sync&country=DE`
},
GB: {
format: formatter('+44 ${serverPhoneNumber}'),
normalize (num) {
if (/^\+44/.test(num)) {
return num;
}
return `+44${num}`;
},
normalize: ensurePrefix('+44'),
pattern: /^(?:\+44)?\d{10,10}$/,
prefix: '+44'
},

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

@ -9,6 +9,59 @@ define((require, exports, module) => {
const CountryTelephoneInfo = require('lib/country-telephone-info');
describe('lib/country-telephone-info', () => {
describe('AT', () => {
const { format, normalize, pattern } = CountryTelephoneInfo.AT;
describe('format', () => {
it('formats correctly', () => {
assert.equal(format('1234567890'), '+43 1234567890');
});
});
describe('normalize', () => {
it('normalizes a number accepted by pattern correctly', () => {
assert.equal(normalize('+431234567890'), '+431234567890');
assert.equal(normalize('1234567890'), '+431234567890');
});
});
describe('pattern', () => {
it('validates correctly', () => {
assert.ok(pattern.test('123456'));
assert.ok(pattern.test('+43123456'));
assert.isFalse(pattern.test('+331234567890'));
});
});
});
describe('DE', () => {
const { format, normalize, pattern } = CountryTelephoneInfo.DE;
describe('format', () => {
it('formats correctly', () => {
assert.equal(format('1234567890'), '+49 1234567890');
});
});
describe('normalize', () => {
it('normalizes a number accepted by pattern correctly', () => {
assert.equal(normalize('+491234567890'), '+491234567890');
assert.equal(normalize('1234567890'), '+491234567890');
});
});
describe('pattern', () => {
it('validates correctly', () => {
assert.ok(pattern.test('123456'));
assert.ok(pattern.test('1234567890123'));
assert.ok(pattern.test('+49123456'));
assert.ok(pattern.test('+491234567890123'));
assert.isFalse(pattern.test('+331234567890'));
});
});
});
describe('GB', () => {
const { format, normalize, pattern } = CountryTelephoneInfo.GB;