mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
server db route (handlers and schemas)
- use associative arrays to store path/filename - add more test for schemas
This commit is contained in:
parent
e7ca7c4c1a
commit
bbfc0eff69
10 changed files with 104 additions and 5 deletions
|
@ -19,9 +19,24 @@ handlers =
|
|||
'level_feedback': '../../server/levels/feedbacks/level_feedback_handler'
|
||||
'level_session': '../../server/levels/sessions/level_session_handler'
|
||||
'level_system': '../../server/levels/systems/level_system_handler'
|
||||
'level_thang_type': '../../server/levels/thangs/level_thangType_handler'
|
||||
'thang_type': '../../server/levels/thangs/thang_type_handler'
|
||||
'user': '../../server/users/user_handler'
|
||||
|
||||
schemas =
|
||||
'article': '../../server/articles/article_schema'
|
||||
'common': '../../server/commons/schemas'
|
||||
#'file': '../../server/files/file_schema'
|
||||
'i18n': '../../server/commons/i18n_schema'
|
||||
'level': '../../server/levels/level_schema'
|
||||
'level_component': '../../server/levels/components/level_component_schema'
|
||||
'level_feedback': '../../server/levels/feedbacks/level_feedback_schema'
|
||||
'level_session': '../../server/levels/sessions/level_session_schema'
|
||||
'level_system': '../../server/levels/systems/level_system_schema'
|
||||
'metaschema': '../../server/commons/metaschema'
|
||||
'thang_component': '../../server/levels/thangs/thang_component_schema'
|
||||
'thang_type': '../../server/levels/thangs/thang_type_schema'
|
||||
'user': '../../server/users/user_schema'
|
||||
|
||||
|
||||
module.exports.connectDatabase = () ->
|
||||
dbName = config.mongo.db
|
||||
|
@ -64,8 +79,9 @@ module.exports.setupRoutes = (app) ->
|
|||
|
||||
getSchema = (req, res, moduleName) ->
|
||||
try
|
||||
name = "./schemas/#{moduleName.replace '.', '_'}"
|
||||
name = schemas[moduleName.replace '.', '_']
|
||||
schema = require(name)
|
||||
|
||||
res.send(schema)
|
||||
res.end()
|
||||
|
||||
|
|
|
@ -77,3 +77,10 @@ describe '/db/article', ->
|
|||
expect(res.statusCode).toBe(200)
|
||||
expect(body.name).toBe(new_article.name)
|
||||
done()
|
||||
|
||||
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()
|
||||
|
|
|
@ -7,7 +7,7 @@ describe 'Level', ->
|
|||
description: 'Climb a mountain.'
|
||||
permissions: simplePermissions
|
||||
|
||||
url = getURL('/db/level')
|
||||
urlLevel = '/db/level'
|
||||
|
||||
it 'clears things first', (done) ->
|
||||
clearModels [Level], (err) ->
|
||||
|
@ -16,6 +16,13 @@ describe 'Level', ->
|
|||
|
||||
it 'can make a Level.', (done) ->
|
||||
loginJoe ->
|
||||
request.post {uri:url, json:level}, (err, res, body) ->
|
||||
request.post {uri:getURL(urlLevel), json:level}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(200)
|
||||
done()
|
||||
|
||||
it 'get schema', (done) ->
|
||||
request.get {uri:getURL(urlLevel+'/schema')}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(200)
|
||||
body = JSON.parse(body)
|
||||
expect(body.type).toBeDefined()
|
||||
done()
|
||||
|
|
|
@ -139,3 +139,10 @@ describe 'LevelComponent', ->
|
|||
request.del {uri:url+'/'+components[0]._id}, (err, res) ->
|
||||
expect(res.statusCode).toBe(404)
|
||||
done()
|
||||
|
||||
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()
|
||||
|
|
12
test/server/handlers/level_feedback.spec.coffee
Normal file
12
test/server/handlers/level_feedback.spec.coffee
Normal file
|
@ -0,0 +1,12 @@
|
|||
require '../common'
|
||||
|
||||
describe 'LevelFeedback', ->
|
||||
|
||||
url = getURL('/db/level.feedback')
|
||||
|
||||
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()
|
12
test/server/handlers/level_session.spec.coffee
Normal file
12
test/server/handlers/level_session.spec.coffee
Normal file
|
@ -0,0 +1,12 @@
|
|||
require '../common'
|
||||
|
||||
describe 'LevelFeedback', ->
|
||||
|
||||
url = getURL('/db/level.session')
|
||||
|
||||
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()
|
|
@ -128,3 +128,10 @@ describe 'LevelSystem', ->
|
|||
request.del {uri:url+'/'+systems[0]._id}, (err, res) ->
|
||||
expect(res.statusCode).toBe(404)
|
||||
done()
|
||||
|
||||
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()
|
||||
|
|
12
test/server/handlers/level_thang_component.spec.coffee
Normal file
12
test/server/handlers/level_thang_component.spec.coffee
Normal file
|
@ -0,0 +1,12 @@
|
|||
require '../common'
|
||||
|
||||
describe 'Level Thang Component', ->
|
||||
|
||||
url = getURL('/db/thang.component')
|
||||
|
||||
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()
|
12
test/server/handlers/level_thang_type.spec.coffee
Normal file
12
test/server/handlers/level_thang_type.spec.coffee
Normal file
|
@ -0,0 +1,12 @@
|
|||
require '../common'
|
||||
|
||||
describe 'Level Thang Type', ->
|
||||
|
||||
url = getURL('/db/thang.type')
|
||||
|
||||
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()
|
|
@ -136,6 +136,13 @@ describe 'GET /db/user', ->
|
|||
form.append('username', 'admin@afc.com')
|
||||
form.append('password', '80yqxpb38j')
|
||||
|
||||
it 'get schema', (done) ->
|
||||
request.get {uri:getURL(urlUser+'/schema')}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(200)
|
||||
body = JSON.parse(body)
|
||||
expect(body.type).toBeDefined()
|
||||
done()
|
||||
|
||||
it 'is able to do a sweet query', (done) ->
|
||||
conditions = [
|
||||
['limit', 20]
|
||||
|
|
Loading…
Reference in a new issue