mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-04-24 03:35:59 +08:00
test of /ticket/view
This commit is contained in:
@@ -16,6 +16,7 @@ app.libs =
|
||||
harp: require 'harp'
|
||||
markdown: require('markdown').markdown
|
||||
middlewareInjector: require 'middleware-injector'
|
||||
moment: require 'moment-timezone'
|
||||
mongoose: require 'mongoose'
|
||||
morgan: require 'morgan'
|
||||
nodemailer: require 'nodemailer'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{config} = app
|
||||
{_, expressSession, redisStore, path, fs} = app.libs
|
||||
{_, expressSession, redisStore, path, fs, moment} = app.libs
|
||||
{Account} = app.models
|
||||
|
||||
exports.errorHandling = (req, res, next) ->
|
||||
|
||||
@@ -101,23 +101,25 @@ Ticket.methods.hasMember = (account) ->
|
||||
Ticket.methods.populateAccounts = (callback) ->
|
||||
accounts_id = _.uniq [@account_id].concat @members.concat _.pluck(@replies, 'account_id')
|
||||
|
||||
async.each accounts_id, (account_id, callback) ->
|
||||
async.map accounts_id, (account_id, callback) ->
|
||||
Account.findById account_id, callback
|
||||
|
||||
, (err, accounts) ->
|
||||
, (err, accounts) =>
|
||||
logger.error err if err
|
||||
|
||||
accounts = _.indexBy accounts, '_id'
|
||||
|
||||
@account = accounts[@account_id]
|
||||
result = @toObject()
|
||||
|
||||
@members = _.map @members, (member_id) ->
|
||||
result.account = accounts[result.account_id]
|
||||
|
||||
result.members = _.map result.members, (member_id) ->
|
||||
return accounts[member_id]
|
||||
|
||||
for reply in @replies
|
||||
for reply in result.replies
|
||||
reply.account = accounts[reply.account_id]
|
||||
|
||||
callback()
|
||||
callback result
|
||||
|
||||
_.extend app.models,
|
||||
Ticket: mongoose.model 'Ticket', Ticket
|
||||
|
||||
@@ -42,9 +42,9 @@ exports.get '/create', (req, res) ->
|
||||
res.render 'ticket/create'
|
||||
|
||||
exports.get '/view/:id', (req, res) ->
|
||||
req.ticket.populateAccounts ->
|
||||
req.ticket.populateAccounts (ticket) ->
|
||||
res.render 'ticket/view',
|
||||
ticket: req.ticket
|
||||
ticket: ticket
|
||||
|
||||
exports.post '/create', (req, res) ->
|
||||
unless /^.+$/.test req.body.title
|
||||
|
||||
@@ -49,4 +49,9 @@ describe 'model/Ticket', ->
|
||||
ticket.hasMember(account).should.be.ok
|
||||
|
||||
describe 'populateAccounts', ->
|
||||
it 'pending'
|
||||
it 'should success', (done) ->
|
||||
ticket.populateAccounts (result) ->
|
||||
result.account.username.should.equal account.username
|
||||
result.members[0].username.should.equal account.username
|
||||
result.replies[0].account.username.should.equal account.username
|
||||
done()
|
||||
|
||||
@@ -38,7 +38,11 @@ describe 'router/ticket', ->
|
||||
.expect /Title/
|
||||
.end done
|
||||
|
||||
it 'GET view/:id'
|
||||
it 'GET view/:id', (done) ->
|
||||
agent.get "/ticket/view/#{ticket_id}"
|
||||
.expect 200
|
||||
.expect /<p><strong>CONTENT<\/strong><\/p>/
|
||||
.end done
|
||||
|
||||
it 'POST reply'
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ block main
|
||||
header
|
||||
| #{ticket.title}
|
||||
|
||||
- l_status = t('ticket_status.' + status)
|
||||
- l_status = t('ticket_status.' + ticket.status)
|
||||
|
||||
if ticket.status == 'closed'
|
||||
span.small.text-muted= l_status
|
||||
@@ -53,9 +53,9 @@ block main
|
||||
button.btn.btn-lg.btn-primary.action-reply(type='button')= t('ticket.create_reply')
|
||||
button(type='button', data-status='closed').btn.btn-lg.btn-danger.action-update-status= t('ticket.close_ticket')
|
||||
|
||||
if inGroup('root') && (ticket.status == 'open' || ticket.status == 'pending')
|
||||
if req.account.inGroup('root') && (ticket.status == 'open' || ticket.status == 'pending')
|
||||
button(type='button', data-status='finish').btn.btn-lg.btn-success.action-update-status= t('ticket.finish_ticket')
|
||||
if inGroup('root') && ticket.status == 'closed'
|
||||
if req.account.inGroup('root') && ticket.status == 'closed'
|
||||
button(type='button', data-status='open').btn.btn-lg.btn-success.action-update-status= t('ticket.reopen_ticket')
|
||||
|
||||
prepend sidebar
|
||||
|
||||
Reference in New Issue
Block a user