Skip to content

Commit fd5a5e8

Browse files
committed
Green cucumbers 🎉
Expect one new created post
1 parent 1eb88e3 commit fd5a5e8

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

features/env/database.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const mongoose = require('mongoose');
33
const sinon = require('sinon');
44

55
const userSchema = require('../../human-connection-api/server/models/users.model.js');
6+
const contributionSchema = require('../../human-connection-api/server/models/contributions.model.js');
67

78
mongoose.connect("mongodb://localhost/hc_api_test");
89
const db = mongoose.connection;
@@ -12,16 +13,25 @@ sinon.stub(app, 'get').callsFake(function() {
1213
return mongoose;
1314
});
1415

15-
let User;
16+
let User, Contribution;
1617
db.on('error', console.error.bind(console, 'connection error:'));
1718
db.once('open', function() {
18-
User = userSchema(app); // initialize User model
19+
// initialize models needed in step definitions
20+
User = userSchema(app);
21+
Contribution = contributionSchema(app);
1922
});
2023

2124
// Asynchronous Promise
2225
Before(function(_, callback) {
23-
User.remove(function (err) {
24-
if(err) throw(err);
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+
});
33+
});
34+
Promise.all(promises).then(() => {
2535
callback();
2636
});
2737
});

features/step_definitions/steps.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ Then('there is an access token in the response:', function (docString) {
8181
expect(httpResponse.accessToken.length).to.eq(342);
8282
});
8383

84-
Then('a new post should be created', function () {
85-
// Write code here that turns the phrase above into concrete actions
86-
return 'pending';
84+
Then('a new post should be created', function (callback) {
85+
const Contribution = mongoose.model('contributions');
86+
Contribution.find({}, function(err, contributions){
87+
if(err) throw(err);
88+
expect(contributions).to.have.lengthOf(1);
89+
expect(contributions[0].type).to.eq('post');
90+
callback();
91+
});
8792
});

0 commit comments

Comments
 (0)