11describe ( 'local app stack' , ( ) => {
22 const apiOrigin = Cypress . env ( 'apiOrigin' ) || 'http://localhost:8080' ;
3+ const appOrigin = Cypress . config ( 'baseUrl' ) || 'http://localhost:3000' ;
34
4- const post = ( url , body ) => cy . request ( `${ apiOrigin } /api/csrf-token` )
5+ const post = ( origin , url , body ) => cy . request ( `${ origin } /api/csrf-token` )
56 . then ( ( { body : { csrfToken } } ) => cy . request ( {
67 body,
78 headers : { 'x-csrf-token' : csrfToken } ,
89 method : 'POST' ,
910 url,
1011 } ) ) ;
1112
13+ const postToApi = ( url , body ) => post ( apiOrigin , url , body ) ;
14+ const postFromApp = ( url , body ) => post ( appOrigin , url , body ) ;
15+
1216 const login = ( ) => {
13- return post ( `${ apiOrigin } /auth/code` , {
17+ return postFromApp ( `${ appOrigin } /auth/code` , {
1418 code : 'cypress-test-code' ,
1519 redirectUri : 'http://localhost:3000/wca-redirect' ,
1620 } ) ;
1721 } ;
1822
1923 const loginAs = ( userId ) => {
20- return post ( `${ apiOrigin } /auth/code` , {
24+ return postFromApp ( `${ appOrigin } /auth/code` , {
2125 code : `cypress-test-user-${ userId } ` ,
2226 redirectUri : 'http://localhost:3000/wca-redirect' ,
2327 } ) ;
@@ -158,7 +162,7 @@ describe('local app stack', () => {
158162
159163 loginAs ( recipientId ) ;
160164 loginAs ( requesterId ) ;
161- post ( `${ apiOrigin } /api/friends/requests` , { userId : recipientId } )
165+ postToApi ( `${ apiOrigin } /api/friends/requests` , { userId : recipientId } )
162166 . its ( 'status' ) . should ( 'eq' , 201 ) ;
163167
164168 loginAs ( recipientId ) ;
@@ -175,11 +179,23 @@ describe('local app stack', () => {
175179 cy . contains ( 'sent you a friend request.' ) . should ( 'be.visible' ) ;
176180 cy . contains ( 'View all notifications' ) . click ( ) ;
177181 cy . location ( 'pathname' ) . should ( 'eq' , '/notifications' ) ;
182+ cy . intercept ( 'POST' , '**/api/friends/requests/*/accept' ) . as ( 'acceptFriendRequest' ) ;
178183 cy . get ( 'button[aria-label="accept notification"]' ) . click ( ) ;
184+ cy . wait ( '@acceptFriendRequest' ) . its ( 'response.statusCode' ) . should ( 'eq' , 200 ) ;
179185
180186 loginAs ( requesterId ) ;
187+ cy . intercept ( {
188+ method : 'GET' ,
189+ pathname : '/api/notifications' ,
190+ query : { limit : '20' } ,
191+ } ) . as ( 'requesterNotifications' ) ;
181192 cy . visit ( '/notifications' ) ;
182- cy . contains ( 'accepted your friend request.' , { timeout : 10000 } ) . should ( 'be.visible' ) ;
193+ cy . wait ( '@requesterNotifications' ) . its ( 'response.body.notifications' ) . should ( ( notifications ) => {
194+ expect ( notifications . some ( ( notification ) => (
195+ notification . type === 'friend_request_accepted' && notification . actor . id === recipientId
196+ ) ) ) . to . eq ( true ) ;
197+ } ) ;
198+ cy . contains ( 'accepted your friend request.' ) . should ( 'be.visible' ) ;
183199 } ) ;
184200
185201 it ( 'starts a race with an accepted friend and lets them join from the invitation' , ( ) => {
@@ -188,10 +204,10 @@ describe('local app stack', () => {
188204
189205 loginAs ( guestId ) ;
190206 loginAs ( hostId ) ;
191- post ( `${ apiOrigin } /api/friends/requests` , { userId : guestId } )
207+ postToApi ( `${ apiOrigin } /api/friends/requests` , { userId : guestId } )
192208 . its ( 'status' ) . should ( 'eq' , 201 ) ;
193209 loginAs ( guestId ) ;
194- post ( `${ apiOrigin } /api/friends/requests/${ hostId } /accept` )
210+ postToApi ( `${ apiOrigin } /api/friends/requests/${ hostId } /accept` )
195211 . its ( 'status' ) . should ( 'eq' , 200 ) ;
196212
197213 loginAs ( hostId ) ;
0 commit comments