diff --git a/core/router/admin.coffee b/core/router/admin.coffee index b8f747f..012564f 100644 --- a/core/router/admin.coffee +++ b/core/router/admin.coffee @@ -1,19 +1,15 @@ -{ObjectID} = require 'mongodb' -express = require 'express' -async = require 'async' -_ = require 'underscore' - +{express, async, _} = app.libs {requireAdminAuthenticate} = app.middleware {plaggable} = app -{mAccount, mTicket, mBalanceLog, mCouponCode} = app.models +{Account, Ticket, Financials, CouponCode} = app.models module.exports = exports = express.Router() exports.get '/', requireAdminAuthenticate, (req, res) -> - mAccount.find().toArray (err, accounts) -> + Account.find {}, (err, accounts) -> return res.render 'admin', accounts: accounts - coupon_code_types: _.keys mCouponCode.type_meta + coupon_code_types: _.keys CouponCode.coupons_meta exports.get '/ticket', requireAdminAuthenticate, (req, res) -> async.parallel diff --git a/core/test/router/admin.test.coffee b/core/test/router/admin.test.coffee index f871c76..2c11eeb 100644 --- a/core/test/router/admin.test.coffee +++ b/core/test/router/admin.test.coffee @@ -1,5 +1,52 @@ describe 'router/admin', -> - it 'GET /' + utils = null + Account = null + + agent = null + csrf_token = null + + before -> + {utils} = app + {Account} = app.models + agent = supertest.agent app.express + + it 'should create a admin account first', (done) -> + username = "admin#{utils.randomString(10).toLowerCase()}" + password = utils.randomString 20 + + Account.register + username: username + email: "#{utils.randomString 20}@gmail.com" + password: password + , (err, admin) -> + created_objects.accounts.push admin._id + + admin.groups.push 'root' + admin.save -> + agent.get '/account/session_info' + .expect 200 + .end (err, res) -> + csrf_token = res.body.csrf_token + + agent.post '/account/login' + .send + csrf_token: csrf_token + username: username + password: password + .end (err, res) -> + res.body.token.should.be.exist + done err + + it 'GET / when no permission', (done) -> + namespace.accountRouter.agent + .get '/admin' + .expect 403 + .end done + + it 'GET /', (done) -> + agent.get '/admin' + .expect 200 + .end done it 'GET ticket' diff --git a/core/test/router/ticket.test.coffee b/core/test/router/ticket.test.coffee index 6fd2d19..0e66d4a 100644 --- a/core/test/router/ticket.test.coffee +++ b/core/test/router/ticket.test.coffee @@ -44,6 +44,8 @@ describe 'router/ticket', -> .expect /
CONTENT<\/strong><\/p>/ .end done + it 'GET view/:id when not exist' + it 'POST reply', (done) -> agent.post "/ticket/reply/#{ticket_id}" .send