server db route (handlers and schemas)

- use associative arrays to store path/filename
- add more test for schemas
This commit is contained in:
Sébastien Moratinos 2014-01-23 23:06:12 +01:00
parent e7ca7c4c1a
commit bbfc0eff69
10 changed files with 104 additions and 5 deletions

View file

@ -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()

View file

@ -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()

View file

@ -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()
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()

View file

@ -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()

View 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()

View 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()

View file

@ -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()

View 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()

View 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()

View file

@ -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]