2014-02-12 05:23:40 -05:00
|
|
|
sinon = require "sinon"
|
|
|
|
|
|
|
|
class MockResponse
|
|
|
|
constructor: ->
|
|
|
|
@rendered = false
|
|
|
|
@redirected = false
|
|
|
|
@returned = false
|
|
|
|
@headers = {}
|
|
|
|
|
|
|
|
render: (template, variables) ->
|
|
|
|
@success = true
|
|
|
|
@rendered = true
|
|
|
|
@returned = true
|
|
|
|
@renderedTemplate = template
|
|
|
|
@renderedVariables = variables
|
|
|
|
@callback() if @callback?
|
|
|
|
|
|
|
|
redirect: (url) ->
|
|
|
|
@success = true
|
|
|
|
@redirected = true
|
|
|
|
@returned = true
|
|
|
|
@redirectedTo = url
|
|
|
|
@callback() if @callback?
|
|
|
|
|
2015-07-08 11:56:38 -04:00
|
|
|
sendStatus: (status) ->
|
|
|
|
if arguments.length < 2
|
|
|
|
if typeof status != "number"
|
|
|
|
body = status
|
|
|
|
status = 200
|
|
|
|
@statusCode = status
|
|
|
|
@returned = true
|
|
|
|
if 200 <= status < 300
|
|
|
|
@success = true
|
|
|
|
else
|
|
|
|
@success = false
|
|
|
|
@callback() if @callback?
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
send: (status, body) ->
|
|
|
|
if arguments.length < 2
|
|
|
|
if typeof status != "number"
|
|
|
|
body = status
|
|
|
|
status = 200
|
|
|
|
@statusCode = status
|
|
|
|
@returned = true
|
|
|
|
if 200 <= status < 300
|
|
|
|
@success = true
|
|
|
|
else
|
|
|
|
@success = false
|
|
|
|
@body = body if body
|
|
|
|
@callback() if @callback?
|
2016-01-25 12:35:57 -05:00
|
|
|
|
|
|
|
json: (status, body) ->
|
|
|
|
if arguments.length < 2
|
|
|
|
if typeof status != "number"
|
|
|
|
body = status
|
|
|
|
status = 200
|
|
|
|
@statusCode = status
|
|
|
|
@returned = true
|
|
|
|
if 200 <= status < 300
|
|
|
|
@success = true
|
|
|
|
else
|
|
|
|
@success = false
|
|
|
|
@body = body if body
|
|
|
|
@callback() if @callback?
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2016-04-20 12:00:17 -04:00
|
|
|
status: (@statusCode)->
|
|
|
|
return @
|
|
|
|
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
setHeader: (header, value) ->
|
|
|
|
@headers[header] = value
|
|
|
|
|
2017-04-12 11:00:02 -04:00
|
|
|
setContentDisposition: sinon.stub()
|
|
|
|
|
2014-10-17 08:23:29 -04:00
|
|
|
setTimeout: (@timout)->
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
header: sinon.stub()
|
|
|
|
|
|
|
|
contentType: sinon.stub()
|
|
|
|
|
|
|
|
end: (data, encoding) ->
|
|
|
|
@callback() if @callback
|
|
|
|
|
|
|
|
type: (type) -> @type = type
|
|
|
|
|
|
|
|
module.exports = MockResponse
|