Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.

Commit

Permalink
Fix tests with new sequelizejs updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Omar Massad committed Jun 15, 2017
1 parent 05e6dbc commit 9477303
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 32 deletions.
2 changes: 1 addition & 1 deletion modules/articles/server/models/articles.server.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ module.exports = function(sequelize, DataTypes) {
}
});
return Article;
};
};
3 changes: 1 addition & 2 deletions modules/articles/tests/server/article.server.model.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ describe('Article Model Unit Tests:', function() {
user.salt = user.makeSalt();
user.hashedPassword = user.encryptPassword('[email protected]$Aw3$0m3', user.salt);


user.save().then(function(user) {
article = Article.build({
title: 'Article Title',
Expand Down Expand Up @@ -87,4 +86,4 @@ describe('Article Model Unit Tests:', function() {
}).catch(function(err) {});
});

});
});
6 changes: 1 addition & 5 deletions modules/articles/tests/server/article.server.routes.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ describe('Article CRUD tests', function() {
// Get articles list
var articles = articlesGetRes.body;

// Set assertions
console.log('articles[0]', articles[0]);
console.log('userId', userId);

//(articles[0].userId).should.equal(userId);
(articles[0].title).should.match('Article Title');

Expand Down Expand Up @@ -350,4 +346,4 @@ describe('Article CRUD tests', function() {
}).catch(function(err) {});
});

});
});
42 changes: 22 additions & 20 deletions modules/users/server/models/user.server.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,6 @@ module.exports = function(sequelize, DataTypes) {
resetPasswordToken: DataTypes.STRING,
resetPasswordExpires: DataTypes.BIGINT
}, {
instanceMethods: {
makeSalt: function() {
return crypto.randomBytes(16).toString('base64');
},
authenticate: function(plainText) {
return this.encryptPassword(plainText, this.salt) === this.hashedPassword;
},
encryptPassword: function(password, salt) {
if (!password || !salt)
return '';
salt = new Buffer(salt, 'base64');
return crypto.pbkdf2Sync(password, salt, 10000, 64).toString('base64');
}
},
classMethods: {
findUniqueUsername: function(username, suffix, callback) {
var _this = this;
Expand All @@ -156,13 +142,29 @@ module.exports = function(sequelize, DataTypes) {
}
});
}
},
associate: function(models) {
if (models.article) {
User.hasMany(models.article);
}
}
});

User.prototype.makeSalt = function() {
return crypto.randomBytes(16).toString('base64');
};

User.prototype.authenticate = function(plainText) {
return this.encryptPassword(plainText, this.salt) === this.hashedPassword;
};

User.prototype.encryptPassword = function(password, salt) {
if (!password || !salt)
return '';
salt = new Buffer(salt, 'base64');
return crypto.pbkdf2Sync(password, salt, 10000, 64).toString('base64');
};

User.associate = function(models) {
if (models.article) {
User.hasMany(models.article);
}
};

return User;
};
};
3 changes: 1 addition & 2 deletions modules/users/tests/server/user.server.model.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ describe('User Model Unit Tests:', function() {
// should.not.exist((success) ? null : errorHandler.getErrorMessage(success));
// user1.roles = ['invalid-user-role-enum'];
// user1.save().then(function(err) {
// console.log('err', err);
// should.exist((err) ? err : null);
// user1.destroy().then(function(err) {
// should.not.exist((err) ? null : errorHandler.getErrorMessage(err));
Expand Down Expand Up @@ -584,4 +583,4 @@ describe('User Model Unit Tests:', function() {
// done();
// }).catch(function(err) {});
});
});
});
3 changes: 1 addition & 2 deletions modules/users/tests/server/user.server.routes.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ describe('User CRUD tests', function() {
.end(function(signupErr, signupRes) {
// Handle signpu error
if (signupErr) {
console.log('signupErr', signupErr);
return done(signupErr);
}
Expand Down Expand Up @@ -284,4 +283,4 @@ describe('User CRUD tests', function() {
done();
}).catch(function(err) {});
});
});
});

0 comments on commit 9477303

Please sign in to comment.