@@ -11,6 +11,8 @@ let currentUser;
11
11
let currentUserPassword ;
12
12
let httpResponse ;
13
13
let currentUserAccessToken ;
14
+ let lastPost ;
15
+ let blacklistedUser ;
14
16
15
17
function authenticate ( email , plainTextPassword ) {
16
18
const formData = {
@@ -35,10 +37,23 @@ function postRequest(route, body, callback) {
35
37
body,
36
38
headers : { 'Content-Type' : 'application/json' } ,
37
39
} ;
40
+ return request ( params , route , callback ) ;
41
+ }
42
+
43
+ function getRequest ( route , callback ) {
44
+ const params = {
45
+ method : 'get' ,
46
+ headers : { 'Content-Type' : 'application/json' } ,
47
+ } ;
48
+ return request ( params , route , callback ) ;
49
+ }
50
+
51
+ function request ( params , route , callback ) {
52
+ const requestParams = Object . assign ( { } , params ) ;
38
53
if ( currentUserAccessToken ) {
39
- params . headers . Authorization = `Bearer ${ currentUserAccessToken } ` ;
54
+ requestParams . headers . Authorization = `Bearer ${ currentUserAccessToken } ` ;
40
55
}
41
- fetch ( `${ hcBackendUrl } ${ route } ` , params )
56
+ fetch ( `${ hcBackendUrl } ${ route } ` , requestParams )
42
57
. then ( response => response . json ( ) )
43
58
. catch ( ( err ) => {
44
59
throw ( err ) ;
@@ -49,14 +64,21 @@ function postRequest(route, body, callback) {
49
64
} ) ;
50
65
}
51
66
52
- Given ( 'there is a user in Human Connection with these credentials:' , function ( dataTable ) {
67
+
68
+ Given ( 'this is your user account:' , function ( dataTable ) {
53
69
const params = dataTable . hashes ( ) [ 0 ] ;
54
70
currentUserPassword = params . password ;
55
71
return this . app . service ( 'users' ) . create ( params ) . then ( ( user ) => {
56
72
currentUser = user ;
57
73
} ) ;
58
74
} ) ;
59
75
76
+ Given ( 'these user accounts exist:' , function ( dataTable ) {
77
+ return Promise . all ( dataTable . hashes ( ) . map ( params => {
78
+ return this . app . service ( 'users' ) . create ( params ) ;
79
+ } ) ) ;
80
+ } ) ;
81
+
60
82
Given ( 'you are authenticated' , ( ) => authenticate ( currentUser . email , currentUserPassword ) . then ( ( accessToken ) => {
61
83
currentUserAccessToken = accessToken ;
62
84
} ) ) ;
@@ -92,7 +114,7 @@ Then('these category ids are stored in your user settings', function () {
92
114
} ) ;
93
115
94
116
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 ) => {
117
+ return this . app . service ( 'usersettings' ) . find ( { query : { userId : currentUser . _id . toString ( ) } } ) . then ( ( settings ) => {
96
118
expect ( settings . total ) . to . eq ( 1 ) ;
97
119
expect ( settings . data [ 0 ] . uiLanguage ) . to . eq ( lang ) ;
98
120
} ) ;
@@ -109,3 +131,71 @@ When('you create your user settings via POST request to {string} with:', functio
109
131
postRequest ( route , JSON . stringify ( jsonBody ) , callback ) ;
110
132
} ) ;
111
133
134
+ Then ( 'you will stop seeing posts of the user with id {string}' , function ( blacklistedUserId ) {
135
+ return this . app . service ( 'usersettings' ) . find ( { userId : currentUser . _id . toString ( ) } ) . then ( ( settings ) => {
136
+ expect ( settings . total ) . to . eq ( 1 ) ;
137
+ expect ( settings . data [ 0 ] . blacklist ) . to . be . an ( 'array' ) . that . does . include ( blacklistedUserId ) ;
138
+ } ) ;
139
+ } ) ;
140
+
141
+ Given ( 'you blacklisted the user {string} before' , async function ( blacklistedUserName ) {
142
+ const res = await this . app . service ( 'users' ) . find ( { query : { name : blacklistedUserName } } ) ;
143
+ blacklistedUser = res . data [ 0 ] ;
144
+ const params = {
145
+ userId : currentUser . _id ,
146
+ blacklist : [ blacklistedUser . _id ]
147
+ } ;
148
+ return this . app . service ( 'usersettings' ) . create ( params ) ;
149
+ } ) ;
150
+
151
+ When ( 'this user publishes a post' , function ( ) {
152
+ const params = {
153
+ title : 'Awful title' ,
154
+ content : 'disgusting content' ,
155
+ language : 'en' ,
156
+ type : 'post' ,
157
+ userId : blacklistedUser . _id
158
+ } ;
159
+ return this . app . service ( 'contributions' ) . create ( params ) ;
160
+ } ) ;
161
+
162
+ When ( 'you read your current news feed' , function ( callback ) {
163
+ getRequest ( '/contributions' , callback ) ;
164
+ } ) ;
165
+
166
+ Then ( 'this post is not included' , function ( ) {
167
+ expect ( httpResponse . data ) . to . be . an ( 'array' ) . that . is . empty ;
168
+ } ) ;
169
+
170
+ Given ( 'there is a post {string} by user {string}' , async function ( postTitle , userName ) {
171
+ const users = await this . app . service ( 'users' ) . find ( { query : { name : userName } } ) ;
172
+ const user = users . data [ 0 ] ;
173
+ const params = {
174
+ title : postTitle ,
175
+ content : 'blah' ,
176
+ language : 'en' ,
177
+ type : 'post' ,
178
+ userId : user . _id
179
+ } ;
180
+ lastPost = await this . app . service ( 'contributions' ) . create ( params ) ;
181
+ return lastPost ;
182
+ } ) ;
183
+
184
+ Given ( 'the blacklisted user wrote a comment on that post:' , function ( comment ) {
185
+ const commentParams = {
186
+ userId : blacklistedUser . _id ,
187
+ content : comment ,
188
+ contributionId : lastPost . _id
189
+ } ;
190
+ return this . app . service ( 'comments' ) . create ( commentParams ) ;
191
+ } ) ;
192
+
193
+ When ( 'you read through the comments of that post' , function ( callback ) {
194
+ getRequest ( '/comments' , callback ) ;
195
+ } ) ;
196
+
197
+ Then ( 'you will see a hint instead of a comment:' , function ( hint ) {
198
+ const comment = httpResponse . data [ 0 ] ;
199
+ expect ( comment . content ) . to . eq ( hint ) ;
200
+ expect ( comment . contentExcerpt ) . to . eq ( hint ) ;
201
+ } ) ;
0 commit comments