File tree Expand file tree Collapse file tree 2 files changed +22
-7
lines changed Expand file tree Collapse file tree 2 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ const mongoose = require('mongoose');
3
3
const sinon = require ( 'sinon' ) ;
4
4
5
5
const userSchema = require ( '../../human-connection-api/server/models/users.model.js' ) ;
6
+ const contributionSchema = require ( '../../human-connection-api/server/models/contributions.model.js' ) ;
6
7
7
8
mongoose . connect ( "mongodb://localhost/hc_api_test" ) ;
8
9
const db = mongoose . connection ;
@@ -12,16 +13,25 @@ sinon.stub(app, 'get').callsFake(function() {
12
13
return mongoose ;
13
14
} ) ;
14
15
15
- let User ;
16
+ let User , Contribution ;
16
17
db . on ( 'error' , console . error . bind ( console , 'connection error:' ) ) ;
17
18
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 ) ;
19
22
} ) ;
20
23
21
24
// Asynchronous Promise
22
25
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 ( ( ) => {
25
35
callback ( ) ;
26
36
} ) ;
27
37
} ) ;
Original file line number Diff line number Diff line change @@ -81,7 +81,12 @@ Then('there is an access token in the response:', function (docString) {
81
81
expect ( httpResponse . accessToken . length ) . to . eq ( 342 ) ;
82
82
} ) ;
83
83
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
+ } ) ;
87
92
} ) ;
You can’t perform that action at this time.
0 commit comments