mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-01 03:16:56 -05:00
46 lines
1.4 KiB
CoffeeScript
46 lines
1.4 KiB
CoffeeScript
|
require '../common'
|
||
|
utils = require '../utils'
|
||
|
_ = require 'lodash'
|
||
|
Promise = require 'bluebird'
|
||
|
requestAsync = Promise.promisify(request, {multiArgs: true})
|
||
|
|
||
|
describe 'GET /db/course', ->
|
||
|
beforeEach utils.wrap (done) ->
|
||
|
yield utils.clearModels([Course, User])
|
||
|
yield new Course({ name: 'Course 1' }).save()
|
||
|
yield new Course({ name: 'Course 2' }).save()
|
||
|
done()
|
||
|
|
||
|
|
||
|
it 'returns an array of Course objects', utils.wrap (done) ->
|
||
|
[res, body] = yield request.getAsync { uri: getURL('/db/course'), json: true }
|
||
|
expect(body.length).toBe(2)
|
||
|
done()
|
||
|
|
||
|
describe 'GET /db/course/:handle', ->
|
||
|
|
||
|
beforeEach utils.wrap (done) ->
|
||
|
yield utils.clearModels([Course, User])
|
||
|
@course = yield new Course({ name: 'Some Name' }).save()
|
||
|
done()
|
||
|
|
||
|
|
||
|
it 'returns Course by id', utils.wrap (done) ->
|
||
|
[res, body] = yield request.getAsync {uri: getURL("/db/course/#{@course.id}"), json: true}
|
||
|
expect(res.statusCode).toBe(200)
|
||
|
expect(body._id).toBe(@course.id)
|
||
|
done()
|
||
|
|
||
|
|
||
|
it 'returns Course by slug', utils.wrap (done) ->
|
||
|
[res, body] = yield request.getAsync {uri: getURL("/db/course/some-name"), json: true}
|
||
|
expect(res.statusCode).toBe(200)
|
||
|
expect(body._id).toBe(@course.id)
|
||
|
done()
|
||
|
|
||
|
|
||
|
it 'returns not found if handle does not exist in the db', utils.wrap (done) ->
|
||
|
[res, body] = yield request.getAsync {uri: getURL("/db/course/dne"), json: true}
|
||
|
expect(res.statusCode).toBe(404)
|
||
|
done()
|