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

Commit

Permalink
fix(sms): ditch the silly ad-hoc config file for sender ids
Browse files Browse the repository at this point in the history
#1722

r=vbudhram
  • Loading branch information
philbooth authored Mar 14, 2017
1 parent a9950ac commit 4cd6f9e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
10 changes: 10 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,16 @@ var conf = convict({
format: RegExp,
env: 'SMS_REGIONS'
},
senderIds: {
doc: 'Sender ids keyed by the region they apply to',
default: {
CA: '16474909977',
GB: 'Firefox',
US: '15036789977'
},
format: Object,
env: 'SMS_SENDER_IDS'
},
installFirefoxLink: {
doc: 'Link for the installFirefox SMS template',
default: 'https://mzl.la/1HOd4ec',
Expand Down
5 changes: 0 additions & 5 deletions config/sms-sender-ids.json

This file was deleted.

4 changes: 2 additions & 2 deletions lib/routes/sms.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const PhoneNumberUtil = require('google-libphonenumber').PhoneNumberUtil
const validators = require('./validators')

const METRICS_CONTEXT_SCHEMA = require('../metrics/context').schema
const SENDER_IDS = new Map(require('../../config/sms-sender-ids.json'))

module.exports = (log, isA, error, config, customs, sms) => {
if (! config.sms.enabled) {
Expand All @@ -18,6 +17,7 @@ module.exports = (log, isA, error, config, customs, sms) => {

const getGeoData = require('../geodb')(log)
const REGIONS = config.sms.regions
const SENDER_IDS = config.sms.senderIds

return [
{
Expand Down Expand Up @@ -68,7 +68,7 @@ module.exports = (log, isA, error, config, customs, sms) => {

function getRegionSpecificSenderId () {
const region = phoneNumberUtil.getRegionCodeForNumber(parsedPhoneNumber)
const senderId = SENDER_IDS.get(region)
const senderId = SENDER_IDS[region]

if (! senderId) {
throw error.invalidRegion(region)
Expand Down
7 changes: 6 additions & 1 deletion test/local/routes/sms.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ describe('/sms', () => {
log = mocks.spyLog()
config = {
sms: {
enabled: true
enabled: true,
senderIds: {
CA: '16474909977',
GB: 'Firefox',
US: '15036789977'
}
}
}
routes = makeRoutes({ log, config })
Expand Down

0 comments on commit 4cd6f9e

Please sign in to comment.