mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 15:48:11 -05:00
Took a detour to write tests for BadMethod. Queue's tests not working yet.
This commit is contained in:
parent
b66f4984c3
commit
925594ffe9
6 changed files with 100 additions and 5 deletions
|
@ -4,7 +4,7 @@ errors = require '../commons/errors'
|
|||
module.exports.setup = (app) ->
|
||||
app.all '/folder*', (req, res) ->
|
||||
return folderGet(req, res) if req.route.method is 'get'
|
||||
return errors.badMethod(res)
|
||||
return errors.badMethod(res, ['GET'])
|
||||
|
||||
folderGet = (req, res) ->
|
||||
folder = req.path[7..]
|
||||
|
@ -15,4 +15,4 @@ folderGet = (req, res) ->
|
|||
mongoose.connection.db.collection 'media.files', (errors, collection) ->
|
||||
collection.find({'metadata.path': folder}).toArray (err, results) ->
|
||||
res.send(results)
|
||||
res.end()
|
||||
res.end()
|
||||
|
|
|
@ -11,7 +11,7 @@ module.exports.setup = (app) ->
|
|||
|
||||
app.all '/languages', (req, res) ->
|
||||
# Now that these are in the client, not sure when we would use this, but hey
|
||||
return errors.badMethod(res) if req.route.method isnt 'get'
|
||||
return errors.badMethod(res, ['GET']) if req.route.method isnt 'get'
|
||||
res.send(languages)
|
||||
return res.end()
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ module.exports.setup = (app) ->
|
|||
|
||||
app.all '/queue/*', (req, res) ->
|
||||
setResponseHeaderToJSONContentType res
|
||||
|
||||
|
||||
queueName = getQueueNameFromPath req.path
|
||||
try
|
||||
handler = loadQueueHandler queueName
|
||||
|
@ -64,7 +64,7 @@ isHTTPMethodPost = (req) -> return req.route.method is 'post'
|
|||
isHTTPMethodPut = (req) -> return req.route.method is 'put'
|
||||
|
||||
|
||||
sendMethodNotSupportedError = (req, res) -> errors.badMethod(res,"Queues do not support the HTTP method used." )
|
||||
sendMethodNotSupportedError = (req, res) -> errors.badMethod(res, ['GET', 'POST', 'PUT'], "Queues do not support the HTTP method used." )
|
||||
|
||||
sendQueueError = (req,res, error) -> errors.serverError(res, "Route #{req.path} had a problem: #{error}")
|
||||
|
||||
|
|
35
test/server/functional/folder.spec.coffee
Normal file
35
test/server/functional/folder.spec.coffee
Normal file
|
@ -0,0 +1,35 @@
|
|||
require '../common'
|
||||
|
||||
describe 'folder', ->
|
||||
url = getURL('/folder')
|
||||
allowHeader = 'GET'
|
||||
|
||||
it 'can\'t be requested with HTTP POST method', (done) ->
|
||||
request.post {uri: url}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(405)
|
||||
expect(res.headers.allow).toBe(allowHeader)
|
||||
done()
|
||||
|
||||
it 'can\'t be requested with HTTP PUT method', (done) ->
|
||||
request.put {uri: url}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(405)
|
||||
expect(res.headers.allow).toBe(allowHeader)
|
||||
done()
|
||||
|
||||
it 'can\'t be requested with HTTP PATCH method', (done) ->
|
||||
request {method:'patch', uri: url}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(405)
|
||||
expect(res.headers.allow).toBe(allowHeader)
|
||||
done()
|
||||
|
||||
it 'can\'t be requested with HTTP HEAD method', (done) ->
|
||||
request.head {uri: url}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(405)
|
||||
expect(res.headers.allow).toBe(allowHeader)
|
||||
done()
|
||||
|
||||
it 'can\'t be requested with HTTP DELETE method', (done) ->
|
||||
request.del {uri: url}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(405)
|
||||
expect(res.headers.allow).toBe(allowHeader)
|
||||
done()
|
35
test/server/functional/languages.spec.coffee
Normal file
35
test/server/functional/languages.spec.coffee
Normal file
|
@ -0,0 +1,35 @@
|
|||
require '../common'
|
||||
|
||||
describe 'languages', ->
|
||||
url = getURL('/languages')
|
||||
allowHeader = 'GET'
|
||||
|
||||
it 'can\'t be requested with HTTP POST method', (done) ->
|
||||
request.post {uri: url}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(405)
|
||||
expect(res.headers.allow).toBe(allowHeader)
|
||||
done()
|
||||
|
||||
it 'can\'t be requested with HTTP PUT method', (done) ->
|
||||
request.put {uri: url}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(405)
|
||||
expect(res.headers.allow).toBe(allowHeader)
|
||||
done()
|
||||
|
||||
it 'can\'t be requested with HTTP PATCH method', (done) ->
|
||||
request {method:'patch', uri: url}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(405)
|
||||
expect(res.headers.allow).toBe(allowHeader)
|
||||
done()
|
||||
|
||||
it 'can\'t be requested with HTTP HEAD method', (done) ->
|
||||
request.head {uri: url}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(405)
|
||||
expect(res.headers.allow).toBe(allowHeader)
|
||||
done()
|
||||
|
||||
it 'can\'t be requested with HTTP DELETE method', (done) ->
|
||||
request.del {uri: url}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(405)
|
||||
expect(res.headers.allow).toBe(allowHeader)
|
||||
done()
|
25
test/server/functional/queue.spec.coffee
Normal file
25
test/server/functional/queue.spec.coffee
Normal file
|
@ -0,0 +1,25 @@
|
|||
require '../common'
|
||||
|
||||
describe 'queue', ->
|
||||
someURL = getURL('/queue/')
|
||||
allowHeader = 'GET, POST, PUT'
|
||||
|
||||
xit 'can\'t be requested with HTTP PATCH method', (done) ->
|
||||
request {method:'patch', uri: someURL}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(405)
|
||||
expect(res.headers.allow).toBe(allowHeader)
|
||||
done()
|
||||
|
||||
xit 'can\'t be requested with HTTP HEAD method', (done) ->
|
||||
request.head {uri: someURL}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(405)
|
||||
expect(res.headers.allow).toBe(allowHeader)
|
||||
done()
|
||||
|
||||
xit 'can\'t be requested with HTTP DELETE method', (done) ->
|
||||
request.del {uri: someURL}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(405)
|
||||
expect(res.headers.allow).toBe(allowHeader)
|
||||
done()
|
||||
|
||||
|
Loading…
Reference in a new issue