node.js - Test for Apple Push Notification -


i using node.js (server framework) , mongoose.js (mongo based schema modeling) backend ios app , using mocha (test framwork) make sure works.

what want know, , can find no documentation on, how test on server if push notifications being appropriately sent. using apnagent , @ moment can see push notifications being sent correctly manually checking device having difficulty finding automated way test working correctly.


that may enough of description answer @ high level needs done. in case not here actual code:

mongoose model fires off push notification upon creation:

#this code called after model saved in mongodb eventmodel.post 'save', (doc) ->   #push 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 users push   #get unique device tokens in database apn   users.getalluniquedevicetokens (error, devices) ->     if error return util.handleerror error     console.log "sending push notices devices (%d):", devices.length     console.log devices     token in devices       sendmessagetodevice doc, token      #send verification here code ran correctly??? 

then in mocha test file have:

it 'should receive push notification fort creation', (done) ->     #some logic here verify push notifications sent     done() 

in many situations, while writing tests, either impossible or dangerous verify action has taken place (i.e. push notification has been delivered). imagine writing unit test rm command ensure doing rm -rf / succeeds. obviously, cannot let action take place , verify root partition indeed empty!

what can do, (and should do, really), verify whatever commands, routines or other actions necessary accomplish task being invoked correctly, without allowing them take place.

in particular situation, not need verify push notification has been delivered because application not responsible notification's delivery. however, can test push notification being correctly delivered push server.

so, instead of testing successful delivery, test

  1. whether outgoing request formatted (i.e. json valid)
  2. whether contains data expect contain (i.e. field in json present , contains expected data)
  3. whether authentication token required server included
  4. whether target server correct (i.e. indeed sending data xxx.apple.com , not localhost)

ideally, these test requests not reach target server - doing mean relying on 2 factors not stable:

  • network connectivity
  • target server availability , proper functionality

in past, dealt first manually issued correct request, captured response , mocked whole communication in unit test (using i.e. nock. way, in control of whole communication.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -