fix(notifications): Send disable notification to all devices

This commit is contained in:
udara 2017-05-24 09:42:01 -04:00 коммит произвёл Vlad Filippov
Родитель 009428e422
Коммит 91ce14c3f0
2 изменённых файлов: 8 добавлений и 9 удалений

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

@ -218,7 +218,7 @@ module.exports = function (log, db, config) {
} }
})) }))
var options = { data: data, TTL: TTL_DEVICE_DISCONNECTED } var options = { data: data, TTL: TTL_DEVICE_DISCONNECTED }
return this.pushToDevice(uid, idToDisconnect, 'deviceDisconnected', options) return this.pushToAllDevices(uid, 'deviceDisconnected', options)
}, },
/** /**

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

@ -474,10 +474,10 @@ describe('push', () => {
) )
it( it(
'notifyDeviceDisconnected calls pushToDevice', 'notifyDeviceDisconnected calls pushToAllDevices',
() => { () => {
var push = require(pushModulePath)(mockLog(), mockDbResult, mockConfig) var push = require(pushModulePath)(mockLog(), mockDbResult, mockConfig)
sinon.spy(push, 'pushToDevice') sinon.spy(push, 'pushToAllDevices')
var idToDisconnect = mockDevices[0].id var idToDisconnect = mockDevices[0].id
var expectedData = { var expectedData = {
version: 1, version: 1,
@ -491,18 +491,17 @@ describe('push', () => {
throw err throw err
}) })
.then(function() { .then(function() {
assert.ok(push.pushToDevice.calledOnce, 'pushToDevice was called') assert.ok(push.pushToAllDevices.calledOnce, 'pushToAllDevices was called')
assert.equal(push.pushToDevice.getCall(0).args[0], mockUid) assert.equal(push.pushToAllDevices.getCall(0).args[0], mockUid)
assert.equal(push.pushToDevice.getCall(0).args[1], idToDisconnect) assert.equal(push.pushToAllDevices.getCall(0).args[1], 'deviceDisconnected')
assert.equal(push.pushToDevice.getCall(0).args[2], 'deviceDisconnected') var options = push.pushToAllDevices.getCall(0).args[2]
var options = push.pushToDevice.getCall(0).args[3]
var payload = JSON.parse(options.data.toString('utf8')) var payload = JSON.parse(options.data.toString('utf8'))
assert.deepEqual(payload, expectedData) assert.deepEqual(payload, expectedData)
var schemaPath = path.resolve(__dirname, PUSH_PAYLOADS_SCHEMA_PATH) var schemaPath = path.resolve(__dirname, PUSH_PAYLOADS_SCHEMA_PATH)
var schema = JSON.parse(fs.readFileSync(schemaPath)) var schema = JSON.parse(fs.readFileSync(schemaPath))
assert.ok(ajv.validate(schema, payload)) assert.ok(ajv.validate(schema, payload))
assert.ok(options.TTL, 'TTL should be set') assert.ok(options.TTL, 'TTL should be set')
push.pushToDevice.restore() push.pushToAllDevices.restore()
}) })
} }
) )