How can I test a function like this?
app.post '/incoming', (req,res) ->
console.log "Hello, incoming call!"
message = req.body.Body
from = req.body.From
sys.log "From: " + from + ", Message: " + message
twiml = '<?xml version="1.0" encoding="UTF-8" ?>\n<Response>\n<Say>Thanks for your text, we\'ll be in touch.</Say>\n</Response>'
res.send twiml, {'Content-Type':'text/xml'}, 200
I haven’t chosen any test framework yet. I don’t understand how this can be tested.
thanks!
Testing is simple. You just create a unit test that starts your express server, makes a http POST and asserts that your HTTP post works and gets the correct output back.
Using vows-is. (Sorry, no coffeescript)
Store this in a file
http-test.jsin a foldertest. Then just runSee an example of exporting your serverSetup function