我正在使用node.js(服务器框架)和mongoose.js(基于mongo的模式建模)作为iOS应用程序后端,并使用Mocha(测试框架)确保一切正常。我真正想知道的是,在服务器上如何测试推送通知是否被适当地发送,但我找不到任何文档。我正在使用apnagent,目前可以通过手动检查我的设备看到推送通知正确发送,但我很难找到自动化测试它们工作是否正确的方法。这可能已经足够描述需要做什么。但以防万一,这里是实际代码:MongoDB模型在创建时触发推送通知:
#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???
接下来,在我的Mocha测试文件中,我有:
it 'should receive push notification from fort creation', (done) ->
#some logic here to verify that push notifications were sent
done()