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

feat(server): implement GET /sms/status#1681

Merged
philbooth merged 1 commit intomasterfrom
phil/issue-1646
Mar 1, 2017
Merged

feat(server): implement GET /sms/status#1681
philbooth merged 1 commit intomasterfrom
phil/issue-1646

Conversation

@philbooth
Copy link
Copy Markdown
Contributor

Fixes #1646, implementing an endpoint for the content server to call before showing the SMS view.

@mozilla/fxa-devs r?

/cc @shane-tomlinson

@philbooth
Copy link
Copy Markdown
Contributor Author

philbooth commented Feb 27, 2017

Hmm, tests are failing, reviewers hold your fire!

@philbooth
Copy link
Copy Markdown
Contributor Author

Breakage appears to be caused by recent db changes, I've updated shrinkwrap here. I could just change the assertions but I'd be happier if the person that updated the db could do it, just to be sure everything is as expected.

Closing this until #1682 is fixed.

@philbooth
Copy link
Copy Markdown
Contributor Author

Reviewers, fill your boots!

},
regions: {
doc: 'Valid ISO 3166-1 alpha-2 country codes for enabled regions',
default: /^(?:US|CA)$/,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may need to change this depending on the outcome of @shane-tomlinson's conversation with legal.

// in the old auth mailer. If/when the two config files are merged and
// there's nothing left that imports mailer/config, it is safe to merge
// raw.js and this file into one. Be careful not to mix the arguments
// legacy_index.js and this file into one. Be careful not to mix the args
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote this comment before I changed the name of that file in #1676 but only just spotted the mismatch, sorry.

Copy link
Copy Markdown

@shane-tomlinson shane-tomlinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested by integrating into the front end, but the API looks exactly as expected. A couple of small nits, nothing that I think really needs to be re-reviewed.

r+ - merge when ready.

})
}

function getLocation (getLocation) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the getLocation argument used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks like some kind of weird copy/paste error.


let isOk

return getStatus()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize there are only a couple of function calls, but I found the isOk check in getLocation a bit confusing before my brain has fully woken up. An alternative that might be easier to follow is to use Promise.all then array destructuring or Promise.spread on the result:

return Promise.all([
  getStatus(),
  getLocation()
])
.spread(createResponse)
.then(reply, reply);

function getStatus () {
  return sms.status()
    .then(statuts => status.isOk)
    .catch(...);
}

function getLocation () {
  return getGeoData(request.app.clientAddress)
    .then(result => REGIONS.test(result.location.countryCode))
    .catch(...);
}

function createResponse(isStatusOk, isLocationOk) {
  return { ok: isStatusOk && isLocationOk };
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point is to shortcut the call to getGeoData if we already know the status is false.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shortcut should be inverted actually, it's more likely that the getGeoData check will fail than the balance check.

})
})

describe('sms.status returns isOk:true and getGeoData returns CA', () => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think it makes sense to abstract the different country tests? The logic between this and the US variant are pretty similar.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think it makes sense to abstract the different country tests?

Although I'm in favour of abstracting setup and teardown, I see abstracted assertions as a massive anti-pattern. They make it harder for the casual reader to quickly grok the invariants and they encourage exhaustive testing, which can obscure where the important boundary conditions are covered.

I much prefer to only assert the important stuff, and to do it all longhand so that readers can quickly understand what the edge cases are.

^imho

},
{
method: 'GET',
path: '/sms/status',
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document this endpoint in API.md?

if (isOk) {
return getGeoData(request.app.clientAddress)
.then(result => {
if (! REGIONS.test(result.location.countryCode)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is location guaranteed to be a member of result?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea but it seems like the kind of thing we should treat as an error if it's missing.

Copy link
Copy Markdown

@shane-tomlinson shane-tomlinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woah, I just noticed the diff size:

+181,801 That's an awful lot. Did something go wrong with the shrinkwrap update?

@philbooth philbooth force-pushed the phil/issue-1646 branch 3 times, most recently from 5c1ff07 to b652b1b Compare February 28, 2017 12:23
@philbooth
Copy link
Copy Markdown
Contributor Author

Did something go wrong with the shrinkwrap update?

In the trade we refer to them as "merge conflicts".

@shane-tomlinson
Copy link
Copy Markdown

r+ - :shipit:

@philbooth philbooth merged commit 34f4390 into master Mar 1, 2017
@philbooth philbooth deleted the phil/issue-1646 branch March 1, 2017 11:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants