2014-01-03 10:32:13 -08:00
require ' ../common '
describe ' LevelSystem ' , ->
2014-01-15 20:36:59 +01:00
system =
2014-01-03 10:32:13 -08:00
name : ' Bashing '
description : ' Performs Thang bashing updates for Bashes Thangs. '
code: """ class Bashing extends System
constructor: (world) ->
super world
"""
language: ' coffeescript '
permissions : simplePermissions
2014-04-08 14:10:50 -07:00
dependencies: [ ]
propertyDocumentation: [ ]
2014-01-03 10:32:13 -08:00
systems = { }
url = getURL ( ' /db/level.system ' )
2014-01-15 20:36:59 +01:00
it ' preparing test : deletes all LevelSystem first ' , (done) ->
2014-01-03 10:32:13 -08:00
clearModels [ Level , LevelSystem ] , (err) ->
expect ( err ) . toBeNull ( )
done ( )
2014-01-15 20:36:59 +01:00
it ' can \' t be created by ordinary users. ' , (done) ->
loginJoe ->
request . post { uri : url , json : system } , (err, res, body) ->
expect ( res . statusCode ) . toBe ( 403 )
done ( )
it ' can be created by an admin. ' , (done) ->
loginAdmin ->
request . post { uri : url , json : system } , (err, res, body) ->
2014-01-03 10:32:13 -08:00
expect ( res . statusCode ) . toBe ( 200 )
2014-01-15 20:36:59 +01:00
expect ( body . _id ) . toBeDefined ( )
expect ( body . name ) . toBe ( system . name )
expect ( body . description ) . toBe ( system . description )
expect ( body . code ) . toBe ( system . code )
expect ( body . language ) . toBe ( system . 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 ( )
2014-01-03 10:32:13 -08:00
systems [ 0 ] = body
done ( )
2014-01-15 20:36:59 +01:00
it ' have a unique name. ' , (done) ->
loginAdmin ->
request . post { uri : url , json : system } , (err, res, body) ->
2014-04-08 14:10:50 -07:00
expect ( res . statusCode ) . toBe ( 409 )
2014-01-15 20:36:59 +01:00
done ( )
it ' can be read by an admin. ' , (done) ->
loginAdmin ->
request . get { uri : url + ' / ' + systems [ 0 ] . _id } , (err, res, body) ->
expect ( res . statusCode ) . toBe ( 200 )
body = JSON . parse ( body )
expect ( body . _id ) . toBe ( systems [ 0 ] . _id )
done ( )
it ' can be read by ordinary users. ' , (done) ->
loginJoe ->
request . get { uri : url + ' / ' + systems [ 0 ] . _id } , (err, res, body) ->
expect ( res . statusCode ) . toBe ( 200 )
body = JSON . parse ( body )
expect ( body . _id ) . toBe ( systems [ 0 ] . _id )
expect ( body . name ) . toBe ( systems [ 0 ] . name )
expect ( body . slug ) . toBeDefined ( )
expect ( body . description ) . toBe ( systems [ 0 ] . description )
expect ( body . code ) . toBe ( systems [ 0 ] . code )
expect ( body . language ) . toBe ( systems [ 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 ->
request . get { uri : url + ' / ' + systems [ 0 ] . _id } , (err, res, body) ->
expect ( res . statusCode ) . toBe ( 200 )
body = JSON . parse ( body )
expect ( body . _id ) . toBe ( systems [ 0 ] . _id )
expect ( body . official ) . toBe ( false )
done ( )
it ' official property isn \' t editable by an ordinary user. ' , (done) ->
2014-01-03 10:32:13 -08:00
systems [ 0 ] . official = true
2014-01-15 20:36:59 +01:00
loginJoe ->
2014-01-03 10:32:13 -08:00
request . post { uri : url , json : systems [ 0 ] } , (err, res, body) ->
2014-01-15 20:36:59 +01:00
expect ( res . statusCode ) . toBe ( 403 )
2014-01-03 10:32:13 -08:00
done ( )
2014-01-15 20:36:59 +01:00
it ' official property is editable by an admin. ' , (done) ->
systems [ 0 ] . official = true
loginAdmin ->
request . post { uri : url , json : systems [ 0 ] } , (err, res, body) ->
expect ( res . statusCode ) . toBe ( 200 )
expect ( body . official ) . toBe ( true )
expect ( body . original ) . toBe ( systems [ 0 ] . original )
expect ( body . version . isLatestMinor ) . toBe ( true )
expect ( body . version . isLatestMajor ) . toBe ( true )
systems [ 1 ] = body
request . get { uri : url + ' / ' + systems [ 0 ] . _id } , (err, res, body) ->
expect ( res . statusCode ) . toBe ( 200 )
body = JSON . parse ( body )
expect ( body . _id ) . toBe ( systems [ 0 ] . _id )
expect ( body . official ) . toBe ( false )
expect ( body . version . isLatestMinor ) . toBe ( false )
expect ( body . version . isLatestMajor ) . toBe ( false )
done ( )
it ' can \' t be requested with HTTP HEAD method ' , (done) ->
request . head { uri : url + ' / ' + systems [ 0 ] . _id } , (err, res) ->
expect ( res . statusCode ) . toBe ( 404 )
done ( )
it ' can \' t be requested with HTTP DEL method ' , (done) ->
request . del { uri : url + ' / ' + systems [ 0 ] . _id } , (err, res) ->
expect ( res . statusCode ) . toBe ( 404 )
done ( )
2014-01-23 23:06:12 +01: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 ( )