From d15bd11bdd3c9ed39e75e1ebf2008140af599bb4 Mon Sep 17 00:00:00 2001 From: Chris Brame Date: Mon, 21 Jan 2019 03:01:20 -0500 Subject: [PATCH] style(code): cleanup --- .eslintignore | 4 + .eslintrc.json | 35 +- gruntfile.js | 2 +- package.json | 3 + src/cache/quickStats.js | 2 + src/controllers/api/v1/groups.js | 2 + src/controllers/api/v1/reports.js | 9 + src/controllers/api/v1/tickets.js | 2 + src/controllers/debug.js | 8 + src/controllers/main.js | 7 + src/controllers/reports.js | 8 + src/controllers/settings.js | 4 - src/controllers/tickets.js | 2 +- src/emitter/events.js | 8 +- src/helpers/hbs/helpers.js | 1 + src/helpers/viewdata/index.js | 8 + src/middleware/index.js | 20 +- src/models/chat/message.js | 121 ++- src/models/ticket.js | 3 +- src/passport/index.js | 1 - src/public/js/angularjs/.eslintrc.json | 16 +- .../js/angularjs/controllers/plugins.js | 1 + .../js/angularjs/controllers/profile.js | 9 +- src/public/js/modules/helpers.js | 2 + src/public/js/pages/plugins.js | 1 + src/public/js/pages/reports.js | 8 +- src/public/js/pages/reportsBreakdown.js | 8 +- src/sass/buildsass.js | 1 - src/socketio/backupRestoreSocket.js | 2 +- src/socketio/logsSocket.js | 4 +- src/socketio/noticeSocket.js | 2 +- test/0_database.js | 365 +++---- test/1_sessions.js | 179 ++-- test/api/api.js | 119 +-- test/api/users.js | 476 +++++---- test/controllers/ticketsController.js | 174 ++-- test/models/group.js | 173 ++-- test/models/message.js | 216 ++-- test/models/ticket.js | 956 +++++++++--------- test/models/tickettype.js | 79 +- test/source/hbsHelpers.js | 38 +- test/source/installServer.js | 23 +- test/source/mailer.js | 3 +- test/source/permissions.js | 55 +- webpack.config.js | 6 +- yarn.lock | 28 +- 46 files changed, 1732 insertions(+), 1462 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 000000000..007e4cae1 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,4 @@ +/src/public/js/plugins/* +/src/public/js/vendor/* +/mobile/* +/public/* \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index 1fd1a5ec6..c65d8925f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,35 +1,30 @@ { - "plugins": ["node"], - "extends": ["standard", "plugin:node/recommended"], + "plugins": ["import", "prettier", "standard"], + "extends": ["standard", "prettier", "prettier/standard"], "root": true, "parserOptions": { "ecmaVersion": 5 }, "env": { "browser": true, - "node": true + "node": true, + "mocha": true }, "rules": { + "standard/no-callback-literal": 0, // enable after error handing refactor "node/exports-style": ["error", "module.exports"], + "new-cap": 0, "no-console": "off", - // "new-cap": "error", - "quotes": ["error", "single"], - "curly": ["error", "multi-or-nest"], - "complexity": ["error", 20], - "wrap-iife": ["error", "outside"], - "semi": ["error", "always"], - "no-extra-semi": "error", - "no-func-assign": "error", - "no-redeclare": "error" + "complexity": ["error", 20] }, "globals": { - "angular": 1, - "define": 1, - "requirejs": 1, - "MG": 1, - "Snackbar": 1, - "ROLES": 1, - "io": 1, - "d3": 1 + "angular": true, + "define": true, + "requirejs": true, + "MG": true, + "Snackbar": true, + "ROLES": true, + "io": true, + "d3": true } } diff --git a/gruntfile.js b/gruntfile.js index 51f8895d4..ebb162610 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -8,7 +8,7 @@ module.exports = function (grunt) { express: { options: { - //Override Defaults + // Override Defaults }, web: { options: { diff --git a/package.json b/package.json index 06dcd6923..1601cf8d7 100644 --- a/package.json +++ b/package.json @@ -111,10 +111,13 @@ "css-loader": "2.1.0", "eslint": "5.12.1", "eslint-config-angular": "0.5.0", + "eslint-config-prettier": "3.6.0", "eslint-config-standard": "12.0.0", "eslint-plugin-angular": "4.0.0", "eslint-plugin-import": "2.14.0", "eslint-plugin-node": "8.0.1", + "eslint-plugin-prettier": "3.0.1", + "eslint-plugin-promise": "4.0.1", "eslint-plugin-react": "7.12.4", "eslint-plugin-standard": "4.0.0", "exports-loader": "0.7.0", diff --git a/src/cache/quickStats.js b/src/cache/quickStats.js index 7388a3207..abb5402e6 100644 --- a/src/cache/quickStats.js +++ b/src/cache/quickStats.js @@ -40,6 +40,8 @@ var init = function (tickets, callback) { function (done) { if (tickets) { ticketSchema.populate(tickets, { path: 'owner comments.owner assignee' }, function (err, _tickets) { + if (err) return done(err) + $tickets = _tickets return done() diff --git a/src/controllers/api/v1/groups.js b/src/controllers/api/v1/groups.js index 39af4a5db..1a71914e9 100644 --- a/src/controllers/api/v1/groups.js +++ b/src/controllers/api/v1/groups.js @@ -50,6 +50,8 @@ apiGroups.get = function (req, res) { if (hasPublic) { GroupSchema.getAllPublicGroups(function (err, grps) { + if (err) return res.status(400).json({ success: false, error: err }) + groups = groups.concat(grps) return res.json({ success: true, groups: groups }) diff --git a/src/controllers/api/v1/reports.js b/src/controllers/api/v1/reports.js index 4e9a76a70..97642d303 100644 --- a/src/controllers/api/v1/reports.js +++ b/src/controllers/api/v1/reports.js @@ -124,6 +124,7 @@ apiReports.generate.ticketsByPriority = function (req, res) { function (done) { if (_.includes(postData.groups, '-1')) { groupSchema.getAllGroupsNoPopulate(function (err, grps) { + if (err) return done(err) return done(null, grps) }) } else { @@ -199,6 +200,8 @@ apiReports.generate.ticketsByStatus = function (req, res) { function (done) { if (_.includes(postData.groups, '-1')) { groupSchema.getAllGroupsNoPopulate(function (err, grps) { + if (err) return done(err) + return done(null, grps) }) } else { @@ -278,6 +281,8 @@ apiReports.generate.ticketsByTags = function (req, res) { function (done) { if (_.includes(postData.groups, '-1')) { groupSchema.getAllGroupsNoPopulate(function (err, grps) { + if (err) return done(err) + return done(null, grps) }) } else { @@ -356,6 +361,8 @@ apiReports.generate.ticketsByType = function (req, res) { function (done) { if (_.includes(postData.groups, '-1')) { groupSchema.getAllGroupsNoPopulate(function (err, grps) { + if (err) return done(err) + return done(null, grps) }) } else { @@ -434,6 +441,8 @@ apiReports.generate.ticketsByUser = function (req, res) { function (done) { if (_.includes(postData.groups, '-1')) { groupSchema.getAllGroupsNoPopulate(function (err, grps) { + if (err) return done(err) + return done(null, grps) }) } else { diff --git a/src/controllers/api/v1/tickets.js b/src/controllers/api/v1/tickets.js index 1ae70a0fd..489629bbf 100644 --- a/src/controllers/api/v1/tickets.js +++ b/src/controllers/api/v1/tickets.js @@ -651,6 +651,8 @@ apiTickets.update = function (req, res) { if (!_.isUndefined(reqTicket.assignee) && !_.isNull(reqTicket.assignee)) { ticket.assignee = reqTicket.assignee ticket.populate('assignee', function (err, t) { + if (err) return cb(err) + var HistoryItem = { action: 'ticket:set:assignee', description: t.assignee.fullname + ' was set as assignee', diff --git a/src/controllers/debug.js b/src/controllers/debug.js index 7877c7783..43fe7fea6 100644 --- a/src/controllers/debug.js +++ b/src/controllers/debug.js @@ -389,9 +389,17 @@ debugController.populatedatabase = function (req, res) { }, function (done) { userSchema.findAll(function (err, users) { + if (err) return done(err) + groupSchema.getAllGroups(function (err, groups) { + if (err) return done(err) + ticketTypeSchema.getTypes(function (err, types) { + if (err) return done(err) + tagSchema.getTags(function (err, tags) { + if (err) return done(err) + var loremIpsum = require('lorem-ipsum') for (var i = 0; i < 100001; i++) { var user = users[Math.floor(Math.random() * users.length)] diff --git a/src/controllers/main.js b/src/controllers/main.js index f1e0c1a65..5c28776c4 100644 --- a/src/controllers/main.js +++ b/src/controllers/main.js @@ -61,6 +61,13 @@ mainController.about = function (req, res) { var marked = require('marked') var settings = require('../models/setting') settings.getSettingByName('legal:privacypolicy', function (err, privacyPolicy) { + if (err) + return res.render('error', { + layout: false, + error: err, + message: err.message + }) + var content = {} content.title = 'About' content.nav = 'about' diff --git a/src/controllers/reports.js b/src/controllers/reports.js index e9e30286f..62507ec12 100644 --- a/src/controllers/reports.js +++ b/src/controllers/reports.js @@ -59,6 +59,14 @@ reportsController.generate = function (req, res) { var prioritySchema = require('../models/ticketpriority') prioritySchema.getPriorities(function (err, priorities) { + if (err) { + return res.render('error', { + layout: false, + error: err, + message: err.message + }) + } + content.data.priorities = priorities return res.render('subviews/reports/generate', content) diff --git a/src/controllers/settings.js b/src/controllers/settings.js index fb1b59e00..971dd7c35 100644 --- a/src/controllers/settings.js +++ b/src/controllers/settings.js @@ -12,11 +12,7 @@ * Copyright (c) 2014-2019. All rights reserved. */ -var async = require('async') var _ = require('lodash') -var jsStringEscape = require('js-string-escape') -var settingSchema = require('../models/setting') -var ticketTypeSchema = require('../models/tickettype') var permissions = require('../permissions') var settingsUtil = require('../settings/settingsUtil') diff --git a/src/controllers/tickets.js b/src/controllers/tickets.js index 6962bdd2d..6ce9e81f8 100644 --- a/src/controllers/tickets.js +++ b/src/controllers/tickets.js @@ -91,7 +91,7 @@ ticketsController.getByStatus = function (req, res, next) { status: [] } - var pathname = url.parse(req.url).pathname + var pathname = url.URL(req.url).pathname var arr = pathname.split('/') var tType = 'new' var s = 0 diff --git a/src/emitter/events.js b/src/emitter/events.js index 0c3570bb1..d196830f5 100644 --- a/src/emitter/events.js +++ b/src/emitter/events.js @@ -36,9 +36,11 @@ var notifications = require('../notifications') // Load Push Events var hostname = data.hostname ticketSchema.getTicketById(ticketObj._id, function (err, ticket) { - if (err) return true + if (err) return false settingsSchema.getSettingsByName(['tps:enable', 'tps:username', 'tps:apikey'], function (err, tpsSettings) { + if (err) return false + var tpsEnabled = _.head(_.filter(tpsSettings, ['name', 'tps:enable'])) var tpsUsername = _.head(_.filter(tpsSettings, ['name', 'tps:username'])) var tpsApiKey = _.head(_.filter(tpsSettings), ['name', 'tps:apikey']) @@ -302,6 +304,8 @@ var notifications = require('../notifications') // Load Push Events io.sockets.emit('updateComments', ticket) settingsSchema.getSettingsByName(['tps:enable', 'tps:username', 'tps:apikey'], function (err, tpsSettings) { + if (err) return false + var tpsEnabled = _.head(_.filter(tpsSettings, ['name', 'tps:enable'])) var tpsUsername = _.head(_.filter(tpsSettings, ['name', 'tps:username'])) var tpsApiKey = _.head(_.filter(tpsSettings), ['name', 'tps:apikey']) @@ -441,6 +445,8 @@ var notifications = require('../notifications') // Load Push Events emitter.on('ticket:setAssignee', function (data) { settingsSchema.getSettingsByName(['tps:enable', 'tps:username', 'tps:apikey'], function (err, tpsSettings) { + if (err) return false + var tpsEnabled = _.head(_.filter(tpsSettings, ['name', 'tps:enable'])) var tpsUsername = _.head(_.filter(tpsSettings, ['name', 'tps:username'])) var tpsApiKey = _.head(_.filter(tpsSettings), ['name', 'tps:apikey']) diff --git a/src/helpers/hbs/helpers.js b/src/helpers/hbs/helpers.js index 9eba1e191..1dc8ae601 100644 --- a/src/helpers/hbs/helpers.js +++ b/src/helpers/hbs/helpers.js @@ -215,6 +215,7 @@ var helpers = { return l >= r }, typeof: function (l, r) { + // eslint-disable-next-line return typeof l === r } } diff --git a/src/helpers/viewdata/index.js b/src/helpers/viewdata/index.js index 569cb6c5f..56cf53cfb 100644 --- a/src/helpers/viewdata/index.js +++ b/src/helpers/viewdata/index.js @@ -312,6 +312,8 @@ viewController.getData = function (request, cb) { }, function (callback) { viewController.getShowTourSetting(request, function (err, data) { + if (err) return callback(err) + viewdata.showTour = data return callback() @@ -319,6 +321,8 @@ viewController.getData = function (request, cb) { }, function (callback) { viewController.getOverdueSetting(request, function (err, data) { + if (err) return callback(err) + viewdata.showOverdue = data return callback() @@ -326,6 +330,8 @@ viewController.getData = function (request, cb) { }, function (callback) { viewController.getPluginsInfo(request, function (err, data) { + if (err) return callback(err) + viewdata.plugins = data return callback() @@ -589,6 +595,8 @@ viewController.getShowTourSetting = function (request, callback) { var userSchema = require('../../models/user') userSchema.getUser(request.user._id, function (err, user) { + if (err) return callback(err) + var hasTourCompleted = false if (user.preferences.tourCompleted) { diff --git a/src/middleware/index.js b/src/middleware/index.js index 80e022ddc..f0144a2cb 100644 --- a/src/middleware/index.js +++ b/src/middleware/index.js @@ -12,36 +12,19 @@ * Copyright (c) 2014-2019. All rights reserved. */ -var _ = require('lodash') - var path = require('path') - var async = require('async') - var express = require('express') - var mongoose = require('mongoose') - var HandleBars = require('handlebars').create() - var hbs = require('express-hbs') - var hbsHelpers = require('../helpers/hbs/helpers') - var winston = require('winston') - var flash = require('connect-flash') - var bodyParser = require('body-parser') - var cookieParser = require('cookie-parser') - -var favicon = require('serve-favicon') - var session = require('express-session') - var MongoStore = require('connect-mongo')(session) - var passportConfig = require('../passport')() var middleware = {} @@ -57,13 +40,12 @@ module.exports = function (app, db, callback) { hbs.express4({ handlebars: HandleBars, defaultLayout: path.join(__dirname, '../views/layout/main.hbs'), - partialsDir: [path.join(__dirname + '/../views/partials/'), path.join(__dirname + '/../views/subviews/reports')] + partialsDir: [path.join(__dirname, '../views/partials/'), path.join(__dirname, '../views/subviews/reports')] }) ) app.set('view engine', 'hbs') hbsHelpers.register(hbs.handlebars) - // app.use(favicon(nconf.get('base_dir') + '/public/img/favicon.ico')); app.use(bodyParser.urlencoded({ extended: false })) app.use(bodyParser.json()) app.use(cookieParser()) diff --git a/src/models/chat/message.js b/src/models/chat/message.js index 009d1ca66..f0953d78a 100644 --- a/src/models/chat/message.js +++ b/src/models/chat/message.js @@ -1 +1,120 @@ -/* . .o8 oooo .o8 "888 `888 .o888oo oooo d8b oooo oooo .oooo888 .ooooo. .oooo.o 888 oooo 888 `888""8P `888 `888 d88' `888 d88' `88b d88( "8 888 .8P' 888 888 888 888 888 888 888ooo888 `"Y88b. 888888. 888 . 888 888 888 888 888 888 .o o. )88b 888 `88b. "888" d888b `V88V"V8P' `Y8bod88P" `Y8bod8P' 8""888P' o888o o888o ======================================================================== Created: 11/24/2016 Author: Chris Brame **/ var mongoose = require('mongoose') var _ = require('lodash') var COLLECTION = 'messages' var messageSchema = mongoose.Schema( { conversation: { type: mongoose.Schema.Types.ObjectId, required: true, index: true }, owner: { type: mongoose.Schema.Types.ObjectId, ref: 'accounts', required: true, index: true }, body: { type: String, required: true } }, { timestamps: true } ) messageSchema.statics.getFullConversation = function (convoId, callback) { return this.model(COLLECTION) .find({ conversation: convoId }) .select('createdAt body owner') .sort('-createdAt') .populate({ path: 'owner', select: '_id username fullname email image lastOnline' }) .exec(callback) } messageSchema.statics.getConversation = function (convoId, callback) { return this.model(COLLECTION) .find({ conversation: convoId }) .select('createdAt body owner') .sort('-createdAt') .limit(25) .populate({ path: 'owner', select: '_id username fullname email image lastOnline' }) .exec(callback) } messageSchema.statics.getConversationWithObject = function (object, callback) { if (!_.isObject(object)) { return callback('Invalid Object (Must by of type Object) - MessageSchema.GetUserWithObject()', null) } var self = this var deletedAt = null var limit = object.limit === null ? 25 : object.limit var page = object.page === null ? 0 : object.page if (object.requestingUser) { var userMetaIdx = _.findIndex(object.userMeta, function (item) { return item.userId.toString() === object.requestingUser._id.toString() }) if (userMetaIdx !== -1 && object.userMeta[userMetaIdx].deletedAt) { deletedAt = new Date(object.userMeta[userMetaIdx].deletedAt) } } var q = self .model(COLLECTION) .find({}) .sort('-createdAt') .skip(page * limit) .populate({ path: 'owner', select: '_id username fullname email image lastOnline' }) if (limit !== -1) { q.limit(limit) } if (object.cid !== null) { q.where({ conversation: object.cid }) } if (deletedAt) { q.where({ createdAt: { $gte: deletedAt } }) } return q.exec(callback) } messageSchema.statics.getMostRecentMessage = function (convoId, callback) { return this.model(COLLECTION) .find({ conversation: convoId }) .sort('-createdAt') .limit(1) .populate({ path: 'owner', select: '_id username fullname image lastOnline' }) .exec(callback) } module.exports = mongoose.model(COLLECTION, messageSchema) \ No newline at end of file +/* + * . .o8 oooo + * .o8 "888 `888 + * .o888oo oooo d8b oooo oooo .oooo888 .ooooo. .oooo.o 888 oooo + * 888 `888""8P `888 `888 d88' `888 d88' `88b d88( "8 888 .8P' + * 888 888 888 888 888 888 888ooo888 `"Y88b. 888888. + * 888 . 888 888 888 888 888 888 .o o. )88b 888 `88b. + * "888" d888b `V88V"V8P' `Y8bod88P" `Y8bod8P' 8""888P' o888o o888o + * ======================================================================== + * Author: Chris Brame + * Updated: 1/21/19 2:04 AM + * Copyright (c) 2014-2019. All rights reserved. + */ + +var mongoose = require('mongoose') +var _ = require('lodash') + +var COLLECTION = 'messages' + +var messageSchema = mongoose.Schema( + { + conversation: { + type: mongoose.Schema.Types.ObjectId, + required: true, + index: true + }, + owner: { + type: mongoose.Schema.Types.ObjectId, + ref: 'accounts', + required: true, + index: true + }, + body: { type: String, required: true } + }, + { timestamps: true } +) + +messageSchema.statics.getFullConversation = function (convoId, callback) { + return this.model(COLLECTION) + .find({ conversation: convoId }) + .select('createdAt body owner') + .sort('-createdAt') + .populate({ + path: 'owner', + select: '_id username fullname email image lastOnline' + }) + .exec(callback) +} + +messageSchema.statics.getConversation = function (convoId, callback) { + return this.model(COLLECTION) + .find({ conversation: convoId }) + .select('createdAt body owner') + .sort('-createdAt') + .limit(25) + .populate({ + path: 'owner', + select: '_id username fullname email image lastOnline' + }) + .exec(callback) +} + +messageSchema.statics.getConversationWithObject = function (object, callback) { + if (!_.isObject(object)) { + return callback('Invalid Object (Must by of type Object) - MessageSchema.GetUserWithObject()', null) + } + + var self = this + var deletedAt = null + + var limit = object.limit === null ? 25 : object.limit + var page = object.page === null ? 0 : object.page + + if (object.requestingUser) { + var userMetaIdx = _.findIndex(object.userMeta, function (item) { + return item.userId.toString() === object.requestingUser._id.toString() + }) + if (userMetaIdx !== -1 && object.userMeta[userMetaIdx].deletedAt) { + deletedAt = new Date(object.userMeta[userMetaIdx].deletedAt) + } + } + + var q = self + .model(COLLECTION) + .find({}) + .sort('-createdAt') + .skip(page * limit) + .populate({ + path: 'owner', + select: '_id username fullname email image lastOnline' + }) + + if (limit !== -1) { + q.limit(limit) + } + + if (object.cid !== null) { + q.where({ conversation: object.cid }) + } + + if (deletedAt) { + q.where({ createdAt: { $gte: deletedAt } }) + } + + return q.exec(callback) +} + +messageSchema.statics.getMostRecentMessage = function (convoId, callback) { + return this.model(COLLECTION) + .find({ conversation: convoId }) + .sort('-createdAt') + .limit(1) + .populate({ + path: 'owner', + select: '_id username fullname image lastOnline' + }) + .exec(callback) +} + +module.exports = mongoose.model(COLLECTION, messageSchema) diff --git a/src/models/ticket.js b/src/models/ticket.js index da1b19400..523c910dc 100644 --- a/src/models/ticket.js +++ b/src/models/ticket.js @@ -16,7 +16,6 @@ var async = require('async') var mongoose = require('mongoose') var _ = require('lodash') var moment = require('moment') -var hash = require('object-hash') // var redisCache = require('../cache/rediscache'); // Needed - For Population @@ -338,6 +337,8 @@ ticketSchema.methods.setTicketGroup = function (ownerId, groupId, callback) { self.group = groupId self.populate('group', function (err, ticket) { + if (err) return callback(err) + var historyItem = { action: 'ticket:set:group', description: 'Ticket Group set to: ' + ticket.group.name, diff --git a/src/passport/index.js b/src/passport/index.js index 2930519bd..e6a9116cb 100644 --- a/src/passport/index.js +++ b/src/passport/index.js @@ -12,7 +12,6 @@ * Copyright (c) 2014-2019. All rights reserved. */ -var _ = require('lodash') var passport = require('passport') var Local = require('passport-local').Strategy var TotpStrategy = require('passport-totp').Strategy diff --git a/src/public/js/angularjs/.eslintrc.json b/src/public/js/angularjs/.eslintrc.json index 41b29d5aa..4c310853b 100644 --- a/src/public/js/angularjs/.eslintrc.json +++ b/src/public/js/angularjs/.eslintrc.json @@ -1,6 +1,6 @@ { - "plugins": ["angular"], - "extends": ["eslint:recommended", "angular"], + "plugins": ["angular", "standard", "import"], + "extends": ["angular", "standard", "prettier", "prettier/standard"], "env": { "browser": true, "node": true @@ -11,18 +11,16 @@ "angular/controller-as": "off", "angular/controller-name": "off", "quotes": ["error", "single"], - "curly": ["error", "multi-or-nest"], "complexity": ["error", 20], "wrap-iife": ["error", "outside"], - "semi": ["error", "always"], "no-extra-semi": "error", "no-func-assign": "error", "no-redeclare": "error" }, "globals": { - "angular": 1, - "define": 1, - "requirejs": 1, - "History": 1 + "angular": true, + "define": true, + "requirejs": true, + "History": true } -} \ No newline at end of file +} diff --git a/src/public/js/angularjs/controllers/plugins.js b/src/public/js/angularjs/controllers/plugins.js index a1b6babdf..2fcfae902 100644 --- a/src/public/js/angularjs/controllers/plugins.js +++ b/src/public/js/angularjs/controllers/plugins.js @@ -226,6 +226,7 @@ define(['angular', 'underscore', 'jquery', 'modules/helpers', 'history'], functi cmp = -1 } } + // eslint-disable-next-line return eval('0' + comparator + cmp) } }) diff --git a/src/public/js/angularjs/controllers/profile.js b/src/public/js/angularjs/controllers/profile.js index 36134b3cc..55808e948 100644 --- a/src/public/js/angularjs/controllers/profile.js +++ b/src/public/js/angularjs/controllers/profile.js @@ -172,9 +172,12 @@ define([ ) } else { generateL2Auth(function (err, key) { - // if (err || angular.isUndefined(key)) { - // //$window.location.reload(); - // } else { + if (err) { + $log.error(err) + helpers.UI.showSnackbar('An unknown error occurred. Check console.', true) + return + } + $timeout(function () { $scope.otpEnabled = true angular.element(event.target).prop('checked', true) diff --git a/src/public/js/modules/helpers.js b/src/public/js/modules/helpers.js index 6fe9a8da9..90595c2dc 100644 --- a/src/public/js/modules/helpers.js +++ b/src/public/js/modules/helpers.js @@ -277,6 +277,7 @@ define([ return } + // eslint-disable-next-line new Tether({ element: element, target: target, @@ -1668,6 +1669,7 @@ define([ } helpers.prototypes = function () { + // eslint-disable-next-line String.prototype.formatUnicorn = String.prototype.formatUnicorn || function () { diff --git a/src/public/js/pages/plugins.js b/src/public/js/pages/plugins.js index 0d3a5ec96..c45de6b84 100644 --- a/src/public/js/pages/plugins.js +++ b/src/public/js/pages/plugins.js @@ -34,6 +34,7 @@ define('pages/plugins', ['jquery', 'modules/helpers', 'tether', 'history'], func }) if ($('.plugin-tether').length > 0) { + // eslint-disable-next-line new Tether({ element: '.plugin-tether', target: '.tether-plugins', diff --git a/src/public/js/pages/reports.js b/src/public/js/pages/reports.js index 0f1bd7cd9..06b1cbed6 100644 --- a/src/public/js/pages/reports.js +++ b/src/public/js/pages/reports.js @@ -86,12 +86,12 @@ define('pages/reports', [ fill: ['#29b955', '#ccc'] }) - var responseTime_text = $('#responseTime_text') + var responseTimeText = $('#responseTime_text') // var responseTime_graph = $('#responseTime_graph'); - var oldResponseTime = responseTime_text.text() === '--' ? 0 : responseTime_text.text() + var oldResponseTime = responseTimeText.text() === '--' ? 0 : responseTimeText.text() var responseTime = _data.ticketAvg - var responseTime_animation = new CountUp('responseTime_text', parseInt(oldResponseTime), responseTime, 0, 1.5) - responseTime_animation.start() + var responeTimeAnimation = new CountUp('responseTime_text', parseInt(oldResponseTime), responseTime, 0, 1.5) + responeTimeAnimation.start() } }).error(function (err) { // console.log(err); diff --git a/src/public/js/pages/reportsBreakdown.js b/src/public/js/pages/reportsBreakdown.js index fc5e6ae21..58caf9db4 100644 --- a/src/public/js/pages/reportsBreakdown.js +++ b/src/public/js/pages/reportsBreakdown.js @@ -103,18 +103,18 @@ define('pages/reportsBreakdown', [ fill: ['#29b955', '#ccc'] }) - var responseTime_text = $('#responseTime_text') + var responseTimeText = $('#responseTime_text') // var responseTime_graph = $('#responseTime_graph'); - var oldResponseTime = responseTime_text.text() === '--' ? 0 : responseTime_text.text() + var oldResponseTime = responseTimeText.text() === '--' ? 0 : responseTimeText.text() var responseTime = _data.data.avgResponse - var responseTime_animation = new CountUp( + var responseTimeAnimation = new CountUp( 'responseTime_text', parseInt(oldResponseTime), responseTime, 0, 1.5 ) - responseTime_animation.start() + responseTimeAnimation.start() var recentTicketsBody = $('tbody.recent-tickets') recentTicketsBody.html('') diff --git a/src/sass/buildsass.js b/src/sass/buildsass.js index a7297663a..573fed0de 100644 --- a/src/sass/buildsass.js +++ b/src/sass/buildsass.js @@ -15,7 +15,6 @@ var _ = require('lodash') var path = require('path') var sass = require('node-sass') -var nconf = require('nconf') var settingUtil = require('../settings/settingsUtil') var buildsass = {} diff --git a/src/socketio/backupRestoreSocket.js b/src/socketio/backupRestoreSocket.js index e1c000c14..c31cc0bb1 100644 --- a/src/socketio/backupRestoreSocket.js +++ b/src/socketio/backupRestoreSocket.js @@ -11,7 +11,7 @@ * Updated: 1/20/19 4:43 PM * Copyright (c) 2014-2019. All rights reserved. */ -var _ = require('lodash') + var utils = require('../helpers/utils') var sharedVars = require('./index').shared diff --git a/src/socketio/logsSocket.js b/src/socketio/logsSocket.js index 6291afb37..ecae6965a 100644 --- a/src/socketio/logsSocket.js +++ b/src/socketio/logsSocket.js @@ -15,7 +15,7 @@ var utils = require('../helpers/utils') var path = require('path') var AnsiUp = require('ansi_up') -var ansi_up = new AnsiUp.default() +var ansiUp = new AnsiUp.default() var fileTailer = require('file-tail') var fs = require('fs-extra') @@ -35,7 +35,7 @@ events.onLogsFetch = function (socket) { } else { var ft = fileTailer.startTailing(logFile) ft.on('line', function (line) { - utils.sendToSelf(socket, 'logs:data', ansi_up.ansi_to_html(line)) + utils.sendToSelf(socket, 'logs:data', ansiUp.ansi_to_html(line)) }) } }) diff --git a/src/socketio/noticeSocket.js b/src/socketio/noticeSocket.js index 1da2ec926..68bd69b92 100644 --- a/src/socketio/noticeSocket.js +++ b/src/socketio/noticeSocket.js @@ -11,7 +11,7 @@ * Updated: 1/20/19 4:43 PM * Copyright (c) 2014-2019. All rights reserved. */ -var _ = require('lodash') + var winston = require('winston') var utils = require('../helpers/utils') var noticeSchema = require('../models/notice') diff --git a/test/0_database.js b/test/0_database.js index 80795b5e1..cbcf90f5f 100644 --- a/test/0_database.js +++ b/test/0_database.js @@ -1,178 +1,203 @@ -var expect = require('chai').expect; -var should = require('chai').should(); -var winston = require('winston'); -var async = require('async'); -var mongoose = require('mongoose'); -var path = require('path'); - -winston.setLevels(winston.config.cli.levels); -winston.remove(winston.transports.Console); -var database, db; -var CONNECTION_URI = 'mongodb://localhost:27017/polonel_trudesk31908899'; - -//Global Setup for tests -before(function(done) { - this.timeout(15000); // Make it a longer timeout since we have to start the web server - delete require.cache[require.resolve('../src/database')]; - delete require.cache[require.resolve('mongoose')]; - mongoose = require('mongoose'); - database = require('../src/database'); - - mongoose.connection.close(); - database.init(function(err, d) { - expect(err).to.not.exist; - expect(d).to.be.a('object'); - expect(d.connection).to.exist; - - db = d; - - async.series([ - function(cb) { - mongoose.connection.db.dropDatabase(function(err) { - expect(err).to.not.exist; - cb(); - }); +/* eslint-disable no-unused-expressions */ +/* globals server */ +var expect = require('chai').expect +var winston = require('winston') +var async = require('async') +var mongoose = require('mongoose') +var path = require('path') + +winston.setLevels(winston.config.cli.levels) +winston.remove(winston.transports.Console) +var database, db +var CONNECTION_URI = 'mongodb://localhost:27017/polonel_trudesk31908899' + +// Global Setup for tests +before(function (done) { + this.timeout(15000) // Make it a longer timeout since we have to start the web server + delete require.cache[require.resolve('../src/database')] + delete require.cache[require.resolve('mongoose')] + mongoose = require('mongoose') + database = require('../src/database') + + mongoose.connection.close() + database.init(function (err, d) { + expect(err).to.not.exist + expect(d).to.be.a('object') + expect(d.connection).to.exist + + db = d + + async.series( + [ + function (cb) { + mongoose.connection.db.dropDatabase(function (err) { + expect(err).to.not.exist + cb() + }) + }, + function (cb) { + var counter = require('../src/models/counters') + counter.create( + { + _id: 'tickets', + next: 1000 }, - function(cb) { - var counter = require('../src/models/counters'); - counter.create({ - _id: 'tickets', - next: 1000 - }, function(err) { - expect(err).to.not.exist; - - 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({ - username: 'trudesk', - password: '$2a$04$350Dkwcq9EpJLFhbeLB0buFcyFkI9q3edQEPpy/zqLjROMD9LPToW', - fullname: 'Trudesk', - email: 'trudesk@trudesk.io', - role: 'admin', - accessToken: 'da39a3ee5e6b4b0d3255bfef95601890afd80709' - }, function(err, user) { - expect(err).to.not.exist; - expect(user).to.be.a('object'); - - cb(); - }); - }, - function(cb) { - var userSchema = require('../src/models/user'); - userSchema.create({ - username: 'fake.user', - password: '$2a$04$350Dkwcq9EpJLFhbeLB0buFcyFkI9q3edQEPpy/zqLjROMD9LPToW', - fullname: 'Fake user', - email: 'fake.user@trudesk.io', - role: 'mod', - accessToken: '456' - }, function(err, user) { - expect(err).to.not.exist; - expect(user).to.be.a('object'); - - cb(); - }); - }, - function(cb) { - var userSchema = require('../src/models/user'); - userSchema.create({ - username: 'deleted.user', - password: '$2a$04$350Dkwcq9EpJLFhbeLB0buFcyFkI9q3edQEPpy/zqLjROMD9LPToW', - fullname: 'Deleted User', - email: 'deleted.user@trudesk.io', - role: 'user', - accessToken: '123', - deleted: true - }, function(err, user) { - expect(err).to.not.exist; - expect(user).to.be.a('object'); - - cb(); - }); + function (err) { + expect(err).to.not.exist + + 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( + { + username: 'trudesk', + password: '$2a$04$350Dkwcq9EpJLFhbeLB0buFcyFkI9q3edQEPpy/zqLjROMD9LPToW', + fullname: 'Trudesk', + email: 'trudesk@trudesk.io', + role: 'admin', + accessToken: 'da39a3ee5e6b4b0d3255bfef95601890afd80709' }, - function(cb) { - var groupSchema = require('../src/models/group'); - groupSchema.create({ - name: 'TEST' - }, function(err, group) { - expect(err).to.not.exist; - expect(group).to.be.a('object'); - - cb(); - }); + function (err, user) { + expect(err).to.not.exist + expect(user).to.be.a('object') + + cb() + } + ) + }, + function (cb) { + var userSchema = require('../src/models/user') + userSchema.create( + { + username: 'fake.user', + password: '$2a$04$350Dkwcq9EpJLFhbeLB0buFcyFkI9q3edQEPpy/zqLjROMD9LPToW', + fullname: 'Fake user', + email: 'fake.user@trudesk.io', + role: 'mod', + accessToken: '456' }, - function(cb) { - var ws = require('../src/webserver'); - ws.init(db, function(err) { - expect(err).to.not.exist; - global.server = ws.server; - - cb(); - }, 3111); + function (err, user) { + expect(err).to.not.exist + expect(user).to.be.a('object') + + cb() } - ], function() { - done(); - }); - }, CONNECTION_URI); -}); - - -//Global Teardown for tests -after(function(done) { - this.timeout(5000); - mongoose.connection.dropDatabase(function() { - mongoose.connection.close(function() { - server.close(); - - done(); - }); - }); -}); - -//Start DB Tests -describe('Database', function() { - beforeEach(function(done) { - //Need to invalid Database Module before each test runs. - delete require.cache[path.join(__dirname, '../src/database')]; - database = require('../src/database'); - - done(); - }); - - it('should connect without error', function(done) { - async.series([ - function(cb) { - database.init(function(err, db) { - expect(err).to.not.exist; - expect(db).to.be.a('object'); - expect(db.connection._readyState).to.equal(1); - - cb(); - }, CONNECTION_URI); + ) + }, + function (cb) { + var userSchema = require('../src/models/user') + userSchema.create( + { + username: 'deleted.user', + password: '$2a$04$350Dkwcq9EpJLFhbeLB0buFcyFkI9q3edQEPpy/zqLjROMD9LPToW', + fullname: 'Deleted User', + email: 'deleted.user@trudesk.io', + role: 'user', + accessToken: '123', + deleted: true }, - function(cb) { - //Test rerunning init and getting DB back without calling connect. - database.init(function(err, db) { - expect(err).to.not.exist; - expect(db).to.be.a('object'); - expect(db.connection._readyState).to.equal(1); + function (err, user) { + expect(err).to.not.exist + expect(user).to.be.a('object') - cb(); + cb() + } + ) + }, + function (cb) { + var groupSchema = require('../src/models/group') + groupSchema.create( + { + name: 'TEST' + }, + function (err, group) { + expect(err).to.not.exist + expect(group).to.be.a('object') - }, CONNECTION_URI); + cb() } - ], function(err) { - done(); - }); - }); -}); + ) + }, + function (cb) { + var ws = require('../src/webserver') + ws.init( + db, + function (err) { + expect(err).to.not.exist + global.server = ws.server + + cb() + }, + 3111 + ) + } + ], + function () { + done() + } + ) + }, CONNECTION_URI) +}) + +// Global Teardown for tests +after(function (done) { + this.timeout(5000) + mongoose.connection.dropDatabase(function () { + mongoose.connection.close(function () { + server.close() + + done() + }) + }) +}) + +// Start DB Tests +describe('Database', function () { + beforeEach(function (done) { + // Need to invalid Database Module before each test runs. + delete require.cache[path.join(__dirname, '../src/database')] + database = require('../src/database') + + done() + }) + + it('should connect without error', function (done) { + async.series( + [ + function (cb) { + database.init(function (err, db) { + expect(err).to.not.exist + expect(db).to.be.a('object') + expect(db.connection._readyState).to.equal(1) + + cb() + }, CONNECTION_URI) + }, + function (cb) { + // Test rerunning init and getting DB back without calling connect. + database.init(function (err, db) { + expect(err).to.not.exist + expect(db).to.be.a('object') + expect(db.connection._readyState).to.equal(1) + + cb() + }, CONNECTION_URI) + } + ], + function (err) { + expect(err).to.not.exist + done() + } + ) + }) +}) diff --git a/test/1_sessions.js b/test/1_sessions.js index 77ccda917..aae92e6c3 100644 --- a/test/1_sessions.js +++ b/test/1_sessions.js @@ -1,92 +1,87 @@ -var async = require('async'); -var expect = require('chai').expect; -var should = require('chai').should(); -var request = require('supertest'); -var superagent = require('superagent'); - - -describe('sessions', function() { - var agent = superagent.agent(); - var unauthAgent = superagent.agent(); - var user = { 'login-username': 'trudesk', 'login-password': '$2a$04$350Dkwcq9EpJLFhbeLB0buFcyFkI9q3edQEPpy/zqLjROMD9LPToW'}; - - it('should gain a session', function(done) { - agent.post('http://localhost:3111/login') - .type('json') - .send(user) - .end(function(err, res) { - should.not.exist(err); - expect(res.status).to.equal(200); - // expect(res.user).to.exist; - - done(); - }); - }); - - it('should be logged in', function(done) { - agent.get('http://localhost:3111/tickets') - .end(function(err, res) { - expect(err).to.not.exist; - expect(res.status).to.equal(200); - res.redirects.should.eql([]); - - done(); - }); - }); - - it('should redirect if logged in', function(done) { - agent.get('http://localhost:3111/') - .end(function(err, res) { - expect(err).to.not.exist; - expect(res.status).to.equal(200); - expect(res.text).to.include('Trudesk · Dashboard'); - - done(); - }); - }); - - it('should redirect on un-auth', function(done) { - unauthAgent.get('http://localhost:3111/tickets') - .end(function(err, res) { - expect(err).to.not.exist; - expect(res.status).to.equal(200); - expect(res.text).to.include('Trudesk · Login'); - - done(); - }); - }); - - it('should redirect to login on /install', function(done) { - unauthAgent.get('http://localhost:3111/install') - .end(function(err, res) { - expect(err).to.not.exist; - expect(res.status).to.equal(200); - expect(res.text).to.include('Trudesk · Login'); - - done(); - }); - }); - - it('should logout', function(done) { - agent.get('http://localhost:3111/logout') - .end(function(err, res) { - expect(err).to.not.exist; - expect(res.status).to.equal(200); - res.redirects.should.eql(['http://localhost:3111/']); - - done(); - }); - }); - - it('should return Trudesk Version', function(done) { - agent.get('http://localhost:3111/api/v1/version') - .end(function(err, res) { - expect(err).to.not.exist; - expect(res.status).to.equal(200); - expect(res.text).to.include('version'); - - done(); - }); - }); - -}); +/* eslint-disable no-unused-expressions */ +var expect = require('chai').expect +var should = require('chai').should() +var superagent = require('superagent') + +describe('sessions', function () { + var agent = superagent.agent() + var unauthAgent = superagent.agent() + var user = { + 'login-username': 'trudesk', + 'login-password': '$2a$04$350Dkwcq9EpJLFhbeLB0buFcyFkI9q3edQEPpy/zqLjROMD9LPToW' + } + + it('should gain a session', function (done) { + agent + .post('http://localhost:3111/login') + .type('json') + .send(user) + .end(function (err, res) { + should.not.exist(err) + expect(res.status).to.equal(200) + // expect(res.user).to.exist; + + done() + }) + }) + + it('should be logged in', function (done) { + agent.get('http://localhost:3111/tickets').end(function (err, res) { + expect(err).to.not.exist + expect(res.status).to.equal(200) + res.redirects.should.eql([]) + + done() + }) + }) + + it('should redirect if logged in', function (done) { + agent.get('http://localhost:3111/').end(function (err, res) { + expect(err).to.not.exist + expect(res.status).to.equal(200) + expect(res.text).to.include('Trudesk · Dashboard') + + done() + }) + }) + + it('should redirect on un-auth', function (done) { + unauthAgent.get('http://localhost:3111/tickets').end(function (err, res) { + expect(err).to.not.exist + expect(res.status).to.equal(200) + expect(res.text).to.include('Trudesk · Login') + + done() + }) + }) + + it('should redirect to login on /install', function (done) { + unauthAgent.get('http://localhost:3111/install').end(function (err, res) { + expect(err).to.not.exist + expect(res.status).to.equal(200) + expect(res.text).to.include('Trudesk · Login') + + done() + }) + }) + + it('should logout', function (done) { + agent.get('http://localhost:3111/logout').end(function (err, res) { + expect(err).to.not.exist + expect(res.status).to.equal(200) + res.redirects.should.eql(['http://localhost:3111/']) + + done() + }) + }) + + it('should return Trudesk Version', function (done) { + agent.get('http://localhost:3111/api/v1/version').end(function (err, res) { + expect(err).to.not.exist + expect(res.status).to.equal(200) + expect(res.text).to.include('version') + + done() + }) + }) +}) diff --git a/test/api/api.js b/test/api/api.js index e4ac25ef8..147a08d80 100644 --- a/test/api/api.js +++ b/test/api/api.js @@ -1,58 +1,61 @@ -var async = require('async'); -var expect = require('chai').expect; -var should = require('chai').should(); -var request = require('supertest'); -var superagent = require('superagent'); - -describe('api/api.js', function() { - - var agent = superagent.agent(); - - it('should return 401 for failed login', function(done) { - var user = { username: 'test', password: '' }; - agent.post('http://localhost:3111/api/v1/login') - .send(user) - .end(function(err,res) { - expect(err).to.exist; - expect(err.status).to.equal(401); - - done(); - }); - }); - - it('should login', function(done) { - var user = { username: 'trudesk', password: '$2a$04$350Dkwcq9EpJLFhbeLB0buFcyFkI9q3edQEPpy/zqLjROMD9LPToW'}; - request(server).post('/api/v1/login') - .send(user) - .expect(200, done); - }); - - - //it('should have access token', function(done) { - // var userSchema = require('../../src/models/user'); - // userSchema.getUserByUsername('trudesk', function(err, user) { - // expect(err).to.not.exist; - // expect(user).to.be.a('object'); - // expect(user.accessToken).to.exist; - // - // done(); - // }); - //}); - - it ('should return a 404 error (\'/api/404\')', function(done) { - request(server).get('/api/404').expect(404, done); - }); - - it('should allow accessToken', function(done) { - request(server).get('/api/v1/tickets/1000') - .set('accesstoken', 'da39a3ee5e6b4b0d3255bfef95601890afd80709') - .expect(200, done); - }); - - it('should error Invalid Access Token', function(done) { - request(server).get('/api/v1/tickets/1000') - .set('accesstoken', '1') - .expect(401, done); - }); - -}); +/* eslint-disable no-unused-expressions */ +/* globals server */ +var expect = require('chai').expect +var request = require('supertest') +var superagent = require('superagent') + +describe('api/api.js', function () { + var agent = superagent.agent() + + it('should return 401 for failed login', function (done) { + var user = { username: 'test', password: '' } + agent + .post('http://localhost:3111/api/v1/login') + .send(user) + .end(function (err, res) { + expect(err).to.exist + expect(err.status).to.equal(401) + + done() + }) + }) + + it('should login', function (done) { + var user = { username: 'trudesk', password: '$2a$04$350Dkwcq9EpJLFhbeLB0buFcyFkI9q3edQEPpy/zqLjROMD9LPToW' } + request(server) + .post('/api/v1/login') + .send(user) + .expect(200, done) + }) + + // it('should have access token', function(done) { + // var userSchema = require('../../src/models/user'); + // userSchema.getUserByUsername('trudesk', function(err, user) { + // expect(err).to.not.exist; + // expect(user).to.be.a('object'); + // expect(user.accessToken).to.exist; + // + // done(); + // }); + // }); + + it("should return a 404 error ('/api/404')", function (done) { + request(server) + .get('/api/404') + .expect(404, done) + }) + + it('should allow accessToken', function (done) { + request(server) + .get('/api/v1/tickets/1000') + .set('accesstoken', 'da39a3ee5e6b4b0d3255bfef95601890afd80709') + .expect(200, done) + }) + + it('should error Invalid Access Token', function (done) { + request(server) + .get('/api/v1/tickets/1000') + .set('accesstoken', '1') + .expect(401, done) + }) +}) diff --git a/test/api/users.js b/test/api/users.js index 842684f09..eeff7f1f8 100644 --- a/test/api/users.js +++ b/test/api/users.js @@ -1,236 +1,264 @@ -var _ = require('lodash'); -var async = require('async'); -var expect = require('chai').expect; -var should = require('chai').should(); -var request = require('supertest'); -var superagent = require('superagent'); +/* eslint-disable no-unused-expressions */ +var async = require('async') +var expect = require('chai').expect +var request = require('supertest') -describe('api/users.js', function() { +describe('api/users.js', function () { + var tdapikey = 'da39a3ee5e6b4b0d3255bfef95601890afd80709' + request = request('http://localhost:3111') - var agent = superagent.agent(); - var tdapikey = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'; - request = request('http://localhost:3111'); + it('should return users', function (done) { + request + .get('/api/v1/users?limit=10&page=0&search=trudesk') + .set('accesstoken', tdapikey) + .set('Accept', 'application/json') + .expect(function (res) { + if (res.body.count !== 1) throw new Error('Could not get users') + }) + .expect(200, done) + }) - it('should return users', function(done) { - request.get('/api/v1/users?limit=10&page=0&search=trudesk') + it('should return a user', function (done) { + request + .get('/api/v1/users/trudesk') + .set('accesstoken', tdapikey) + .set('Accept', 'application/json') + .expect(function (res) { + if (res.body.user.username !== 'trudesk') throw new Error('Invalid User') + }) + .expect(200, done) + }) + + it('should create new user', function (done) { + var user = { + aUsername: 'new.user.1', + aPass: 'password', + aPassConfirm: 'password', + aFullname: 'New User', + aEmail: 'new.user.1@trudesk.io', + aRole: 'user', + aTitle: 'My New Title', + aGrps: [] + } + + async.series( + [ + function (cb) { + request + .post('/api/v1/users/create') + .set('accesstoken', tdapikey) + .set('Content-Type', 'application/json') + .send(user) + .set('Accept', 'application/json') + .expect(200, cb) + }, + function (cb) { + user.aGrps = undefined + request + .post('/api/v1/users/create') + .set('accesstoken', tdapikey) + .set('Content-Type', 'application/json') + .send(user) + .set('Accept', 'application/json') + .expect( + 400, + { + success: false, + error: 'Invalid Group Array' + }, + cb + ) + }, + function (cb) { + // password mismatch + user.aPass = '2222' + user.aGrps = [] + request + .post('/api/v1/users/create') + .set('accesstoken', tdapikey) + .set('Content-Type', 'application/json') + .send(user) + .set('Accept', 'application/json') + .expect( + 400, + { + success: false, + error: 'Invalid Password Match' + }, + cb + ) + }, + function (cb) { + request + .post('/api/v1/users/create') + .set('accesstoken', tdapikey) + .expect( + 400, + { + success: false, + error: 'Invalid Post Data' + }, + cb + ) + } + ], + function (err) { + if (err) throw err + + done() + } + ) + }) + + it('should update user', function (done) { + async.waterfall( + [ + function (cb) { + var userSchema = require('../../src/models/user') + userSchema.getUserByUsername('fake.user', function (err, user) { + if (err) return cb(err) + + return cb(null, user) + }) + }, + function (user, cb) { + var u = { + aTitle: 'The Title', + aRole: 'support' + } + + cb(null, u) + } + ], + function (err, u) { + if (err) return done(err) + request + .put('/api/v1/users/fake.user') .set('accesstoken', tdapikey) + .set('Content-Type', 'application/json') + .send(u) .set('Accept', 'application/json') - .expect(function(res) { - if (res.body.count !== 1) throw new Error('Could not get users'); + .expect(function (res) { + if (res.body.success !== true) throw new Error('Unable to update user') }) - .expect(200, done); - }); + .expect(200, done) + } + ) + }) + + it('should add user to group', function (done) { + var groupSchema = require('../../src/models/group') + var userSchema = require('../../src/models/user') + + groupSchema.getGroupByName('TEST', function (err, group) { + expect(err).to.not.exist - it('should return a user', function(done) { - request.get('/api/v1/users/trudesk') + userSchema.getUserByUsername('trudesk', function (err, user) { + expect(err).to.not.exist + var u = { + aFullname: user.fullname, + aEmail: user.email, + aGrps: [group._id], + saveGroups: true + } + + request + .put('/api/v1/users/trudesk') .set('accesstoken', tdapikey) + .set('Content-Type', 'application/json') + .send(u) .set('Accept', 'application/json') - .expect(function(res) { - if (res.body.user.username !== 'trudesk') throw new Error('Invalid User'); - }) - .expect(200, done); - }); - - it('should create new user', function(done) { - var user = { - 'aUsername': 'new.user.1', - 'aPass': 'password', - 'aPassConfirm': 'password', - 'aFullname': 'New User', - 'aEmail': 'new.user.1@trudesk.io', - 'aRole': 'user', - 'aTitle': 'My New Title', - 'aGrps': [] - }; - - async.series([ - function(cb) { - request.post('/api/v1/users/create') - .set('accesstoken', tdapikey) - .set('Content-Type', 'application/json') - .send(user) - .set('Accept', 'application/json') - .expect(200, cb); - }, - function(cb) { - user.aGrps = undefined; - request.post('/api/v1/users/create') - .set('accesstoken', tdapikey) - .set('Content-Type', 'application/json') - .send(user) - .set('Accept', 'application/json') - .expect(400, { - success: false, - error: 'Invalid Group Array' - }, cb); - }, - function(cb) { - //password mismatch - user.aPass = '2222'; - user.aGrps = []; - request.post('/api/v1/users/create') - .set('accesstoken', tdapikey) - .set('Content-Type', 'application/json') - .send(user) - .set('Accept', 'application/json') - .expect(400, { - success: false, - error: 'Invalid Password Match' - }, cb); - }, - function(cb) { - request.post('/api/v1/users/create') - .set('accesstoken', tdapikey) - .expect(400, { - success: false, - error: 'Invalid Post Data' - }, cb); - } - ], function(err) { - if (err) throw err; - - done(); - }); - }); - - it('should update user', function(done) { - async.waterfall([ - function(cb) { - var userSchema = require('../../src/models/user'); - userSchema.getUserByUsername('fake.user', function(err, user) { - if (err) return cb(err); - - return cb(null, user); - }); - }, - function(user, cb) { - var u = { - aTitle: 'The Title', - aRole: 'support' - }; - - cb(null, u); - } - ], function(err, u) { - if (err) return done(err); - request.put('/api/v1/users/fake.user') - .set('accesstoken', tdapikey) - .set('Content-Type', 'application/json') - .send(u) - .set('Accept', 'application/json') - .expect(function(res) { - if (res.body.success !== true) throw new Error('Unable to update user'); - }) - .expect(200, done); - }); - }); - - it('should add user to group', function(done) { - var groupSchema = require('../../src/models/group'); - var userSchema = require('../../src/models/user'); - - groupSchema.getGroupByName('TEST', function(err, group) { - expect(err).to.not.exist; - - userSchema.getUserByUsername('trudesk', function(err, user) { - expect(err).to.not.exist; - var u = { - aFullname: user.fullname, - aEmail: user.email, - aGrps: [group._id], - saveGroups: true - }; - - request.put('/api/v1/users/trudesk') - .set('accesstoken', tdapikey) - .set('Content-Type', 'application/json') - .send(u) - .set('Accept', 'application/json') - .expect(200, function() { - groupSchema.getGroupByName('TEST', function(err, grp) { - expect(err).to.not.exist; - - expect(grp.isMember(user._id)).to.equal(true); - - done(); - }); - }); - }); - }); - }); - - it('should remove user from group', function(done) { - var groupSchema = require('../../src/models/group'); - var userSchema = require('../../src/models/user'); - - groupSchema.getGroupByName('TEST', function(err, group) { - expect(err).to.not.exist; - - userSchema.getUserByUsername('trudesk', function(err, user) { - expect(err).to.not.exist; - var u = { - aId: user._id, - aFullname: user.fullname, - aEmail: user.email, - aGrps: [], - saveGroups: true - }; - - request.put('/api/v1/users/trudesk') - .set('accesstoken', tdapikey) - .set('Content-Type', 'application/json') - .send(u) - .set('Accept', 'application/json') - .expect(200, { success: true }, function() { - groupSchema.getGroupByName('TEST', function(err, grp) { - expect(err).to.not.exist; - expect(grp.isMember(user._id)).to.equal(false); - - done(); - }) - }); - }); - }); - }); - - it('should update user preference', function(done) { - var data = { - preference: 'autoRefreshTicketGrid', - value: false - }; - - request.put('/api/v1/users/trudesk/updatepreferences') - .set('accesstoken', tdapikey) - .set('Content-Type', 'application/json') - .send(data) - .set('Accept', 'application/json') - .expect(function(res) { - if (res.body.success !== true || - res.body.user.preferences.autoRefreshTicketGrid !== false) - throw new Error('Unable to update user'); + .expect(200, function () { + groupSchema.getGroupByName('TEST', function (err, grp) { + expect(err).to.not.exist + + expect(grp.isMember(user._id)).to.equal(true) + + done() }) - .expect(200, done); - }); - - // it('POST /api/v1/public/account/create - should create public account', function(done) { - // request.post('/api/v1/public/account/create') - // .set('accesstoken', tdapikey) - // .set('Content-Type', 'application/json') - // .send({user: {email: 'public.user@trudesk.io', password: 'password', fullname: 'public.user@trudesk.io'}}) - // .expect(function(res) { - // console.log(res); - // expect(res.body.success).to.eq(true); - // }) - // .expect(200, done); - // }); - - it('should delete user', function(done) { - request.delete('/api/v1/users/deleted.user') + }) + }) + }) + }) + + it('should remove user from group', function (done) { + var groupSchema = require('../../src/models/group') + var userSchema = require('../../src/models/user') + + groupSchema.getGroupByName('TEST', function (err, group) { + expect(err).to.not.exist + + userSchema.getUserByUsername('trudesk', function (err, user) { + expect(err).to.not.exist + var u = { + aId: user._id, + aFullname: user.fullname, + aEmail: user.email, + aGrps: [], + saveGroups: true + } + + request + .put('/api/v1/users/trudesk') .set('accesstoken', tdapikey) + .set('Content-Type', 'application/json') + .send(u) .set('Accept', 'application/json') - .expect(200, { - success: true, - disabled: false - }, done); - }); -}); + .expect(200, { success: true }, function () { + groupSchema.getGroupByName('TEST', function (err, grp) { + expect(err).to.not.exist + expect(grp.isMember(user._id)).to.equal(false) + + done() + }) + }) + }) + }) + }) + + it('should update user preference', function (done) { + var data = { + preference: 'autoRefreshTicketGrid', + value: false + } + + request + .put('/api/v1/users/trudesk/updatepreferences') + .set('accesstoken', tdapikey) + .set('Content-Type', 'application/json') + .send(data) + .set('Accept', 'application/json') + .expect(function (res) { + if (res.body.success !== true || res.body.user.preferences.autoRefreshTicketGrid !== false) + throw new Error('Unable to update user') + }) + .expect(200, done) + }) + + // it('POST /api/v1/public/account/create - should create public account', function(done) { + // request.post('/api/v1/public/account/create') + // .set('accesstoken', tdapikey) + // .set('Content-Type', 'application/json') + // .send({user: {email: 'public.user@trudesk.io', password: 'password', fullname: 'public.user@trudesk.io'}}) + // .expect(function(res) { + // console.log(res); + // expect(res.body.success).to.eq(true); + // }) + // .expect(200, done); + // }); + + it('should delete user', function (done) { + request + .delete('/api/v1/users/deleted.user') + .set('accesstoken', tdapikey) + .set('Accept', 'application/json') + .expect( + 200, + { + success: true, + disabled: false + }, + done + ) + }) +}) diff --git a/test/controllers/ticketsController.js b/test/controllers/ticketsController.js index 080a72e6a..6b7dfe3de 100644 --- a/test/controllers/ticketsController.js +++ b/test/controllers/ticketsController.js @@ -1,94 +1,106 @@ -var async = require('async'); -var expect = require('chai').expect; -var should = require('chai').should(); -var request = require('supertest'); +/* eslint-disable no-unused-expressions */ +var async = require('async') +var expect = require('chai').expect +var request = require('supertest') -describe('ticketsController', function() { - var authAgent = request.agent('http://localhost:3111'); - var user = { 'login-username': 'trudesk', 'login-password': '$2a$04$350Dkwcq9EpJLFhbeLB0buFcyFkI9q3edQEPpy/zqLjROMD9LPToW'}; - var cookie; +describe('ticketsController', function () { + var authAgent = request.agent('http://localhost:3111') + var user = { + 'login-username': 'trudesk', + 'login-password': '$2a$04$350Dkwcq9EpJLFhbeLB0buFcyFkI9q3edQEPpy/zqLjROMD9LPToW' + } + var cookie - //FIRST! - before(function(done) { - authAgent - .post('/login') - .send(user) - .end(function(err, res) { - cookie = res.headers['set-cookie']; + // FIRST! + before(function (done) { + authAgent + .post('/login') + .send(user) + .end(function (err, res) { + if (err) return done(err) + cookie = res.headers['set-cookie'] - done(); - }); - }); + done() + }) + }) - it('/tickets/:status - should return tickets by status', function(done) { - async.parallel([ - function(next) { - authAgent.get('/tickets/new') - .set('Cookie', cookie) - .end(function(err) { - expect(err).to.not.exist; - - next(); - }); - }, - function(next) { - authAgent.get('/tickets/open') - .set('Cookie', cookie) - .end(function(err) { - expect(err).to.not.exist; + it('/tickets/:status - should return tickets by status', function (done) { + async.parallel( + [ + function (next) { + authAgent + .get('/tickets/new') + .set('Cookie', cookie) + .end(function (err) { + expect(err).to.not.exist - next(); - }); - }, - function(next) { - authAgent.get('/tickets/pending') - .set('Cookie', cookie) - .end(function(err) { - expect(err).to.not.exist; + next() + }) + }, + function (next) { + authAgent + .get('/tickets/open') + .set('Cookie', cookie) + .end(function (err) { + expect(err).to.not.exist - next(); - }); - }, - function(next) { - authAgent.get('/tickets/closed') - .set('Cookie', cookie) - .end(function(err) { - expect(err).to.not.exist; + next() + }) + }, + function (next) { + authAgent + .get('/tickets/pending') + .set('Cookie', cookie) + .end(function (err) { + expect(err).to.not.exist - next(); - }); - } - ], done); + next() + }) + }, + function (next) { + authAgent + .get('/tickets/closed') + .set('Cookie', cookie) + .end(function (err) { + expect(err).to.not.exist - }); + next() + }) + } + ], + done + ) + }) - it('/tickets/assigned - should get tickets assigned to user', function(done) { - authAgent.get('/tickets/assigned') - .set('Cookie', cookie) - .end(function(err) { - expect(err).to.not.exist; + it('/tickets/assigned - should get tickets assigned to user', function (done) { + authAgent + .get('/tickets/assigned') + .set('Cookie', cookie) + .end(function (err) { + expect(err).to.not.exist - done(); - }); - }); + done() + }) + }) - it('/tickets/unassigned - should get unassigned tickets', function(done) { - authAgent.get('/tickets/unassigned') - .set('Cookie', cookie) - .end(function(err) { - expect(err).to.not.exist; + it('/tickets/unassigned - should get unassigned tickets', function (done) { + authAgent + .get('/tickets/unassigned') + .set('Cookie', cookie) + .end(function (err) { + expect(err).to.not.exist - done(); - }); - }); + done() + }) + }) - // it('/tickets/{uid} - should return single ticket', function(done) { - // authAgent.get('/tickets/1000') - // .set('Cookie', cookie) - // .end(function(err) { - // expect(err).to.not.exist; - // - // done(); - // }); - // }); -}); \ No newline at end of file + // it('/tickets/{uid} - should return single ticket', function(done) { + // authAgent.get('/tickets/1000') + // .set('Cookie', cookie) + // .end(function(err) { + // expect(err).to.not.exist; + // + // done(); + // }); + // }); +}) diff --git a/test/models/group.js b/test/models/group.js index 44b9aeee4..e6a03c23d 100644 --- a/test/models/group.js +++ b/test/models/group.js @@ -1,88 +1,85 @@ -var async = require('async'); -var expect = require('chai').expect; -var should = require('chai').should(); -var m = require('mongoose'); -var groupSchema = require('../../src/models/group'); - -describe('group.js', function() { - - var groupId = m.Types.ObjectId(); - var memberId1 = m.Types.ObjectId(); - var memberId2 = m.Types.ObjectId(); - var memberId3 = m.Types.ObjectId(); - - var nonMember1 = m.Types.ObjectId(); - - it('should create a group', function(done) { - groupSchema.create({ - _id: groupId, - name: 'Test Group', - members: [memberId1, memberId2, memberId3], - sendMailTo: [] - - }, function(err, group) { - expect(err).to.not.exist; - expect(group).to.be.a('object'); - expect(group._doc).to.include.keys( - '_id', 'name', 'members', 'sendMailTo' - ); - - done(); - }); - }); - - it('should get all groups', function(done) { - groupSchema.getAllGroups(function(err, group) { - expect(err).to.not.exist; - expect(group).to.have.length(2); - - done(); - }); - }); - - it('should get group by id', function(done) { - groupSchema.getGroupById(groupId, function(err, groups) { - expect(err).to.not.exist; - expect(groups).to.be.a('object'); - - done(); - }); - }); - - - it('should add group member', function(done) { - groupSchema.getGroupByName('Test Group', function(err, group) { - expect(err).to.not.exist; - expect(group).to.be.a('object'); - - group.addMember(nonMember1, function(err, success) { - expect(err).to.not.exist; - expect(success).to.equal(true); - - group.addMember(memberId1, function(err, success) { - expect(err).to.not.exist; - expect(success).to.equal(true); - - done(); - }); - }); - }); - }); - - it('should remove group member', function(done) { - groupSchema.getGroupByName('Test Group', function(err, group) { - expect(err).to.not.exist; - expect(group).to.be.a('object'); - var mem = { - _id: memberId2 - }; - group.members = [mem]; - group.removeMember(memberId2, function(err, success) { - expect(err).to.not.exist; - expect(success).to.equal(true); - - done(); - }); - }); - }); -}); +/* eslint-disable no-unused-expressions */ +var expect = require('chai').expect +var m = require('mongoose') +var groupSchema = require('../../src/models/group') + +describe('group.js', function () { + var groupId = m.Types.ObjectId() + var memberId1 = m.Types.ObjectId() + var memberId2 = m.Types.ObjectId() + var memberId3 = m.Types.ObjectId() + + var nonMember1 = m.Types.ObjectId() + + it('should create a group', function (done) { + groupSchema.create( + { + _id: groupId, + name: 'Test Group', + members: [memberId1, memberId2, memberId3], + sendMailTo: [] + }, + function (err, group) { + expect(err).to.not.exist + expect(group).to.be.a('object') + expect(group._doc).to.include.keys('_id', 'name', 'members', 'sendMailTo') + + done() + } + ) + }) + + it('should get all groups', function (done) { + groupSchema.getAllGroups(function (err, group) { + expect(err).to.not.exist + expect(group).to.have.length(2) + + done() + }) + }) + + it('should get group by id', function (done) { + groupSchema.getGroupById(groupId, function (err, groups) { + expect(err).to.not.exist + expect(groups).to.be.a('object') + + done() + }) + }) + + it('should add group member', function (done) { + groupSchema.getGroupByName('Test Group', function (err, group) { + expect(err).to.not.exist + expect(group).to.be.a('object') + + group.addMember(nonMember1, function (err, success) { + expect(err).to.not.exist + expect(success).to.equal(true) + + group.addMember(memberId1, function (err, success) { + expect(err).to.not.exist + expect(success).to.equal(true) + + done() + }) + }) + }) + }) + + it('should remove group member', function (done) { + groupSchema.getGroupByName('Test Group', function (err, group) { + expect(err).to.not.exist + expect(group).to.be.a('object') + var mem = { + _id: memberId2 + } + group.members = [mem] + group.removeMember(memberId2, function (err, success) { + expect(err).to.not.exist + expect(success).to.equal(true) + + done() + }) + }) + }) +}) diff --git a/test/models/message.js b/test/models/message.js index 087b27d47..384f9c28d 100644 --- a/test/models/message.js +++ b/test/models/message.js @@ -1,108 +1,108 @@ -var async = require('async'); -var expect = require('chai').expect; -var should = require('chai').should(); -var m = require('mongoose'); -var messageSchema = require('../../src/models/chat/message'); - -describe('message.js', function() { - //it('should clear collections.', function(done) { - // expect(mongoose).to.exist; - // - // dbHelper.clearCollections(mongoose, function(err) { - // expect(err).to.not.exist; - // - // done(); - // }); - //}); - - // var messageId = m.Types.ObjectId(); - // var ownerId = m.Types.ObjectId(); - // - // it('should create message', function(done) { - // messageSchema.create({ - // _id: messageId, - // owner: ownerId, - // from: m.Types.ObjectId(), - // subject: 'This is the Subject', - // message: 'This is the message' - // }, function(err, message) { - // expect(err).to.not.exist; - // expect(message).to.be.a('object'); - // expect(message._doc).to.include.keys( - // '_id', 'owner', 'folder', 'unread', 'from', 'subject', 'date', 'message' - // ); - // - // done(); - // }); - // }); - // - // it('should mark as read', function(done) { - // messageSchema.getMessageById(messageId, function(err, message) { - // expect(err).to.not.exist; - // expect(message).to.be.a('object'); - // - // message.updateUnread(undefined, function(err, message) { - // expect(err).to.not.exist; - // expect(message).to.be.a('object'); - // expect(message.unread).to.exist; - // expect(message.unread).to.equal(false); - // - // done(); - // }); - // }); - // }); - // - // it('should move to folder', function(done) { - // messageSchema.getMessageById(messageId, function(err, message) { - // expect(err).to.not.exist; - // expect(message).to.be.a('object'); - // - // message.moveToFolder(1, function(err, message) { - // expect(err).to.not.exist; - // expect(message).to.be.a('object'); - // expect(message.folder).to.exist; - // expect(message.folder).to.equal(1); - // - // done(); - // }); - // }); - // }); - // - // it('should get message with object', function(done) { - // var object = { - // limit: 10, - // page: 0, - // folder: 1, - // owner: ownerId - // }; - // - // messageSchema.getMessagesWithObject(object, function(err, messages) { - // expect(err).to.not.exist; - // expect(messages).to.be.a('array'); - // expect(messages).to.have.length(1); - // - // var message = messages[0]; - // expect(message._id).to.exist; - // - // done(); - // }); - // }); - // - // it('should get unread message count of INBOX', function(done) { - // messageSchema.getUnreadInboxCount(ownerId, function(err, count) { - // expect(err).to.not.exist; - // expect(count).to.equal(0); - // - // done(); - // }); - // }); - // - // it('should get user folder', function(done) { - // messageSchema.getUserFolder(ownerId, 1, function(err, messages) { - // expect(err).to.not.exist; - // expect(messages).to.have.length(1); - // - // done(); - // }); - // }); -}); +// var async = require('async'); +// var expect = require('chai').expect; +// var should = require('chai').should(); +// var m = require('mongoose'); +// var messageSchema = require('../../src/models/chat/message'); +// +// describe('message.js', function() { +// // it('should clear collections.', function(done) { +// // expect(mongoose).to.exist; +// // +// // dbHelper.clearCollections(mongoose, function(err) { +// // expect(err).to.not.exist; +// // +// // done(); +// // }); +// // }); +// +// // var messageId = m.Types.ObjectId(); +// // var ownerId = m.Types.ObjectId(); +// // +// // it('should create message', function(done) { +// // messageSchema.create({ +// // _id: messageId, +// // owner: ownerId, +// // from: m.Types.ObjectId(), +// // subject: 'This is the Subject', +// // message: 'This is the message' +// // }, function(err, message) { +// // expect(err).to.not.exist; +// // expect(message).to.be.a('object'); +// // expect(message._doc).to.include.keys( +// // '_id', 'owner', 'folder', 'unread', 'from', 'subject', 'date', 'message' +// // ); +// // +// // done(); +// // }); +// // }); +// // +// // it('should mark as read', function(done) { +// // messageSchema.getMessageById(messageId, function(err, message) { +// // expect(err).to.not.exist; +// // expect(message).to.be.a('object'); +// // +// // message.updateUnread(undefined, function(err, message) { +// // expect(err).to.not.exist; +// // expect(message).to.be.a('object'); +// // expect(message.unread).to.exist; +// // expect(message.unread).to.equal(false); +// // +// // done(); +// // }); +// // }); +// // }); +// // +// // it('should move to folder', function(done) { +// // messageSchema.getMessageById(messageId, function(err, message) { +// // expect(err).to.not.exist; +// // expect(message).to.be.a('object'); +// // +// // message.moveToFolder(1, function(err, message) { +// // expect(err).to.not.exist; +// // expect(message).to.be.a('object'); +// // expect(message.folder).to.exist; +// // expect(message.folder).to.equal(1); +// // +// // done(); +// // }); +// // }); +// // }); +// // +// // it('should get message with object', function(done) { +// // var object = { +// // limit: 10, +// // page: 0, +// // folder: 1, +// // owner: ownerId +// // }; +// // +// // messageSchema.getMessagesWithObject(object, function(err, messages) { +// // expect(err).to.not.exist; +// // expect(messages).to.be.a('array'); +// // expect(messages).to.have.length(1); +// // +// // var message = messages[0]; +// // expect(message._id).to.exist; +// // +// // done(); +// // }); +// // }); +// // +// // it('should get unread message count of INBOX', function(done) { +// // messageSchema.getUnreadInboxCount(ownerId, function(err, count) { +// // expect(err).to.not.exist; +// // expect(count).to.equal(0); +// // +// // done(); +// // }); +// // }); +// // +// // it('should get user folder', function(done) { +// // messageSchema.getUserFolder(ownerId, 1, function(err, messages) { +// // expect(err).to.not.exist; +// // expect(messages).to.have.length(1); +// // +// // done(); +// // }); +// // }); +// }); diff --git a/test/models/ticket.js b/test/models/ticket.js index 4caf26dc4..a33a1e7ca 100644 --- a/test/models/ticket.js +++ b/test/models/ticket.js @@ -1,458 +1,498 @@ -var async = require('async'); -var expect = require('chai').expect; -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) { - // expect(mongoose).to.exist; - // - // dbHelper.clearCollections(mongoose, function(err) { - // expect(err).to.not.exist; - // - // done(); - // }); - //}); - - it('should create ticket', function(done) { - prioritySchema.findOne({default: true}).exec(function(err, p) { - expect(err).to.not.exist; - expect(p).to.be.a('object'); - - 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: [] - - }, 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(); - }); - }); - }); - - it('should set the ticket status to closed then to open', function(done) { - async.series([ - function(cb) { - ticketSchema.getTicketByUid(1000, function(err, ticket) { - expect(err).to.not.exist; - expect(ticket).to.be.a('object'); - - ticket.setStatus(m.Types.ObjectId(), 3, function(err, ticket) { - expect(ticket.status).to.equal(3); - expect(ticket.closedDate).to.exist; - - cb(); - }); - }); - }, - function(cb) { - ticketSchema.getTicketByUid(1000, function(err, ticket) { - expect(err).to.not.exist; - expect(ticket).to.be.a('object'); - - ticket.setStatus(m.Types.ObjectId(), 1, function(err, ticket) { - expect(ticket.status).to.equal(1); - expect(ticket.closedDate).to.not.exist; - - cb(); - }); - }); - } - ], function() { - done(); - }); - }); - - it('should set assignee to user', function(done){ - var userSchema = require('../../src/models/user'); - async.waterfall([ - function(cb) { - userSchema.getUserByUsername('trudesk', function(err, user) { - expect(err).to.not.exist; - expect(user).to.be.a('object'); - expect(user).to.have.property('_id'); - - cb(null, user._id); - }) - }, - function(userId, cb) { - ticketSchema.getTicketByUid(1000, function(err, ticket) { - ticket.setAssignee(userId, userId, function(err, ticket) { - expect(err).to.not.exist; - expect(ticket.assignee).to.equal(userId); - - cb(); - }); - }); - } - ], function() { - done(); - }); - }); - - it('should set ticket type', function(done) { - ticketSchema.getTicketByUid(1000, function(err, ticket) { - var type = m.Types.ObjectId(); - var ownerId = m.Types.ObjectId(); - ticket.setTicketType(ownerId, type, function(err, ticket) { - expect(err).to.not.exist; - expect(ticket.type).to.equal(type); - - done(); - }); - }); - }); - - it('should set ticket priority', function(done) { - ticketSchema.getTicketByUid(1000, function(err, ticket) { - var ownerId = m.Types.ObjectId(); - prioritySchema.getByMigrationNum(3, function(err, priority) { - expect(err).to.not.exist; - expect(priority).to.be.a('object'); - - ticket.setTicketPriority(ownerId, priority, function(err, ticket) { - expect(err).to.not.exist; - expect(ticket.priority.name).to.equal('Critical'); - - done(); - }); - }); - }); - }); - - it('should set ticket group', function(done) { - var grp = groupSchema({ - name: 'Test' - }); - grp.save(function(err, group) { - expect(err).to.not.exist; - expect(group).to.be.a('object'); - - ticketSchema.getTicketByUid(1000, function(err, ticket) { - var ownerId = m.Types.ObjectId(); - ticket.setTicketGroup(ownerId, group._id, function(err, ticket) { - expect(err).to.not.exist; - expect(ticket.group.name).to.equal('Test'); - - done(); - }); - }); - }); - }); - - it('should clear the ticket assignee', function(done) { - ticketSchema.getTicketByUid(1000, function(err, ticket) { - expect(err).to.not.exist; - expect(ticket).to.be.a('object'); - - ticket.clearAssignee(m.Types.ObjectId(), function(err, ticket) { - expect(err).to.not.exist; - expect(ticket.assignee).to.not.exist; - - done(); - }); - }); - }); - - it('should add Comment and Save', function(done) { - ticketSchema.getTicketByUid(1000, function(err, ticket) { - expect(err).to.not.exist; - expect(ticket).to.be.a('object'); - - var comment = { - owner: m.Types.ObjectId(), - date: new Date(), - comment: 'This is a comment' - }; - - ticket.comments.push(comment); - - //Fake populate required Fields - ticket.group = m.Types.ObjectId(); - ticket.owner = m.Types.ObjectId(); - ticket.type = m.Types.ObjectId(); - - ticket.save(function(err, ticket) { - expect(err).to.not.exist; - expect(ticket.comments).to.have.length(1); - - done(); - }); - }); - }); - - it('should update comment', function(done) { - ticketSchema.getTicketByUid(1000, function(err, ticket) { - expect(err).to.not.exist; - expect(ticket).to.be.a('object'); - - var commentId = ticket.comments[0]._id; - expect(commentId).to.exist; - - ticket.updateComment(m.Types.ObjectId(), commentId, 'This is the new comment text', function(err, ticket) { - expect(err).to.not.exist; - expect(ticket.comments[0].comment).to.equal('This is the new comment text'); - - done(); - }); - }); - }); - - it('should remove comment', function(done) { - ticketSchema.getTicketByUid(1000, function(err, ticket) { - expect(err).to.not.exist; - expect(ticket).to.be.a('object'); - - var commentId = ticket.comments[0]._id; - expect(commentId).to.exist; - - ticket.removeComment(m.Types.ObjectId(), commentId, function(err, ticket) { - expect(err).to.not.exist; - expect(ticket.comments).to.have.length(0); - - done(); - }); - }); - }); - - it('should add Note and Save', function(done) { - ticketSchema.getTicketByUid(1000, function(err, ticket) { - expect(err).to.not.exist; - expect(ticket).to.be.a('object'); - - var note = { - owner: m.Types.ObjectId(), - date: new Date(), - note: 'This is a note' - }; - - ticket.notes.push(note); - - //Fake populate required Fields - ticket.group = m.Types.ObjectId(); - ticket.owner = m.Types.ObjectId(); - ticket.type = m.Types.ObjectId(); - - ticket.save(function(err, ticket) { - expect(err).to.not.exist; - expect(ticket.notes).to.have.length(1); - - done(); - }); - }); - }); - - it('should update note', function(done) { - ticketSchema.getTicketByUid(1000, function(err, ticket) { - expect(err).to.not.exist; - expect(ticket).to.be.a('object'); - - var noteId = ticket.notes[0]._id; - expect(noteId).to.exist; - - ticket.updateNote(m.Types.ObjectId(), noteId, 'This is the new note text', function(err, ticket) { - expect(err).to.not.exist; - expect(ticket.notes[0].note).to.equal('This is the new note text'); - - done(); - }); - }); - }); - - it('should remove note', function(done) { - ticketSchema.getTicketByUid(1000, function(err, ticket) { - expect(err).to.not.exist; - expect(ticket).to.be.a('object'); - - var noteId = ticket.notes[0]._id; - expect(noteId).to.exist; - - ticket.removeNote(m.Types.ObjectId(), noteId, function(err, ticket) { - expect(err).to.not.exist; - expect(ticket.notes).to.have.length(0); - - done(); - }); - }); - }); - - it('should set ticket issue', function(done) { - ticketSchema.getTicketByUid(1000, function(err, ticket) { - expect(err).to.not.exist; - expect(ticket).to.be.a('object'); - - var ownerId = m.Types.ObjectId(); - ticket.setIssue(ownerId, 'This is the new issue text', function(err, ticket) { - expect(err).to.not.exist; - expect(ticket.issue).to.equal('This is the new issue text'); - - done(); - }); - }); - }); - - it('should get all tickets', function(done) { - ticketSchema.getForCache(function(err, tickets) { - expect(err).to.not.exist; - expect(tickets).to.have.length(1); - - done(); - }); - }); - - it('should get all tickets for group', function(done) { - ticketSchema.getTickets([m.Types.ObjectId()], function(err, tickets) { - expect(err).to.not.exist; - expect(tickets).to.have.length(0); - - done(); - }); - }); - - it('should error getting tickets for group', function(done) { - async.parallel([ - function(cb) { - ticketSchema.getTickets(undefined, function(err, tickets) { - expect(err).to.exist; - - cb(); - }); - }, - function(cb) { - ticketSchema.getTickets(1, function(err, tickets) { - expect(err).to.exist; - - cb(); - }); - } - ], function() { - done(); - }); - }); - - it('should get all tickets for group with limit', function(done) { - //todo Rewrite this with GetTicketsWithObject Test - return done(); - }); - - it('should get all tickets for group by status', function(done) { - async.parallel([ - function(cb) { - ticketSchema.getTicketsByStatus([m.Types.ObjectId()], 0, function(err, tickets) { - expect(err).to.not.exist; - expect(tickets).to.have.length(0); - - cb(); - }); - }, - function(cb) { - ticketSchema.getTicketsByStatus(undefined, 0, function(err, tickets) { - expect(err).to.exist; - - cb(); - }); - }, - function(cb) { - ticketSchema.getTicketsByStatus(m.Types.ObjectId(), 0, function(err, tickets) { - expect(err).to.exist; - - cb(); - }); - } - ], function() { - done(); - }); - }); - - it('should get all tickets by status', function(done) { - ticketSchema.getAllByStatus(0, function(err, tickets) { - expect(err).to.not.exist; - - expect(tickets).to.have.length(1); - - done(); - }); - }); - - it('should get ticket by _id', function(done) { - async.parallel([ - function(cb) { - ticketSchema.getTicketById(m.Types.ObjectId(), function(err, ticket) { - expect(err).to.not.exist; - - cb(); - }); - }, - function(cb) { - ticketSchema.getTicketById(undefined, function(err, ticket) { - expect(err).to.exist; - - cb(); - }); - } - ], function() { - done(); - }); - }); - - it('should get tickets by assignee', function(done) { - async.parallel([ - function(cb) { - ticketSchema.getAssigned(m.Types.ObjectId(), function(err, tickets) { - expect(err).to.not.exist; - - cb(); - }); - }, - function(cb) { - ticketSchema.getAssigned(undefined, function(err, tickets) { - expect(err).to.exist; - - cb(); - }); - } - ], function() { - done(); - }); - }); - - //Should be last - it('should soft delete ticket with UID 1000', function(done) { - ticketSchema.getTicketByUid(1000, function(err, ticket) { - expect(err).to.not.exist; - expect(ticket).to.be.a('object'); - - ticketSchema.softDelete(ticket._id, function(err, ticket) { - expect(err).to.not.exist; - expect(ticket).to.be.a('object'); - - ticket.save(function(err, t) { - expect(err).to.not.exist; - expect(t).to.be.a('object'); - - expect(t.deleted).to.be.false; - - done(); - }); - }); - }); - }); -}); +/* eslint-disable no-unused-expressions */ +var async = require('async') +var expect = require('chai').expect +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) { + // expect(mongoose).to.exist; + // + // dbHelper.clearCollections(mongoose, function(err) { + // expect(err).to.not.exist; + // + // done(); + // }); + // }); + + it('should create ticket', function (done) { + prioritySchema.findOne({ default: true }).exec(function (err, p) { + expect(err).to.not.exist + expect(p).to.be.a('object') + + 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: [] + }, + 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() + } + ) + }) + }) + + it('should set the ticket status to closed then to open', function (done) { + async.series( + [ + function (cb) { + ticketSchema.getTicketByUid(1000, function (err, ticket) { + expect(err).to.not.exist + expect(ticket).to.be.a('object') + + ticket.setStatus(m.Types.ObjectId(), 3, function (err, ticket) { + expect(err).to.not.exist + expect(ticket.status).to.equal(3) + expect(ticket.closedDate).to.exist + + cb() + }) + }) + }, + function (cb) { + ticketSchema.getTicketByUid(1000, function (err, ticket) { + expect(err).to.not.exist + expect(ticket).to.be.a('object') + + ticket.setStatus(m.Types.ObjectId(), 1, function (err, ticket) { + expect(err).to.not.exist + expect(ticket.status).to.equal(1) + expect(ticket.closedDate).to.not.exist + + cb() + }) + }) + } + ], + function () { + done() + } + ) + }) + + it('should set assignee to user', function (done) { + var userSchema = require('../../src/models/user') + async.waterfall( + [ + function (cb) { + userSchema.getUserByUsername('trudesk', function (err, user) { + expect(err).to.not.exist + expect(user).to.be.a('object') + expect(user).to.have.property('_id') + + cb(null, user._id) + }) + }, + function (userId, cb) { + ticketSchema.getTicketByUid(1000, function (err, ticket) { + expect(err).to.not.exist + ticket.setAssignee(userId, userId, function (err, ticket) { + expect(err).to.not.exist + expect(ticket.assignee).to.equal(userId) + + cb() + }) + }) + } + ], + function () { + done() + } + ) + }) + + it('should set ticket type', function (done) { + ticketSchema.getTicketByUid(1000, function (err, ticket) { + expect(err).to.not.exist + var type = m.Types.ObjectId() + var ownerId = m.Types.ObjectId() + ticket.setTicketType(ownerId, type, function (err, ticket) { + expect(err).to.not.exist + expect(ticket.type).to.equal(type) + + done() + }) + }) + }) + + it('should set ticket priority', function (done) { + ticketSchema.getTicketByUid(1000, function (err, ticket) { + expect(err).to.not.exist + var ownerId = m.Types.ObjectId() + prioritySchema.getByMigrationNum(3, function (err, priority) { + expect(err).to.not.exist + expect(priority).to.be.a('object') + + ticket.setTicketPriority(ownerId, priority, function (err, ticket) { + expect(err).to.not.exist + expect(ticket.priority.name).to.equal('Critical') + + done() + }) + }) + }) + }) + + it('should set ticket group', function (done) { + var grp = groupSchema({ + name: 'Test' + }) + grp.save(function (err, group) { + expect(err).to.not.exist + expect(group).to.be.a('object') + + ticketSchema.getTicketByUid(1000, function (err, ticket) { + expect(err).to.not.exist + var ownerId = m.Types.ObjectId() + ticket.setTicketGroup(ownerId, group._id, function (err, ticket) { + expect(err).to.not.exist + expect(ticket.group.name).to.equal('Test') + + done() + }) + }) + }) + }) + + it('should clear the ticket assignee', function (done) { + ticketSchema.getTicketByUid(1000, function (err, ticket) { + expect(err).to.not.exist + expect(ticket).to.be.a('object') + + ticket.clearAssignee(m.Types.ObjectId(), function (err, ticket) { + expect(err).to.not.exist + expect(ticket.assignee).to.not.exist + + done() + }) + }) + }) + + it('should add Comment and Save', function (done) { + ticketSchema.getTicketByUid(1000, function (err, ticket) { + expect(err).to.not.exist + expect(ticket).to.be.a('object') + + var comment = { + owner: m.Types.ObjectId(), + date: new Date(), + comment: 'This is a comment' + } + + ticket.comments.push(comment) + + // Fake populate required Fields + ticket.group = m.Types.ObjectId() + ticket.owner = m.Types.ObjectId() + ticket.type = m.Types.ObjectId() + + ticket.save(function (err, ticket) { + expect(err).to.not.exist + expect(ticket.comments).to.have.length(1) + + done() + }) + }) + }) + + it('should update comment', function (done) { + ticketSchema.getTicketByUid(1000, function (err, ticket) { + expect(err).to.not.exist + expect(ticket).to.be.a('object') + + var commentId = ticket.comments[0]._id + expect(commentId).to.exist + + ticket.updateComment(m.Types.ObjectId(), commentId, 'This is the new comment text', function (err, ticket) { + expect(err).to.not.exist + expect(ticket.comments[0].comment).to.equal('This is the new comment text') + + done() + }) + }) + }) + + it('should remove comment', function (done) { + ticketSchema.getTicketByUid(1000, function (err, ticket) { + expect(err).to.not.exist + expect(ticket).to.be.a('object') + + var commentId = ticket.comments[0]._id + expect(commentId).to.exist + + ticket.removeComment(m.Types.ObjectId(), commentId, function (err, ticket) { + expect(err).to.not.exist + expect(ticket.comments).to.have.length(0) + + done() + }) + }) + }) + + it('should add Note and Save', function (done) { + ticketSchema.getTicketByUid(1000, function (err, ticket) { + expect(err).to.not.exist + expect(ticket).to.be.a('object') + + var note = { + owner: m.Types.ObjectId(), + date: new Date(), + note: 'This is a note' + } + + ticket.notes.push(note) + + // Fake populate required Fields + ticket.group = m.Types.ObjectId() + ticket.owner = m.Types.ObjectId() + ticket.type = m.Types.ObjectId() + + ticket.save(function (err, ticket) { + expect(err).to.not.exist + expect(ticket.notes).to.have.length(1) + + done() + }) + }) + }) + + it('should update note', function (done) { + ticketSchema.getTicketByUid(1000, function (err, ticket) { + expect(err).to.not.exist + expect(ticket).to.be.a('object') + + var noteId = ticket.notes[0]._id + expect(noteId).to.exist + + ticket.updateNote(m.Types.ObjectId(), noteId, 'This is the new note text', function (err, ticket) { + expect(err).to.not.exist + expect(ticket.notes[0].note).to.equal('This is the new note text') + + done() + }) + }) + }) + + it('should remove note', function (done) { + ticketSchema.getTicketByUid(1000, function (err, ticket) { + expect(err).to.not.exist + expect(ticket).to.be.a('object') + + var noteId = ticket.notes[0]._id + expect(noteId).to.exist + + ticket.removeNote(m.Types.ObjectId(), noteId, function (err, ticket) { + expect(err).to.not.exist + expect(ticket.notes).to.have.length(0) + + done() + }) + }) + }) + + it('should set ticket issue', function (done) { + ticketSchema.getTicketByUid(1000, function (err, ticket) { + expect(err).to.not.exist + expect(ticket).to.be.a('object') + + var ownerId = m.Types.ObjectId() + ticket.setIssue(ownerId, 'This is the new issue text', function (err, ticket) { + expect(err).to.not.exist + expect(ticket.issue).to.equal('This is the new issue text') + + done() + }) + }) + }) + + it('should get all tickets', function (done) { + ticketSchema.getForCache(function (err, tickets) { + expect(err).to.not.exist + expect(tickets).to.have.length(1) + + done() + }) + }) + + it('should get all tickets for group', function (done) { + ticketSchema.getTickets([m.Types.ObjectId()], function (err, tickets) { + expect(err).to.not.exist + expect(tickets).to.have.length(0) + + done() + }) + }) + + it('should error getting tickets for group', function (done) { + async.parallel( + [ + function (cb) { + ticketSchema.getTickets(undefined, function (err, tickets) { + expect(err).to.exist + + cb() + }) + }, + function (cb) { + ticketSchema.getTickets(1, function (err, tickets) { + expect(err).to.exist + + cb() + }) + } + ], + function () { + done() + } + ) + }) + + it('should get all tickets for group with limit', function (done) { + // todo Rewrite this with GetTicketsWithObject Test + return done() + }) + + it('should get all tickets for group by status', function (done) { + async.parallel( + [ + function (cb) { + ticketSchema.getTicketsByStatus([m.Types.ObjectId()], 0, function (err, tickets) { + expect(err).to.not.exist + expect(tickets).to.have.length(0) + + cb() + }) + }, + function (cb) { + ticketSchema.getTicketsByStatus(undefined, 0, function (err, tickets) { + expect(err).to.exist + + cb() + }) + }, + function (cb) { + ticketSchema.getTicketsByStatus(m.Types.ObjectId(), 0, function (err, tickets) { + expect(err).to.exist + + cb() + }) + } + ], + function () { + done() + } + ) + }) + + it('should get all tickets by status', function (done) { + ticketSchema.getAllByStatus(0, function (err, tickets) { + expect(err).to.not.exist + + expect(tickets).to.have.length(1) + + done() + }) + }) + + it('should get ticket by _id', function (done) { + async.parallel( + [ + function (cb) { + ticketSchema.getTicketById(m.Types.ObjectId(), function (err, ticket) { + expect(err).to.not.exist + + cb() + }) + }, + function (cb) { + ticketSchema.getTicketById(undefined, function (err, ticket) { + expect(err).to.exist + + cb() + }) + } + ], + function () { + done() + } + ) + }) + + it('should get tickets by assignee', function (done) { + async.parallel( + [ + function (cb) { + ticketSchema.getAssigned(m.Types.ObjectId(), function (err, tickets) { + expect(err).to.not.exist + + cb() + }) + }, + function (cb) { + ticketSchema.getAssigned(undefined, function (err, tickets) { + expect(err).to.exist + + cb() + }) + } + ], + function () { + done() + } + ) + }) + + // Should be last + it('should soft delete ticket with UID 1000', function (done) { + ticketSchema.getTicketByUid(1000, function (err, ticket) { + expect(err).to.not.exist + expect(ticket).to.be.a('object') + + ticketSchema.softDelete(ticket._id, function (err, ticket) { + expect(err).to.not.exist + expect(ticket).to.be.a('object') + + ticket.save(function (err, t) { + expect(err).to.not.exist + expect(t).to.be.a('object') + + expect(t.deleted).to.be.false + + done() + }) + }) + }) + }) +}) diff --git a/test/models/tickettype.js b/test/models/tickettype.js index 7b35dbb1e..14f590c39 100644 --- a/test/models/tickettype.js +++ b/test/models/tickettype.js @@ -1,40 +1,39 @@ -var async = require('async'); -var expect = require('chai').expect; -var should = require('chai').should(); -var m = require('mongoose'); -var ticketTypeSchema = require('../../src/models/tickettype'); - -describe('ticketType.js', function() { - - it('should create a ticket type', function(done) { - ticketTypeSchema.create({ - name: 'Test Ticket Type' - }, function(err, tt) { - expect(err).to.not.exist; - expect(tt).to.be.a('object'); - expect(tt._doc).to.include.keys('_id', 'name'); - - done(); - }); - }); - - it('should get all ticket types.', function(done) { - ticketTypeSchema.getTypes(function(err, types) { - expect(err).to.not.exist; - expect(types).to.be.a('array'); - expect(types).to.have.length(3); //Has default ticket types already - - done(); - }); - }); - - it('should get ticket type via name', function(done) { - ticketTypeSchema.getTypeByName('Test Ticket Type', function(err, type) { - expect(err).to.not.exist; - expect(type).to.be.a('object'); - - done(); - }); - }); - -}); +/* eslint-disable no-unused-expressions */ +var expect = require('chai').expect +var ticketTypeSchema = require('../../src/models/tickettype') + +describe('ticketType.js', function () { + it('should create a ticket type', function (done) { + ticketTypeSchema.create( + { + name: 'Test Ticket Type' + }, + function (err, tt) { + expect(err).to.not.exist + expect(tt).to.be.a('object') + expect(tt._doc).to.include.keys('_id', 'name') + + done() + } + ) + }) + + it('should get all ticket types.', function (done) { + ticketTypeSchema.getTypes(function (err, types) { + expect(err).to.not.exist + expect(types).to.be.a('array') + expect(types).to.have.length(3) // Has default ticket types already + + done() + }) + }) + + it('should get ticket type via name', function (done) { + ticketTypeSchema.getTypeByName('Test Ticket Type', function (err, type) { + expect(err).to.not.exist + expect(type).to.be.a('object') + + done() + }) + }) +}) diff --git a/test/source/hbsHelpers.js b/test/source/hbsHelpers.js index 9d8916a31..2f163dd66 100644 --- a/test/source/hbsHelpers.js +++ b/test/source/hbsHelpers.js @@ -1,25 +1,21 @@ -var async = require('async'); -var expect = require('chai').expect; -var should = require('chai').should(); +var expect = require('chai').expect -var hbsHelpers = require('../../src/helpers/hbs/helpers'); +var hbsHelpers = require('../../src/helpers/hbs/helpers') -describe('Handlebars Helpers', function() { +describe('Handlebars Helpers', function () { + it('should return status name', function (done) { + var strNew = hbsHelpers.helpers.statusName(0) + var strOpen = hbsHelpers.helpers.statusName(1) + var strPending = hbsHelpers.helpers.statusName(2) + var strClosed = hbsHelpers.helpers.statusName(3) + var strDefault = hbsHelpers.helpers.statusName() - it('should return status name', function(done) { - var strNew = hbsHelpers.helpers.statusName(0); - var strOpen = hbsHelpers.helpers.statusName(1); - var strPending = hbsHelpers.helpers.statusName(2); - var strClosed = hbsHelpers.helpers.statusName(3); - var strDefault = hbsHelpers.helpers.statusName(); + expect(strNew).to.equal('New') + expect(strOpen).to.equal('Open') + expect(strPending).to.equal('Pending') + expect(strClosed).to.equal('Closed') + expect(strDefault).to.equal('New') - expect(strNew).to.equal('New'); - expect(strOpen).to.equal('Open'); - expect(strPending).to.equal('Pending'); - expect(strClosed).to.equal('Closed'); - expect(strDefault).to.equal('New'); - - done(); - }); - -}); + done() + }) +}) diff --git a/test/source/installServer.js b/test/source/installServer.js index f355bc9df..961605324 100644 --- a/test/source/installServer.js +++ b/test/source/installServer.js @@ -1,16 +1,11 @@ -var async = require('async'); -var expect = require('chai').expect; -var should = require('chai').should(); +var is = require('../../src/webserver') -var is = require('../../src/webserver'); +describe('installServer.js', function () { + it('should start install server', function (done) { + if (is.server.listening) is.server.close() -describe('installServer.js', function() { - - it('should start install server', function(done) { - if (is.server.listening) is.server.close(); - - is.installServer(function() { - done(); - }); - }); -}); + is.installServer(function () { + done() + }) + }) +}) diff --git a/test/source/mailer.js b/test/source/mailer.js index 2eb7f664d..fe37a0507 100644 --- a/test/source/mailer.js +++ b/test/source/mailer.js @@ -1,2 +1 @@ - -var mailer = require('../../src/mailer'); +// var mailer = require('../../src/mailer'); diff --git a/test/source/permissions.js b/test/source/permissions.js index d7d8e8691..3a13d9368 100644 --- a/test/source/permissions.js +++ b/test/source/permissions.js @@ -1,40 +1,39 @@ -var async = require('async'); -var expect = require('chai').expect; -var should = require('chai').should(); +/* eslint-disable no-unused-expressions */ +var expect = require('chai').expect -var permissions = require('../../src/permissions'); +var permissions = require('../../src/permissions') -describe('premissions.js', function() { - it('should return false', function(done) { - var result = permissions.canThis(undefined, 'action:action'); - var result2 = permissions.canThis('fakerole', 'action:action'); - expect(result).to.be.false; - expect(result2).to.be.false; +describe('premissions.js', function () { + it('should return false', function (done) { + var result = permissions.canThis(undefined, 'action:action') + var result2 = permissions.canThis('fakerole', 'action:action') + expect(result).to.be.false + expect(result2).to.be.false - done(); - }); + done() + }) - it('should allow all actions', function(done) { - var result = permissions.canThis('support', 'comment:create'); + it('should allow all actions', function (done) { + var result = permissions.canThis('support', 'comment:create') - expect(result).to.be.true; + expect(result).to.be.true - done(); - }); + done() + }) - it('show allow note creation', function(done) { - var result = permissions.canThis('support', 'notes:create'); + it('show allow note creation', function (done) { + var result = permissions.canThis('support', 'notes:create') - expect(result).to.be.true; + expect(result).to.be.true - done(); - }); + done() + }) - it('should get roles with action', function(done) { - var results = permissions.getRoles('ticket:create'); + it('should get roles with action', function (done) { + var results = permissions.getRoles('ticket:create') - expect(results).to.have.length(4); + expect(results).to.have.length(4) - done(); - }); -}); + done() + }) +}) diff --git a/webpack.config.js b/webpack.config.js index 6b111b744..40504ddb9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -32,10 +32,10 @@ module.exports = { resolve: { modules: [path.resolve(__dirname, 'src/public/js/')], alias: { - //server side + // server side roles: path.resolve(__dirname, 'src/permissions/roles'), - //client side + // client side jquery: 'vendor/jquery/jquery', jquery_scrollTo: 'vendor/jquery/jquery.scrollTo.min', jscookie: 'vendor/jscookie/js.cookie', @@ -95,7 +95,7 @@ module.exports = { } }, externals: { - //These are bunbled already + // These are bunbled already jsdom: 'jsdom', canvas: 'canvas' }, diff --git a/yarn.lock b/yarn.lock index 780f480c1..09860d2a8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4260,6 +4260,13 @@ eslint-config-angular@0.5.0: resolved "https://registry.yarnpkg.com/eslint-config-angular/-/eslint-config-angular-0.5.0.tgz#e0aae0132e39e7467df3f7547fec81a44d3685c4" integrity sha1-4KrgEy4550Z98/dUf+yBpE02hcQ= +eslint-config-prettier@3.6.0: + version "3.6.0" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-3.6.0.tgz#8ca3ffac4bd6eeef623a0651f9d754900e3ec217" + integrity sha512-ixJ4U3uTLXwJts4rmSVW/lMXjlGwCijhBJHk8iVqKKSifeI0qgFEfWl8L63isfc8Od7EiBALF6BX3jKLluf/jQ== + dependencies: + get-stdin "^6.0.0" + eslint-config-standard-jsx@6.0.2: version "6.0.2" resolved "https://registry.yarnpkg.com/eslint-config-standard-jsx/-/eslint-config-standard-jsx-6.0.2.tgz#90c9aa16ac2c4f8970c13fc7efc608bacd02da70" @@ -4339,7 +4346,14 @@ eslint-plugin-node@~7.0.1: resolve "^1.8.1" semver "^5.5.0" -eslint-plugin-promise@~4.0.0: +eslint-plugin-prettier@3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.0.1.tgz#19d521e3981f69dd6d14f64aec8c6a6ac6eb0b0d" + integrity sha512-/PMttrarPAY78PLvV3xfWibMOdMDl57hmlQ2XqFeA37wd+CJ7WSxV7txqjVPHi/AAFKd2lX0ZqfsOc/i5yFCSQ== + dependencies: + prettier-linter-helpers "^1.0.0" + +eslint-plugin-promise@4.0.1, eslint-plugin-promise@~4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-4.0.1.tgz#2d074b653f35a23d1ba89d8e976a985117d1c6a2" integrity sha512-Si16O0+Hqz1gDHsys6RtFRrW7cCTB6P7p3OJmKp3Y3dxpQE2qwOA7d3xnV+0mBmrPoi0RBnxlCKvqu70te6wjg== @@ -4840,6 +4854,11 @@ fast-deep-equal@^2.0.1: resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49" integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk= +fast-diff@^1.1.2: + version "1.2.0" + resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03" + integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w== + fast-glob@^2.2.6: version "2.2.6" resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-2.2.6.tgz#a5d5b697ec8deda468d85a74035290a025a95295" @@ -9833,6 +9852,13 @@ prepend-http@^1.0.1: resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc" integrity sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw= +prettier-linter-helpers@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b" + integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w== + dependencies: + fast-diff "^1.1.2" + prettier-standard@9.1.1: version "9.1.1" resolved "https://registry.yarnpkg.com/prettier-standard/-/prettier-standard-9.1.1.tgz#31926843d6d2b428fbecb3aceea59e872947d016"