@@ -13,19 +13,29 @@ describe('local app stack', () => {
1313 const postToApi = ( url , body ) => post ( apiOrigin , url , body ) ;
1414 const postFromApp = ( url , body ) => post ( appOrigin , url , body ) ;
1515
16- const login = ( ) => {
17- return postFromApp ( `${ appOrigin } /auth/code` , {
18- code : ' cypress-test-code' ,
16+ const loginAs = ( userId = 990001 ) => cy . session ( `cypress-test-user- ${ userId } ` , ( ) => {
17+ postFromApp ( `${ appOrigin } /auth/code` , {
18+ code : ` cypress-test-user- ${ userId } ` ,
1919 redirectUri : 'http://localhost:3000/wca-redirect' ,
2020 } ) ;
21- } ;
21+ cy . request ( `${ appOrigin } /api/me` ) . its ( 'body.id' ) . should ( 'eq' , userId ) ;
22+ } , {
23+ validate : ( ) => {
24+ cy . request ( `${ appOrigin } /api/me` ) . its ( 'body.id' ) . should ( 'eq' , userId ) ;
25+ } ,
26+ } ) ;
2227
23- const loginAs = ( userId ) => {
24- return postFromApp ( `${ appOrigin } /auth/code` , {
25- code : ` cypress-test-user- ${ userId } ` ,
28+ const login = ( ) => cy . session ( 'cypress-test-user-default' , ( ) => {
29+ postFromApp ( `${ appOrigin } /auth/code` , {
30+ code : ' cypress-test-code' ,
2631 redirectUri : 'http://localhost:3000/wca-redirect' ,
2732 } ) ;
28- } ;
33+ cy . request ( `${ appOrigin } /api/me` ) . its ( 'body.id' ) . should ( 'eq' , 990001 ) ;
34+ } , {
35+ validate : ( ) => {
36+ cy . request ( `${ appOrigin } /api/me` ) . its ( 'body.id' ) . should ( 'eq' , 990001 ) ;
37+ } ,
38+ } ) ;
2939
3040 it ( 'shows the lobby without a logged-in session' , ( ) => {
3141 cy . visit ( '/' ) ;
@@ -184,17 +194,13 @@ describe('local app stack', () => {
184194 cy . wait ( '@acceptFriendRequest' ) . its ( 'response.statusCode' ) . should ( 'eq' , 200 ) ;
185195
186196 loginAs ( requesterId ) ;
187- cy . intercept ( {
188- method : 'GET' ,
189- pathname : '/api/notifications' ,
190- query : { limit : '20' } ,
191- } ) . as ( 'requesterNotifications' ) ;
192- cy . visit ( '/notifications' ) ;
193- cy . wait ( '@requesterNotifications' ) . its ( 'response.body.notifications' ) . should ( ( notifications ) => {
194- expect ( notifications . some ( ( notification ) => (
197+ cy . request ( `${ apiOrigin } /api/notifications` ) . then ( ( response ) => {
198+ expect ( response . status ) . to . eq ( 200 ) ;
199+ expect ( response . body . notifications . some ( ( notification ) => (
195200 notification . type === 'friend_request_accepted' && notification . actor . id === recipientId
196201 ) ) ) . to . eq ( true ) ;
197202 } ) ;
203+ cy . visit ( '/notifications' ) ;
198204 cy . contains ( 'accepted your friend request.' ) . should ( 'be.visible' ) ;
199205 } ) ;
200206
0 commit comments