Skip to content

Commit 785af73

Browse files
committed
Refactoring: Use promises when possible
1 parent fd5a5e8 commit 785af73

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

features/env/database.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,8 @@ db.once('open', function() {
2323

2424
// Asynchronous Promise
2525
Before(function(_, callback) {
26-
let promises = [User].map((model) => {
27-
return new Promise(function(resolve, reject) {
28-
model.remove(function (err) {
29-
if(err) reject(err);
30-
resolve();
31-
});
32-
});
26+
let promises = [User, Contribution].map((model) => {
27+
return model.remove();
3328
});
3429
Promise.all(promises).then(() => {
3530
callback();

features/step_definitions/steps.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,14 @@ Given("there is a 3rd party application running, e.g. 'Democracy'", function ()
3232
// Just documentation
3333
});
3434

35-
Given('there is an organization in Human Connection with these credentials:', function (dataTable, callback) {
35+
Given('there is an organization in Human Connection with these credentials:', function (dataTable) {
3636
const User = mongoose.model('users');
3737
params = dataTable.hashes()[0];
38-
encrypt(params.password).then((hashedPassword) => {
38+
return encrypt(params.password).then((hashedPassword) => {
3939
currentUserPassword = params.password; // remember plain text password
4040
params.password = hashedPassword; // hashed password goes into db
4141
currentUser = new User(params);
42-
currentUser.save(function (err, user) {
43-
if(err) callback(err);
44-
callback();
45-
});
42+
return currentUser.save();
4643
});
4744
});
4845

@@ -52,13 +49,10 @@ Given('I am authenticated', function () {
5249
});
5350
});
5451

55-
Given('my user account is verified', function (callback) {
52+
Given('my user account is verified', function () {
5653
// Write code here that turns the phrase above into concrete actions
5754
currentUser.isVerified = true;
58-
currentUser.save(function(err, user) {
59-
if(err) throw(err);
60-
callback();
61-
});
55+
return currentUser.save();
6256
});
6357

6458
When('I send a POST request to {string} with:', function (route, body, callback) {

0 commit comments

Comments
 (0)