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

Commit

Permalink
Merge pull request #1124 from mozilla/phil/issue-1123
Browse files Browse the repository at this point in the history
fix(server): permit null values in devices response
  • Loading branch information
rfk committed Nov 22, 2015
2 parents 551ee15 + 3407f4e commit 7718e0c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/routes/account.js
Expand Up @@ -764,10 +764,10 @@ module.exports = function (
schema: isA.array().items(isA.object({
id: isA.string().length(32).regex(HEX_STRING).required(),
isCurrentDevice: isA.boolean().required(),
name: isA.string().max(255).optional().allow(''),
name: isA.string().max(255).optional().allow('').allow(null),
type: isA.string().max(16).required(),
pushCallback: isA.string().uri({ scheme: 'https' }).max(255).optional().allow(''),
pushPublicKey: isA.string().length(64).regex(HEX_STRING).optional()
pushCallback: isA.string().uri({ scheme: 'https' }).max(255).optional().allow('').allow(null),
pushPublicKey: isA.string().length(64).regex(HEX_STRING).optional().allow(null)
}))
}
},
Expand Down
4 changes: 2 additions & 2 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions test/remote/device_tests.js
Expand Up @@ -205,10 +205,10 @@ TestServer.start(config)
.then(
function (devices) {
t.equal(devices.length, 1, 'devices returned one item')
t.equal(devices[0].name, undefined, 'devices returned undefined name')
t.equal(devices[0].name, null, 'devices returned undefined name')
t.equal(devices[0].type, deviceInfo.type, 'devices returned correct type')
t.equal(devices[0].pushCallback, undefined, 'devices returned undefined pushCallback')
t.deepEqual(devices[0].pushPublicKey, undefined, 'devices returned undefined pushPublicKey')
t.equal(devices[0].pushCallback, null, 'devices returned undefined pushCallback')
t.deepEqual(devices[0].pushPublicKey, null, 'devices returned undefined pushPublicKey')
return client.destroyDevice(devices[0].id)
}
)
Expand Down Expand Up @@ -258,6 +258,15 @@ TestServer.start(config)
.then(
function (devices) {
t.equal(devices.length, 2, 'devices returned two items')
if (devices[0].name === deviceInfo[1].name) {
// database results are unordered, swap them if necessary
var swap = {}
Object.keys(devices[0]).forEach(function (key) {
swap[key] = devices[0][key]
devices[0][key] = devices[1][key]
devices[1][key] = swap[key]
})
}
t.equal(devices[0].isCurrentDevice, false, 'devices returned false isCurrentDevice for first item')
t.equal(devices[0].name, deviceInfo[0].name, 'devices returned correct name for first item')
t.equal(devices[0].type, deviceInfo[0].type, 'devices returned correct type for first item')
Expand Down

0 comments on commit 7718e0c

Please sign in to comment.