- Created all Tests with Mocha: User + Todo tables

This commit is contained in:
Paolo Arena
2019-02-07 00:52:48 +01:00
parent 779bd1cb63
commit 87378fe732
10 changed files with 309 additions and 150 deletions

View File

@@ -6,21 +6,26 @@ const { User } = require('./../../models/user');
var bcrypt = require('bcrypt');
const tools = require('../../tools/general');
let myuserIdOne = '';
const userOneId = new ObjectID();
const userTwoId = new ObjectID();
const userThreeId = new ObjectID();
// const userThreeId = new ObjectID();
// let mypwdchiaro = 'mypassword@1A';
// let mypwdcrypt = bcrypt.hash(mypwdchiaro, bcrypt.genSaltSync(12))
// .then((hashedPassword) => {
// console.log('pwd=',hashedPassword);
// });
// String(mypwdcrypt)
let mypwdchiaro = 'mypassword@1A';
let mypwdcrypted = '$2b$12$mteST.isuWO0SNsfeZ0aCe.Dz3qwPh5SU8t9rc5SaPTkb3j0ywGv6'
const users = [ {
_id: userTwoId,
const users = [{
_id: userOneId,
keyappid: process.env.KEY_APP_ID,
lang: 'it',
idapp: '1',
@@ -33,7 +38,7 @@ const users = [ {
}]
},
{
_id: userThreeId,
_id: userTwoId,
keyappid: process.env.KEY_APP_ID,
lang: 'it',
idapp: '1',
@@ -45,7 +50,7 @@ const users = [ {
token: jwt.sign({ _id: userTwoId, access: 'auth' }, process.env.SIGNCODE).toString()
}]
}, {
keyappid: process.env.KEY_APP_ID,
keyappid: process.env.KEY_APP_ID, // RECORD CHE VERRA' UTILIZZATO PER UNA NUOVA REGISTRAZIONE
lang: 'it',
idapp: '1',
email: 'pao.loarena77@gmail.com',
@@ -60,35 +65,106 @@ const userjson = JSON.stringify(users[0]);
const todos = [{
_id: new ObjectID(),
text: 'First test todo',
_creator: userOneId
category: "personal",
completed: false,
completed_at: 0,
created_at: 6,
descr: "Primo Task Esempio",
enableExpiring: false,
expiring_at: 16,
id_next: "10000000",
id_prev: "0",
modified: false,
modify_at: 6,
pos: 1,
priority: 1,
progress: 0,
userId: users[0]._id
}, {
_id: new ObjectID(),
text: 'Second test todo',
completed: true,
completedAt: 333,
_creator: userTwoId
category: "personal",
completed: false,
completed_at: 0,
created_at: 6,
descr: "Secondo Task Esempio",
enableExpiring: false,
expiring_at: 16,
id_next: "10000000",
id_prev: "1",
modified: false,
modify_at: 6,
pos: 2,
priority: 1,
progress: 0,
userId: users[0]._id
}, {
_id: new ObjectID(),
category: "personal",
completed: false,
completed_at: 0,
created_at: 6,
descr: "Terzo Task Esempio",
enableExpiring: false,
expiring_at: 16,
id_next: "10000000",
id_prev: "1",
modified: false,
modify_at: 6,
pos: 3,
priority: 1,
progress: 0,
userId: users[1]._id
}, { // RECORD CHE VERRA' UTILIZZATO PER AGGIUNGERE UN NUOVO TASK
_id: new ObjectID(),
category: "personal",
completed: false,
completed_at: 0,
created_at: 6,
descr: "Nuovo Quarto Task Esempio da Inserire",
enableExpiring: false,
expiring_at: 16,
id_next: "10000000",
id_prev: "2",
modified: false,
modify_at: 6,
pos: 4,
priority: 1,
progress: 0,
userId: users[0]._id
}];
const populateTodos = (done) => {
const lista = [ users[0]._id, users[1]._id, users[2]._id];
Todo.deleteMany({ userId: {$in: lista } })
Todo.deleteMany({})
.then(() => {
return Todo.insertMany(todos);
}).then(() => done())
var TodoOne = new Todo(todos[0]).save();
var TodoTwo = new Todo(todos[1]).save();
return Promise.all([TodoOne, TodoTwo])
}).then(() => {
done()
// tools.mylogshow('todos[0]', todos[0]._id);
// tools.mylogshow('todos[1]', todos[1]._id);
});
};
const populateUsers = (done) => {
const lista = [ users[0].username, users[1].username, users[2].username];
// const lista = [ "aa"]
User.deleteMany({ username: {$in: lista } })
User.deleteMany({})
.then(() => {
// console.log('users[0]', users[0])
var userOne = new User(users[0]).save();
var userTwo = new User(users[1]).save();
return Promise.all([userOne, userTwo])
}).then(() => done());
};
module.exports = { todos, populateTodos, users, populateUsers, userjson, mypwdcrypted };
module.exports = { todos, populateTodos, users, populateUsers, userjson, mypwdcrypted, mypwdchiaro };