我正在使用 node.js(服务器框架)和 mongoose.js(基于 mongo 的模式建模)作为 iOS 应用程序的后端,并且我正在使用 Mocha(测试框架)来确保一切正常。
我真正想知道并且找不到任何文档的是如何在服务器上测试推送通知是否被正确发送。我正在使用 apnagent,目前我可以通过手动检查我的设备看到推送通知正在正确发送,但我很难找到一种自动化的方法来测试它们是否正常工作。
这可能足以在高层次上回答需要做什么的描述。但如果它不在这里是实际的代码:
Mongoose 模型在创建时触发推送通知:
#this code is called after this model is saved in mongodb
eventModel.post 'save', (doc) ->
#push the message
sendMessageToDevice = (event, token) ->
message =
event_body:
eventId: event._id
lat: event.lngLat[1]
lng: event.lngLat[0]
agent.createMessage()
.device(token)
.alert('New Event! ' + event.description)
.set(message)
.send()
#cycle through the users to push to
#get all the unique device tokens in the database for APN
users.getAllUniqueDeviceTokens (error, devices) ->
if error then return util.handleError error
console.log "Sending push notices to all devices (%d):", devices.length
console.log devices
for token in devices
sendMessageToDevice doc, token
#send some verification here that the code ran correctly???
然后在我的摩卡测试文件中,我有:
it 'should receive push notification from fort creation', (done) ->
#some logic here to verify that push notifications were sent
done()