overleaf/services/web/test/unit/coffee/helpers/MockResponse.coffee

87 lines
1.6 KiB
CoffeeScript
Raw Normal View History

2014-02-12 10:23:40 +00: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 15:56:38 +00: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 10:23:40 +00: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?
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 10:23:40 +00:00
status: (@statusCode)->
return @
2014-02-12 10:23:40 +00:00
setHeader: (header, value) ->
@headers[header] = value
setContentDisposition: sinon.stub()
setTimeout: (@timout)->
2014-02-12 10:23:40 +00:00
header: sinon.stub()
contentType: sinon.stub()
end: (data, encoding) ->
@callback() if @callback
type: (type) -> @type = type
module.exports = MockResponse