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

145 lines
5.1 KiB
CoffeeScript
Raw Normal View History

2014-01-03 13:32:13 -05:00
require '../common'
describe 'LevelComponent', ->
component =
2014-06-30 22:16:26 -04:00
name: 'BashesEverything'
description: 'Makes the unit uncontrollably bash anything bashable, using the bash system.'
2014-01-03 13:32:13 -05:00
code: 'bash();'
codeLanguage: 'coffeescript'
2014-06-30 22:16:26 -04:00
permissions: simplePermissions
propertyDocumentation: []
system: 'ai'
dependencies: []
2014-01-03 13:32:13 -05:00
components = {}
url = getURL('/db/level.component')
it 'preparing test : clears things first.', (done) ->
2014-01-03 13:32:13 -05:00
clearModels [Level, LevelComponent], (err) ->
expect(err).toBeNull()
done()
2014-07-10 17:31:25 -04:00
it 'can be created by ordinary users.', (done) ->
2014-01-15 14:36:59 -05:00
loginJoe ->
2014-06-30 22:16:26 -04:00
request.post {uri: url, json: component}, (err, res, body) ->
2014-01-03 13:32:13 -05:00
expect(res.statusCode).toBe(200)
expect(body._id).toBeDefined()
expect(body.name).toBe(component.name)
expect(body.description).toBe(component.description)
expect(body.code).toBe(component.code)
expect(body.codeLanguage).toBe(component.codeLanguage)
expect(body.__v).toBe(0)
expect(body.creator).toBeDefined()
expect(body.original).toBeDefined()
expect(body.created).toBeDefined()
expect(body.version).toBeDefined()
expect(body.permissions).toBeDefined()
2014-01-03 13:32:13 -05:00
components[0] = body
done()
it 'have a unique name.', (done) ->
2014-01-15 14:36:59 -05:00
loginAdmin ->
2014-06-30 22:16:26 -04:00
request.post {uri: url, json: component}, (err, res, body) ->
expect(res.statusCode).toBe(409)
done()
it 'can be read by an admin.', (done) ->
2014-01-15 14:36:59 -05:00
loginAdmin ->
2014-06-30 22:16:26 -04:00
request.get {uri: url+'/'+components[0]._id}, (err, res, body) ->
expect(res.statusCode).toBe(200)
body = JSON.parse(body)
expect(body._id).toBe(components[0]._id)
done()
it 'can be read by ordinary users.', (done) ->
2014-01-15 14:36:59 -05:00
loginJoe ->
2014-06-30 22:16:26 -04:00
request.get {uri: url+'/'+components[0]._id}, (err, res, body) ->
expect(res.statusCode).toBe(200)
body = JSON.parse(body)
expect(body._id).toBe(components[0]._id)
expect(body.name).toBe(components[0].name)
expect(body.slug).toBeDefined()
expect(body.description).toBe(components[0].description)
expect(body.code).toBe(components[0].code)
expect(body.codeLanguage).toBe(components[0].codeLanguage)
expect(body.__v).toBe(0)
expect(body.creator).toBeDefined()
expect(body.original).toBeDefined()
expect(body.created).toBeDefined()
expect(body.dependencies).toBeDefined()
expect(body.propertyDocumentation).toBeDefined()
expect(body.version.isLatestMajor).toBe(true)
expect(body.version.isLatestMinor).toBe(true)
expect(body.permissions).toBeDefined()
done()
it 'is unofficial by default', (done) ->
2014-01-15 14:36:59 -05:00
loginJoe ->
2014-06-30 22:16:26 -04:00
request.get {uri: url+'/'+components[0]._id}, (err, res, body) ->
expect(res.statusCode).toBe(200)
body = JSON.parse(body)
expect(body._id).toBe(components[0]._id)
2014-08-29 19:28:07 -04:00
expect(body.official).toBeUndefined()
done()
it 'has system ai by default', (done) ->
2014-01-15 14:36:59 -05:00
loginJoe ->
2014-06-30 22:16:26 -04:00
request.get {uri: url+'/'+components[0]._id}, (err, res, body) ->
expect(res.statusCode).toBe(200)
body = JSON.parse(body)
expect(body._id).toBe(components[0]._id)
2014-06-30 22:16:26 -04:00
expect(body.system).toBe('ai')
done()
it 'official property isn\'t editable by an ordinary user.', (done) ->
components[0].official = true
2014-01-15 14:36:59 -05:00
loginJoe ->
2014-06-30 22:16:26 -04:00
request.post {uri: url, json: components[0]}, (err, res, body) ->
2014-07-10 17:31:25 -04:00
expect(res.statusCode).toBe(200)
2014-08-29 19:28:07 -04:00
expect(body.official).toBeUndefined()
done()
it 'official property is editable by an admin.', (done) ->
2014-01-03 13:32:13 -05:00
components[0].official = true
2014-01-15 14:36:59 -05:00
loginAdmin ->
2014-06-30 22:16:26 -04:00
request.post {uri: url, json: components[0]}, (err, res, body) ->
2014-01-03 13:32:13 -05:00
expect(res.statusCode).toBe(200)
expect(body.official).toBe(true)
expect(body.original).toBe(components[0].original)
expect(body.version.isLatestMinor).toBe(true)
expect(body.version.isLatestMajor).toBe(true)
components[1] = body
2014-06-30 22:16:26 -04:00
request.get {uri: url+'/'+components[0]._id}, (err, res, body) ->
expect(res.statusCode).toBe(200)
body = JSON.parse(body)
expect(body._id).toBe(components[0]._id)
2014-08-29 19:28:07 -04:00
expect(body.official).toBeUndefined()
expect(body.version.isLatestMinor).toBe(false)
expect(body.version.isLatestMajor).toBe(false)
done()
xit ' can\'t be requested with HTTP PUT method', (done) ->
2014-06-30 22:16:26 -04:00
request.put {uri: url+'/'+components[0]._id}, (err, res) ->
expect(res.statusCode).toBe(405)
done()
it ' can\'t be requested with HTTP HEAD method', (done) ->
2014-06-30 22:16:26 -04:00
request.head {uri: url+'/'+components[0]._id}, (err, res) ->
expect(res.statusCode).toBe(405)
done()
it ' can\'t be requested with HTTP DEL method', (done) ->
2014-06-30 22:16:26 -04:00
request.del {uri: url+'/'+components[0]._id}, (err, res) ->
expect(res.statusCode).toBe(405)
done()
it 'get schema', (done) ->
2014-06-30 22:16:26 -04:00
request.get {uri: url+'/schema'}, (err, res, body) ->
expect(res.statusCode).toBe(200)
body = JSON.parse(body)
expect(body.type).toBeDefined()
done()