@@ -30,6 +30,26 @@ function authenticate(email, plainTextPassword) {
30
30
. then ( json => json . accessToken ) ;
31
31
}
32
32
33
+ function postRequest ( route , body , callback ) {
34
+ const params = {
35
+ method : 'post' ,
36
+ body,
37
+ headers : { 'Content-Type' : 'application/json' } ,
38
+ } ;
39
+ if ( currentUserAccessToken ) {
40
+ params . headers . Authorization = `Bearer ${ currentUserAccessToken } ` ;
41
+ }
42
+ fetch ( `${ hcBackendUrl } ${ route } ` , params )
43
+ . then ( response => response . json ( ) )
44
+ . catch ( ( err ) => {
45
+ throw ( err ) ;
46
+ } )
47
+ . then ( ( json ) => {
48
+ httpResponse = json ;
49
+ callback ( ) ;
50
+ } ) ;
51
+ }
52
+
33
53
Given ( / ^ t h e H u m a n C o n n e c t i o n A P I i s u p a n d r u n n i n g (?: o n " h t t p : \/ \/ l o c a l h o s t : 3 0 3 0 " ) ? / , ( callback ) => {
34
54
waitOn ( { resources : [ 'tcp:3030' ] , timeout : 30000 } , ( err ) => {
35
55
if ( err ) throw ( err ) ;
@@ -53,25 +73,7 @@ Given('you are authenticated', () => authenticate(currentUser.email, currentUser
53
73
currentUserAccessToken = accessToken ;
54
74
} ) ) ;
55
75
56
- When ( 'you send a POST request to {string} with:' , ( route , body , callback ) => {
57
- const params = {
58
- method : 'post' ,
59
- body,
60
- headers : { 'Content-Type' : 'application/json' } ,
61
- } ;
62
- if ( currentUserAccessToken ) {
63
- params . headers . Authorization = `Bearer ${ currentUserAccessToken } ` ;
64
- }
65
- fetch ( `${ hcBackendUrl } ${ route } ` , params )
66
- . then ( response => response . json ( ) )
67
- . catch ( ( err ) => {
68
- throw ( err ) ;
69
- } )
70
- . then ( ( json ) => {
71
- httpResponse = json ;
72
- callback ( ) ;
73
- } ) ;
74
- } ) ;
76
+ When ( 'you send a POST request to {string} with:' , ( route , body , callback ) => postRequest ( route , body , callback ) ) ;
75
77
76
78
Then ( 'there is an access token in the response:' , ( jsonResponse ) => {
77
79
expect ( httpResponse . accessToken ) . to . be . a ( 'string' ) ;
@@ -88,3 +90,22 @@ Then('a new post is created', function () {
88
90
} ) ;
89
91
} ) ;
90
92
93
+
94
+ Then ( 'your language {string} is stored in your user settings' , function ( lang ) {
95
+ return this . app . service ( 'usersettings' ) . find ( { userId : currentUser . _id . toString ( ) } ) . then ( ( settings ) => {
96
+ expect ( settings . total ) . to . eq ( 1 ) ;
97
+ expect ( settings . data [ 0 ] . uiLanguage ) . to . eq ( lang ) ;
98
+ } ) ;
99
+ } ) ;
100
+
101
+ Then ( 'debug' , function ( ) {
102
+ // eslint-disable-next-line no-debugger
103
+ debugger ;
104
+ } ) ;
105
+
106
+ When ( 'you create your user settings via POST request to {string} with:' , function ( route , body , callback ) {
107
+ let jsonBody = JSON . parse ( body ) ;
108
+ jsonBody . userId = currentUser . _id . toString ( ) ;
109
+ postRequest ( route , JSON . stringify ( jsonBody ) , callback ) ;
110
+ } ) ;
111
+
0 commit comments