mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Fix and add test in LevelComponent on the server side.
This commit is contained in:
parent
76b795a8e6
commit
4f62448d74
1 changed files with 97 additions and 7 deletions
|
@ -7,30 +7,120 @@ describe 'LevelComponent', ->
|
||||||
description:'Makes the unit uncontrollably bash anything bashable, using the bash system.'
|
description:'Makes the unit uncontrollably bash anything bashable, using the bash system.'
|
||||||
code: 'bash();'
|
code: 'bash();'
|
||||||
language: 'javascript'
|
language: 'javascript'
|
||||||
official: true
|
|
||||||
permissions:simplePermissions
|
permissions:simplePermissions
|
||||||
|
|
||||||
components = {}
|
components = {}
|
||||||
|
|
||||||
url = getURL('/db/level.component')
|
url = getURL('/db/level.component')
|
||||||
|
|
||||||
it 'clears things first', (done) ->
|
it 'preparing test : clears things first.', (done) ->
|
||||||
clearModels [Level, LevelComponent], (err) ->
|
clearModels [Level, LevelComponent], (err) ->
|
||||||
expect(err).toBeNull()
|
expect(err).toBeNull()
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it 'can make a LevelComponent, without setting official.', (done) ->
|
it 'can\'t be created by ordinary users.', (done) ->
|
||||||
loginJoe (joe) ->
|
loginJoe (joe) ->
|
||||||
|
request.post {uri:url, json:component}, (err, res, body) ->
|
||||||
|
expect(res.statusCode).toBe(403)
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'can be created by an admin.', (done) ->
|
||||||
|
loginAdmin (joe) ->
|
||||||
request.post {uri:url, json:component}, (err, res, body) ->
|
request.post {uri:url, json:component}, (err, res, body) ->
|
||||||
expect(res.statusCode).toBe(200)
|
expect(res.statusCode).toBe(200)
|
||||||
expect(body.official).toBeUndefined()
|
expect(body._id).toBeDefined()
|
||||||
|
expect(body.name).toBe(component.name)
|
||||||
|
expect(body.description).toBe(component.description)
|
||||||
|
expect(body.code).toBe(component.code)
|
||||||
|
expect(body.language).toBe(component.language)
|
||||||
|
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()
|
||||||
components[0] = body
|
components[0] = body
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it 'can allows admins to edit the official property.', (done) ->
|
it 'have a unique name.', (done) ->
|
||||||
|
loginAdmin (joe) ->
|
||||||
|
request.post {uri:url, json:component}, (err, res, body) ->
|
||||||
|
expect(res.statusCode).toBe(422)
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'can read by an admin.', (done) ->
|
||||||
|
loginAdmin (joe) ->
|
||||||
|
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) ->
|
||||||
|
loginJoe (joe) ->
|
||||||
|
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.language).toBe(components[0].language)
|
||||||
|
expect(body.__v).toBe(0)
|
||||||
|
expect(body.official).toBeDefined()
|
||||||
|
expect(body.creator).toBeDefined()
|
||||||
|
expect(body.original).toBeDefined()
|
||||||
|
expect(body.created).toBeDefined()
|
||||||
|
expect(body.configSchema).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) ->
|
||||||
|
loginJoe (joe) ->
|
||||||
|
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.official).toBe(false)
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'has system ai by default', (done) ->
|
||||||
|
loginJoe (joe) ->
|
||||||
|
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.system).toBe("ai")
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'official property isn\'t editable by an ordinary user.', (done) ->
|
||||||
|
components[0].official = true
|
||||||
|
loginJoe (joe) ->
|
||||||
|
request.post {uri:url, json:components[0]}, (err, res, body) ->
|
||||||
|
expect(res.statusCode).toBe(403)
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'official property is editable by an admin.', (done) ->
|
||||||
components[0].official = true
|
components[0].official = true
|
||||||
loginAdmin (joe) ->
|
loginAdmin (joe) ->
|
||||||
request.post {uri:url, json:components[0]}, (err, res, body) ->
|
request.post {uri:url, json:components[0]}, (err, res, body) ->
|
||||||
expect(body.official).toBe(true)
|
|
||||||
expect(res.statusCode).toBe(200)
|
expect(res.statusCode).toBe(200)
|
||||||
done()
|
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
|
||||||
|
|
||||||
|
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.official).toBe(false)
|
||||||
|
expect(body.version.isLatestMinor).toBe(false)
|
||||||
|
expect(body.version.isLatestMajor).toBe(false)
|
||||||
|
done()
|
Loading…
Reference in a new issue