1
1
const { Given, When, Then } = require ( 'cucumber' ) ;
2
2
const fetch = require ( 'node-fetch' ) ;
3
3
const mongoose = require ( 'mongoose' ) ;
4
- const expect = require ( 'chai' ) . expect ;
4
+ const { expect } = require ( 'chai' ) ;
5
5
// Hack: Directly accessing the default password hashing function
6
6
const encrypt = require ( '../../node_modules/feathers-authentication-local/lib/utils/hash' ) ;
7
7
8
- let currentUser , currentUserPassword , httpResponse , currentUserAccessToken ;
8
+ let currentUser ;
9
+ let currentUserPassword ;
10
+ let httpResponse ;
11
+ let currentUserAccessToken ;
9
12
const hcBackendUrl = 'http://localhost:3030' ;
10
13
11
14
12
- function authenticate ( email , plainTextPassword ) {
15
+ function authenticate ( email , plainTextPassword ) {
13
16
const formData = {
14
- email : email ,
17
+ email,
15
18
password : plainTextPassword ,
16
19
strategy : 'local' ,
17
20
} ;
18
21
return fetch ( `${ hcBackendUrl } /authentication` , {
19
22
method : 'post' ,
20
23
body : JSON . stringify ( formData ) ,
21
24
headers : { 'Content-Type' : 'application/json' } ,
22
- } ) . then ( response => response . json ( ) ) . then ( ( json ) => {
23
- return json . accessToken ;
24
- } ) ;
25
+ } ) . then ( response => response . json ( ) ) . then ( json => json . accessToken ) ;
25
26
}
26
27
27
- Given ( 'the Human Connection API is up and running' , function ( ) {
28
+ Given ( 'the Human Connection API is up and running' , ( ) => {
28
29
// Just documentation
29
30
} ) ;
30
31
31
- Given ( "there is a 3rd party application running, e.g. 'Democracy'" , function ( ) {
32
+ Given ( "there is a 3rd party application running, e.g. 'Democracy'" , ( ) => {
32
33
// Just documentation
33
34
} ) ;
34
35
35
- Given ( 'there is an organization in Human Connection with these credentials:' , function ( dataTable ) {
36
+ Given ( 'there is an organization in Human Connection with these credentials:' , ( dataTable ) => {
36
37
const User = mongoose . model ( 'users' ) ;
37
- params = dataTable . hashes ( ) [ 0 ] ;
38
+ const params = dataTable . hashes ( ) [ 0 ] ;
38
39
return encrypt ( params . password ) . then ( ( hashedPassword ) => {
39
40
currentUserPassword = params . password ; // remember plain text password
40
41
params . password = hashedPassword ; // hashed password goes into db
@@ -43,22 +44,20 @@ Given('there is an organization in Human Connection with these credentials:', fu
43
44
} ) ;
44
45
} ) ;
45
46
46
- Given ( 'I am authenticated' , function ( ) {
47
- return authenticate ( currentUser . email , currentUserPassword ) . then ( ( accessToken ) => {
48
- currentUserAccessToken = accessToken ;
49
- } ) ;
50
- } ) ;
47
+ Given ( 'I am authenticated' , ( ) => authenticate ( currentUser . email , currentUserPassword ) . then ( ( accessToken ) => {
48
+ currentUserAccessToken = accessToken ;
49
+ } ) ) ;
51
50
52
- Given ( 'my user account is verified' , function ( ) {
51
+ Given ( 'my user account is verified' , ( ) => {
53
52
// Write code here that turns the phrase above into concrete actions
54
53
currentUser . isVerified = true ;
55
54
return currentUser . save ( ) ;
56
55
} ) ;
57
56
58
- When ( 'I send a POST request to {string} with:' , function ( route , body , callback ) {
59
- let params = {
57
+ When ( 'I send a POST request to {string} with:' , ( route , body , callback ) => {
58
+ const params = {
60
59
method : 'post' ,
61
- body : body ,
60
+ body,
62
61
headers : { 'Content-Type' : 'application/json' } ,
63
62
} ;
64
63
if ( currentUserAccessToken ) {
@@ -70,15 +69,15 @@ When('I send a POST request to {string} with:', function (route, body, callback)
70
69
} ) ;
71
70
} ) ;
72
71
73
- Then ( 'there is an access token in the response:' , function ( docString ) {
72
+ Then ( 'there is an access token in the response:' , ( ) => {
74
73
expect ( httpResponse . accessToken ) . to . be . a ( 'string' ) ;
75
74
expect ( httpResponse . accessToken . length ) . to . eq ( 342 ) ;
76
75
} ) ;
77
76
78
- Then ( 'a new post should be created' , function ( callback ) {
77
+ Then ( 'a new post should be created' , ( callback ) => {
79
78
const Contribution = mongoose . model ( 'contributions' ) ;
80
- Contribution . find ( { } , function ( err , contributions ) {
81
- if ( err ) throw ( err ) ;
79
+ Contribution . find ( { } , ( err , contributions ) => {
80
+ if ( err ) throw ( err ) ;
82
81
expect ( contributions ) . to . have . lengthOf ( 1 ) ;
83
82
expect ( contributions [ 0 ] . type ) . to . eq ( 'post' ) ;
84
83
callback ( ) ;
0 commit comments