Skip to content

Commit

Permalink
fix(test): updated test for priority changes
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Sep 7, 2018
1 parent de31779 commit cdf0a4d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 30 deletions.
4 changes: 3 additions & 1 deletion src/models/ticket.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ ticketSchema.methods.setTicketPriority = function(ownerId, priority, callback) {
};
self.history.push(historyItem);

callback(null, self);
self.populate('priority').execPopulate()
.then(function(updatedSelf){ return callback(null, updatedSelf); })
.catch(function(err) { return callback(err, null); });
};

/**
Expand Down
5 changes: 2 additions & 3 deletions src/settings/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,12 @@ function ticketPriorityDefaults(callback) {
priorities.push(normal);
priorities.push(urgent);
priorities.push(critical);

async.each(priorities, function(item, next) {
prioritySchema.findOne({migrationNum: item.migrationNum}, function(err, priority) {
if (!err && _.isUndefined(priority)) {
if (!err && (_.isUndefined(priority) || _.isNull(priority))) {
return item.save(next);
} else {
return next();
return next(err);
}
});
}, callback);
Expand Down
13 changes: 10 additions & 3 deletions test/0_database.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var path = require('path');
winston.setLevels(winston.config.cli.levels);
winston.remove(winston.transports.Console);
var database, db;
var CONNECTION_URI = 'mongodb://localhost/polonel_trudesk31908899';
var CONNECTION_URI = 'mongodb://localhost:27017/polonel_trudesk31908899';

//Global Setup for tests
before(function(done) {
Expand All @@ -31,7 +31,7 @@ before(function(done) {
mongoose.connection.db.dropDatabase(function(err) {
expect(err).to.not.exist;
cb();
});
})
},
function(cb) {
var counter = require('../src/models/counters');
Expand All @@ -44,6 +44,13 @@ before(function(done) {
cb();
});
},
function(cb) {
var typeSchema = require('../src/models/tickettype');
typeSchema.insertMany([{name: 'Task'}, {name: 'Issue'}], cb);
},
function(cb) {
require('../src/settings/defaults').init(cb);
},
function(cb) {
var userSchema = require('../src/models/user');
userSchema.create({
Expand Down Expand Up @@ -123,7 +130,7 @@ before(function(done) {
//Global Teardown for tests
after(function(done) {
this.timeout(5000);
mongoose.connection.db.dropDatabase(function() {
mongoose.connection.dropDatabase(function() {
mongoose.connection.close(function() {
server.close();

Expand Down
55 changes: 33 additions & 22 deletions test/models/ticket.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var should = require('chai').should();
var m = require('mongoose');
var ticketSchema = require('../../src/models/ticket');
var groupSchema = require('../../src/models/group');
var prioritySchema = require('../../src/models/ticketpriority');

describe('ticket.js', function() {
//it('should clear collections.', function(done) {
Expand All @@ -17,28 +18,33 @@ describe('ticket.js', function() {
//});

it('should create ticket', function(done) {
ticketSchema.create({
owner: m.Types.ObjectId(),
group: m.Types.ObjectId(),
status: 0,
tags: [],
date: new Date(),
subject: 'Dummy Test Subject',
issue: 'Dummy Test Issue',
priority: 0,
type: m.Types.ObjectId(),
history: []

}, function(err, t) {
prioritySchema.findOne({default: true}).exec(function(err, p) {
expect(err).to.not.exist;
expect(t).to.be.a('object');
expect(t._doc).to.include.keys(
'_id', 'uid', 'owner','group', 'status', 'tags', 'date', 'subject', 'issue', 'priority', 'type', 'history', 'attachments', 'comments', 'deleted'
);
expect(p).to.be.a('object');

expect(t.uid).to.equal(1000);
ticketSchema.create({
owner: m.Types.ObjectId(),
group: m.Types.ObjectId(),
status: 0,
tags: [],
date: new Date(),
subject: 'Dummy Test Subject',
issue: 'Dummy Test Issue',
priority: p._id,
type: m.Types.ObjectId(),
history: []

done();
}, function(err, t) {
expect(err).to.not.exist;
expect(t).to.be.a('object');
expect(t._doc).to.include.keys(
'_id', 'uid', 'owner','group', 'status', 'tags', 'date', 'subject', 'issue', 'priority', 'type', 'history', 'attachments', 'comments', 'deleted'
);

expect(t.uid).to.equal(1000);

done();
});
});
});

Expand Down Expand Up @@ -118,11 +124,16 @@ describe('ticket.js', function() {
it('should set ticket priority', function(done) {
ticketSchema.getTicketByUid(1000, function(err, ticket) {
var ownerId = m.Types.ObjectId();
ticket.setTicketPriority(ownerId, 3, function(err, ticket) {
prioritySchema.getByMigrationNum(3, function(err, priority) {
expect(err).to.not.exist;
expect(ticket.priority).to.equal(3);
expect(priority).to.be.a('object');

done();
ticket.setTicketPriority(ownerId, priority, function(err, ticket) {
expect(err).to.not.exist;
expect(ticket.priority.name).to.equal('Critical');

done();
});
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/models/tickettype.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('ticketType.js', function() {
ticketTypeSchema.getTypes(function(err, types) {
expect(err).to.not.exist;
expect(types).to.be.a('array');
expect(types).to.have.length(1);
expect(types).to.have.length(3); //Has default ticket types already

done();
});
Expand Down

0 comments on commit cdf0a4d

Please sign in to comment.