2014-01-03 13:32:13 -05:00
|
|
|
require '../common'
|
|
|
|
|
|
|
|
describe 'LevelComponent', ->
|
|
|
|
|
|
|
|
component =
|
2014-04-08 17:10:50 -04:00
|
|
|
name:'BashesEverything'
|
2014-01-03 13:32:13 -05:00
|
|
|
description:'Makes the unit uncontrollably bash anything bashable, using the bash system.'
|
|
|
|
code: 'bash();'
|
2014-06-10 16:20:14 -04:00
|
|
|
codeLanguage: 'coffeescript'
|
2014-01-03 13:32:13 -05:00
|
|
|
permissions:simplePermissions
|
2014-04-08 17:10:50 -04:00
|
|
|
propertyDocumentation: []
|
|
|
|
system: 'ai'
|
|
|
|
dependencies: []
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
components = {}
|
|
|
|
|
|
|
|
url = getURL('/db/level.component')
|
|
|
|
|
2014-01-12 10:16:56 -05:00
|
|
|
it 'preparing test : clears things first.', (done) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
clearModels [Level, LevelComponent], (err) ->
|
|
|
|
expect(err).toBeNull()
|
|
|
|
done()
|
|
|
|
|
2014-01-12 10:16:56 -05:00
|
|
|
it 'can\'t be created by ordinary users.', (done) ->
|
2014-01-15 14:36:59 -05:00
|
|
|
loginJoe ->
|
2014-01-12 10:16:56 -05:00
|
|
|
request.post {uri:url, json:component}, (err, res, body) ->
|
|
|
|
expect(res.statusCode).toBe(403)
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'can be created by an admin.', (done) ->
|
2014-01-15 14:36:59 -05:00
|
|
|
loginAdmin ->
|
2014-01-03 13:32:13 -05:00
|
|
|
request.post {uri:url, json:component}, (err, res, body) ->
|
|
|
|
expect(res.statusCode).toBe(200)
|
2014-01-12 10:16:56 -05:00
|
|
|
expect(body._id).toBeDefined()
|
|
|
|
expect(body.name).toBe(component.name)
|
|
|
|
expect(body.description).toBe(component.description)
|
|
|
|
expect(body.code).toBe(component.code)
|
2014-06-10 16:20:14 -04:00
|
|
|
expect(body.codeLanguage).toBe(component.codeLanguage)
|
2014-01-12 10:16:56 -05:00
|
|
|
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()
|
|
|
|
|
2014-01-12 10:16:56 -05:00
|
|
|
it 'have a unique name.', (done) ->
|
2014-01-15 14:36:59 -05:00
|
|
|
loginAdmin ->
|
2014-01-12 10:16:56 -05:00
|
|
|
request.post {uri:url, json:component}, (err, res, body) ->
|
2014-04-08 17:10:50 -04:00
|
|
|
expect(res.statusCode).toBe(409)
|
2014-01-12 10:16:56 -05:00
|
|
|
done()
|
|
|
|
|
2014-01-14 16:44:33 -05:00
|
|
|
it 'can be read by an admin.', (done) ->
|
2014-01-15 14:36:59 -05:00
|
|
|
loginAdmin ->
|
2014-01-12 10:16:56 -05: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-01-12 10:16:56 -05: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)
|
2014-06-10 16:20:14 -04:00
|
|
|
expect(body.codeLanguage).toBe(components[0].codeLanguage)
|
2014-01-12 10:16:56 -05:00
|
|
|
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) ->
|
2014-01-15 14:36:59 -05:00
|
|
|
loginJoe ->
|
2014-01-12 10:16:56 -05: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.official).toBe(false)
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'has system ai by default', (done) ->
|
2014-01-15 14:36:59 -05:00
|
|
|
loginJoe ->
|
2014-01-12 10:16:56 -05: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.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-01-12 10:16:56 -05:00
|
|
|
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) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
components[0].official = true
|
2014-01-15 14:36:59 -05:00
|
|
|
loginAdmin ->
|
2014-01-03 13:32:13 -05:00
|
|
|
request.post {uri:url, json:components[0]}, (err, res, body) ->
|
|
|
|
expect(res.statusCode).toBe(200)
|
2014-01-12 10:16:56 -05:00
|
|
|
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)
|
2014-01-14 16:44:33 -05:00
|
|
|
done()
|
|
|
|
|
|
|
|
xit ' can\'t be requested with HTTP PUT method', (done) ->
|
|
|
|
request.put {uri:url+'/'+components[0]._id}, (err, res) ->
|
2014-06-09 11:28:35 -04:00
|
|
|
expect(res.statusCode).toBe(405)
|
2014-01-14 16:44:33 -05:00
|
|
|
done()
|
|
|
|
|
|
|
|
it ' can\'t be requested with HTTP HEAD method', (done) ->
|
|
|
|
request.head {uri:url+'/'+components[0]._id}, (err, res) ->
|
2014-06-09 11:28:35 -04:00
|
|
|
expect(res.statusCode).toBe(405)
|
2014-01-14 16:44:33 -05:00
|
|
|
done()
|
|
|
|
|
|
|
|
it ' can\'t be requested with HTTP DEL method', (done) ->
|
|
|
|
request.del {uri:url+'/'+components[0]._id}, (err, res) ->
|
2014-06-09 11:28:35 -04:00
|
|
|
expect(res.statusCode).toBe(405)
|
2014-01-14 16:44:33 -05:00
|
|
|
done()
|
2014-01-23 17:06:12 -05:00
|
|
|
|
|
|
|
it 'get schema', (done) ->
|
|
|
|
request.get {uri:url+'/schema'}, (err, res, body) ->
|
|
|
|
expect(res.statusCode).toBe(200)
|
|
|
|
body = JSON.parse(body)
|
|
|
|
expect(body.type).toBeDefined()
|
|
|
|
done()
|