Skip to content

Commit

Permalink
Mongoose@6 (#509)
Browse files Browse the repository at this point in the history
* migrate for mongoose@6
* update also mongomock
* update inmemory initialization
* fix bug that makes now visible after mongoose update

if Result:dut object was same time with duts -
object result was generated with extra dut.

* create user explicitly for each user tests
replace obsoleted nModified with modifiedCount property
* fix loan test
* CI store logs even test fails
* replace deprecated uuid usage
  • Loading branch information
jupe authored May 7, 2022
1 parent c5482eb commit 5696b18
Show file tree
Hide file tree
Showing 18 changed files with 12,282 additions and 292 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ jobs:
- name: api tests
run: |
MOCHA_FILE=junit/apitests.xml grunt apitests --silent
- name: cluster tests
run: |
MOCHA_FILE=junit/clustertests.xml grunt clustertests --silent
- name: lint
run: |
npm run lint
- uses: actions/[email protected]
if: success() || failure() # run this step even if previous step failed
with:
# Artifact name
name: logs-${{ matrix.node-version }}
Expand Down
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const gruntConfig = {
},
simplemocha: {
options: {
reporter: 'json',
reporter: 'spec',
timeout: 120000,
ignoreLeaks: false
},
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/clusters.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// 3rd party modules
const Promise = require('bluebird');
const _ = require('lodash');
const uuid = require('uuid/v1');
const uuid = require('uuid').v1;

// own modules
const cluster = require('cluster');
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require('colors');
const Promise = require('bluebird');
const mongoose = require('mongoose');
const JunitXmlParser = require('junit-xml-parser').parser;
const uuid = require('uuid/v1');
const uuid = require('uuid').v1;
const logger = require('../tools/logger');

// Setup
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class UsersController extends DefaultController {
doc.$unset[`settings.${namespace}`] = 1;
return req.user.update(doc)
.then((resp) => {
if (resp.nModified === 1) {
if (resp.modifiedCount === 1) {
res.json({});
} else {
res.status(404).json({error: resp.message});
Expand Down Expand Up @@ -63,7 +63,7 @@ class UsersController extends DefaultController {
doc[`settings.${namespace}`] = req.body;
return req.user.update(doc)
.then((resp) => {
if (!resp.nModified) {
if (!resp.modifiedCount) {
res.status(208);
}
res.json(req.body);
Expand Down
8 changes: 3 additions & 5 deletions app/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ let tearingDown = false;

const initialize = async function () {
if (dbUrl === 'inmemory') {
mongoServer = new MongoMemoryServer();
dbUrl = await mongoServer.getUri();
mongoServer = await MongoMemoryServer.create();
dbUrl = mongoServer.getUri();
logger.info(`use inmemory db: ${dbUrl}`);
config.set('db', dbUrl);
}
Expand All @@ -28,12 +28,10 @@ const connect = async function () {
logger: logger.info.bind(logger),
promiseLibrary: Promise,
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true
useUnifiedTopology: true
};
const overwritable = {
appname: 'opentmi',
validateOptions: true,
loggerLevel: 'info'
};
const options = _.merge(overwritable, dbOptions, must);
Expand Down
2 changes: 1 addition & 1 deletion app/models/apikeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
const mongoose = require('mongoose');
const QueryPlugin = require('mongoose-query');
const uuidv4 = require('uuid/v4');
const uuidv4 = require('uuid').v4;

/* Implementation */
const {Schema} = mongoose;
Expand Down
2 changes: 1 addition & 1 deletion app/models/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const path = require('path');

// Third party modules
const _ = require('lodash');
const uuidv4 = require('uuid/v4');
const uuidv4 = require('uuid').v4;
const mongoose = require('mongoose');
const QueryPlugin = require('mongoose-query');

Expand Down
2 changes: 1 addition & 1 deletion app/models/plugins/resource-allocator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Validator = require('jsonschema').Validator;
const async = require('async');
const _ = require('lodash');
const uuid = require('uuid');
const uuid = require('uuid').v1;
const logger = require('winston');

/**
Expand Down
4 changes: 4 additions & 0 deletions app/models/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ ResultSchema
if (!this.exec.duts) {
this.exec.duts = [];
}
if (obj.count === this.exec.duts.length) {
// expect that duts array holds same data than what dut object contains
return;
}
this.exec.duts.push(obj);
});

Expand Down
1 change: 0 additions & 1 deletion app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ UserSchema.methods.saltPassword = function saltPassword(password) {
UserSchema.methods.isAdmin = function isAdmin() {
return this
.populate('groups')
.execPopulate()
.then((populatedUser) => {
const admins = populatedUser.groups.find(g => g.name === 'admins');
return !!admins;
Expand Down
1 change: 0 additions & 1 deletion app/routes/middlewares/authorization.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ function createJWT(user) {
logger.info(`Auth middleware: creating JWT token (exp: ${expDays} days)`);
return user
.populate('groups')
.execPopulate()
.then((populatedUser) => {
const payload = {
_id: populatedUser._id,
Expand Down
Loading

0 comments on commit 5696b18

Please sign in to comment.