2014-01-03 13:32:13 -05:00
|
|
|
require '../common'
|
2016-04-06 13:56:06 -04:00
|
|
|
Level = require '../../../server/models/Level'
|
|
|
|
LevelComponent = require '../../../server/models/LevelComponent'
|
2016-05-09 18:16:54 -04:00
|
|
|
User = require '../../../server/models/User'
|
2016-04-06 13:56:06 -04:00
|
|
|
request = require '../request'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
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();'
|
2014-06-10 16:20:14 -04:00
|
|
|
codeLanguage: 'coffeescript'
|
2014-06-30 22:16:26 -04: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) ->
|
2016-05-09 18:16:54 -04:00
|
|
|
clearModels [Level, LevelComponent, User], (err) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
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)
|
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-06-30 22:16:26 -04: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-06-30 22:16:26 -04:00
|
|
|
request.get {uri: url+'/'+components[0]._id}, (err, res, body) ->
|
2014-01-12 10:16:56 -05:00
|
|
|
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) ->
|
2014-01-12 10:16:56 -05:00
|
|
|
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.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) ->
|
2014-01-12 10:16:56 -05:00
|
|
|
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()
|
2014-01-12 10:16:56 -05:00
|
|
|
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) ->
|
2014-01-12 10:16:56 -05:00
|
|
|
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')
|
2014-01-12 10:16:56 -05:00
|
|
|
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()
|
2014-01-12 10:16:56 -05:00
|
|
|
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)
|
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
|
|
|
|
|
2014-06-30 22:16:26 -04:00
|
|
|
request.get {uri: url+'/'+components[0]._id}, (err, res, body) ->
|
2014-01-12 10:16:56 -05:00
|
|
|
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()
|
2014-01-12 10:16:56 -05:00
|
|
|
expect(body.version.isLatestMinor).toBe(false)
|
|
|
|
expect(body.version.isLatestMajor).toBe(false)
|
2014-01-14 16:44:33 -05:00
|
|
|
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) ->
|
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) ->
|
2014-06-30 22:16:26 -04:00
|
|
|
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) ->
|
2014-06-30 22:16:26 -04:00
|
|
|
request.get {uri: url+'/schema'}, (err, res, body) ->
|
2014-01-23 17:06:12 -05:00
|
|
|
expect(res.statusCode).toBe(200)
|
|
|
|
body = JSON.parse(body)
|
|
|
|
expect(body.type).toBeDefined()
|
|
|
|
done()
|