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

Commit 9477303

Browse files
author
Omar Massad
committed
Fix tests with new sequelizejs updates
1 parent 05e6dbc commit 9477303

File tree

6 files changed

+27
-32
lines changed

6 files changed

+27
-32
lines changed

modules/articles/server/models/articles.server.model.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ module.exports = function(sequelize, DataTypes) {
2020
}
2121
});
2222
return Article;
23-
};
23+
};

modules/articles/tests/server/article.server.model.tests.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ describe('Article Model Unit Tests:', function() {
3131
user.salt = user.makeSalt();
3232
user.hashedPassword = user.encryptPassword('S3@n.jsI$Aw3$0m3', user.salt);
3333

34-
3534
user.save().then(function(user) {
3635
article = Article.build({
3736
title: 'Article Title',
@@ -87,4 +86,4 @@ describe('Article Model Unit Tests:', function() {
8786
}).catch(function(err) {});
8887
});
8988

90-
});
89+
});

modules/articles/tests/server/article.server.routes.tests.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@ describe('Article CRUD tests', function() {
9797
// Get articles list
9898
var articles = articlesGetRes.body;
9999

100-
// Set assertions
101-
console.log('articles[0]', articles[0]);
102-
console.log('userId', userId);
103-
104100
//(articles[0].userId).should.equal(userId);
105101
(articles[0].title).should.match('Article Title');
106102

@@ -350,4 +346,4 @@ describe('Article CRUD tests', function() {
350346
}).catch(function(err) {});
351347
});
352348

353-
});
349+
});

modules/users/server/models/user.server.model.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,6 @@ module.exports = function(sequelize, DataTypes) {
125125
resetPasswordToken: DataTypes.STRING,
126126
resetPasswordExpires: DataTypes.BIGINT
127127
}, {
128-
instanceMethods: {
129-
makeSalt: function() {
130-
return crypto.randomBytes(16).toString('base64');
131-
},
132-
authenticate: function(plainText) {
133-
return this.encryptPassword(plainText, this.salt) === this.hashedPassword;
134-
},
135-
encryptPassword: function(password, salt) {
136-
if (!password || !salt)
137-
return '';
138-
salt = new Buffer(salt, 'base64');
139-
return crypto.pbkdf2Sync(password, salt, 10000, 64).toString('base64');
140-
}
141-
},
142128
classMethods: {
143129
findUniqueUsername: function(username, suffix, callback) {
144130
var _this = this;
@@ -156,13 +142,29 @@ module.exports = function(sequelize, DataTypes) {
156142
}
157143
});
158144
}
159-
},
160-
associate: function(models) {
161-
if (models.article) {
162-
User.hasMany(models.article);
163-
}
164145
}
165146
});
166147

148+
User.prototype.makeSalt = function() {
149+
return crypto.randomBytes(16).toString('base64');
150+
};
151+
152+
User.prototype.authenticate = function(plainText) {
153+
return this.encryptPassword(plainText, this.salt) === this.hashedPassword;
154+
};
155+
156+
User.prototype.encryptPassword = function(password, salt) {
157+
if (!password || !salt)
158+
return '';
159+
salt = new Buffer(salt, 'base64');
160+
return crypto.pbkdf2Sync(password, salt, 10000, 64).toString('base64');
161+
};
162+
163+
User.associate = function(models) {
164+
if (models.article) {
165+
User.hasMany(models.article);
166+
}
167+
};
168+
167169
return User;
168-
};
170+
};

modules/users/tests/server/user.server.model.tests.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ describe('User Model Unit Tests:', function() {
129129
// should.not.exist((success) ? null : errorHandler.getErrorMessage(success));
130130
// user1.roles = ['invalid-user-role-enum'];
131131
// user1.save().then(function(err) {
132-
// console.log('err', err);
133132
// should.exist((err) ? err : null);
134133
// user1.destroy().then(function(err) {
135134
// should.not.exist((err) ? null : errorHandler.getErrorMessage(err));
@@ -584,4 +583,4 @@ describe('User Model Unit Tests:', function() {
584583
// done();
585584
// }).catch(function(err) {});
586585
});
587-
});
586+
});

modules/users/tests/server/user.server.routes.tests.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ describe('User CRUD tests', function() {
6565
.end(function(signupErr, signupRes) {
6666
// Handle signpu error
6767
if (signupErr) {
68-
console.log('signupErr', signupErr);
6968
return done(signupErr);
7069
}
7170
@@ -284,4 +283,4 @@ describe('User CRUD tests', function() {
284283
done();
285284
}).catch(function(err) {});
286285
});
287-
});
286+
});

0 commit comments

Comments
 (0)