mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-06-15 07:00:09 +08:00
test of /admin
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
@@ -44,6 +44,8 @@ describe 'router/ticket', ->
|
||||
.expect /<p><strong>CONTENT<\/strong><\/p>/
|
||||
.end done
|
||||
|
||||
it 'GET view/:id when not exist'
|
||||
|
||||
it 'POST reply', (done) ->
|
||||
agent.post "/ticket/reply/#{ticket_id}"
|
||||
.send
|
||||
|
||||
Reference in New Issue
Block a user