codecombat/test/server/functional/level.spec.coffee

104 lines
2.7 KiB
CoffeeScript
Raw Normal View History

2014-01-03 13:32:13 -05:00
require '../common'
describe 'Level', ->
level =
2014-06-30 22:16:26 -04:00
name: 'King\'s Peak 3'
2014-01-03 13:32:13 -05:00
description: 'Climb a mountain.'
permissions: simplePermissions
scripts: []
thangs: []
documentation: {specificArticles: [], generalArticles: []}
2014-01-03 13:32:13 -05:00
urlLevel = '/db/level'
2014-01-03 13:32:13 -05:00
it 'clears things first', (done) ->
clearModels [Level], (err) ->
expect(err).toBeNull()
done()
it 'can make a Level.', (done) ->
2014-01-15 14:36:59 -05:00
loginJoe ->
2014-06-30 22:16:26 -04:00
request.post {uri: getURL(urlLevel), json: level}, (err, res, body) ->
2014-01-03 13:32:13 -05:00
expect(res.statusCode).toBe(200)
done()
it 'get schema', (done) ->
2014-06-30 22:16:26 -04:00
request.get {uri: getURL(urlLevel+'/schema')}, (err, res, body) ->
expect(res.statusCode).toBe(200)
body = JSON.parse(body)
expect(body.type).toBeDefined()
done()
describe 'GET /db/level/<id>/session', ->
describe 'when level is a course level', ->
levelID = null
it 'sets up a course instance', (done) ->
clearModels [Campaign, Course, CourseInstance, Level, User], (err) ->
loginAdmin (admin) ->
url = getURL('/db/level')
body =
name: 'Course Level'
type: 'course'
permissions: simplePermissions
request.post {uri: url, json: body }, (err, res, level) ->
levelID = level._id
url = getURL('/db/campaign')
body =
name: 'Course Campaign'
levels: {}
body.levels[level.original] = { 'original': level.original }
request.post { uri: url, json: body }, (err, res, campaign) ->
course = new Course({
name: 'Test Course'
campaignID: ObjectId(campaign._id)
})
course.save (err) ->
expect(err).toBeNull()
loginJoe (joe) ->
courseInstance = new CourseInstance({
name: 'Course Instance'
members: [
joe.get('_id')
]
courseID: ObjectId(course.id)
})
courseInstance.save (err) ->
expect(err).toBeNull()
done()
it 'creates a new session if the user is in a course with that level', (done) ->
loginJoe (joe) ->
url = getURL("/db/level/#{levelID}/session")
request.get { uri: url }, (err, res, body) ->
expect(res.statusCode).toBe(200)
done()
it 'does not create a new session if the user is not in a course with that level', (done) ->
loginSam (sam) ->
url = getURL("/db/level/#{levelID}/session")
request.get { uri: url }, (err, res, body) ->
expect(res.statusCode).toBe(402)
done()