import { User , Transaction } from "../../../src/models" ; type NewTransactionCtx = { transactionRequest ? : Transaction ; authenticatedUser ? : User ; } ; describe ( "Transaction View" , function ( ) { const ctx = { } ; beforeEach ( function ( ) { cy . task ( "db:seed" ) ; cy . intercept ( "GET" , "/transactions*" ) . as ( "personalTransactions" ) ; cy . intercept ( "GET" , "/transactions/public*" ) . as ( "publicTransactions" ) ; cy . intercept ( "GET" , "/transactions/*" ) . as ( "getTransaction" ) ; cy . intercept ( "PATCH" , "/transactions/*" ) . as ( "updateTransaction" ) ; cy . intercept ( "GET" , "/checkAuth" ) . as ( "userProfile" ) ; cy . intercept ( "GET" , "/notifications" ) . as ( "getNotifications" ) ; cy . intercept ( "GET" , "/bankAccounts" ) . as ( "getBankAccounts" ) ; cy . database ( "find" , "users" ) . then ( ( user ) => { ctx . authenticatedUser = user ; cy . loginByXstate ( ctx . authenticatedUser . username ) ; cy . database ( "find" , "transactions" , { receiverId : ctx . authenticatedUser . id , status : "pending" , requestStatus : "pending" , requestResolvedAt : "" , } ) . then ( ( transaction ) => { ctx . transactionRequest = transaction ; } ) ; } ) ; cy . getBySel ( "nav-personal-tab" ) . click ( ) ; cy . wait ( "@personalTransactions" ) ; } ) ; it ( "transactions navigation tabs are hidden on a transaction view page" , function ( ) { cy . getBySelLike ( "transaction-item" ) . first ( ) . click ( ) ; cy . location ( "pathname" ) . should ( "include" , "/transaction" ) ; cy . getBySel ( "nav-transaction-tabs" ) . should ( "not.exist" ) ; cy . getBySel ( "transaction-detail-header" ) . should ( "be.visible" ) ; cy . visualSnapshot ( "Transaction Navigation Tabs Hidden" ) ; } ) ; it ( "likes a transaction" , function ( ) { cy . getBySelLike ( "transaction-item" ) . first ( ) . click ( ) ; cy . wait ( "@getTransaction" ) ; cy . getBySelLike ( "like-button" ) . click ( ) ; cy . getBySelLike ( "like-count" ) . should ( "contain" , 1 ) ; cy . getBySelLike ( "like-button" ) . should ( "be.disabled" ) ; cy . visualSnapshot ( "Transaction after Liked" ) ; } ) ; it ( "comments on a transaction" , function ( ) { cy . getBySelLike ( "transaction-item" ) . first ( ) . click ( ) ; cy . wait ( "@getTransaction" ) ; const comments = [ "Thank you!" , "Appreciate it." ] ; comments . forEach ( ( comment , index ) => { cy . getBySelLike ( "comment-input" ) . type ( `${ comment }{enter}` ) ; cy . getBySelLike ( "comments-list" ) . children ( ) . eq ( index ) . contains ( comment ) ; } ) ; cy . getBySelLike ( "comments-list" ) . children ( ) . should ( "have.length" , comments . length ) ; cy . visualSnapshot ( "Comment on Transaction" ) ; } ) ; it ( "accepts a transaction request" , function ( ) { cy . visit ( `/transaction/${ ctx . transactionRequest ! . id }` ) ; cy . wait ( "@getTransaction" ) ; cy . getBySelLike ( "accept-request" ) . click ( ) ; cy . wait ( "@updateTransaction" ) . its ( "response.statusCode" ) . should ( "equal" , 204 ) ; cy . getBySelLike ( "accept-request" ) . should ( "not.exist" ) ; cy . getBySel ( "transaction-detail-header" ) . should ( "be.visible" ) ; cy . visualSnapshot ( "Transaction Accepted" ) ; } ) ; it ( "rejects a transaction request" , function ( ) { cy . visit ( `/transaction/${ ctx . transactionRequest ! . id }` ) ; cy . wait ( "@getTransaction" ) ; cy . getBySelLike ( "reject-request" ) . click ( ) ; cy . wait ( "@updateTransaction" ) . its ( "response.statusCode" ) . should ( "equal" , 204 ) ; cy . getBySelLike ( "reject-request" ) . should ( "not.exist" ) ; cy . getBySel ( "transaction-detail-header" ) . should ( "be.visible" ) ; cy . visualSnapshot ( "Transaction Rejected" ) ; } ) ; it ( "does not display accept/reject buttons on completed request" , function ( ) { cy . database ( "find" , "transactions" , { receiverId : ctx . authenticatedUser ! . id , status : "complete" , requestStatus : "accepted" , } ) . then ( ( transactionRequest ) => { cy . visit ( `/transaction/${ transactionRequest ! . id }` ) ; cy . wait ( "@getNotifications" ) ; cy . getBySel ( "nav-top-notifications-count" ) . should ( "be.visible" ) ; cy . getBySel ( "transaction-detail-header" ) . should ( "be.visible" ) ; cy . getBySel ( "transaction-accept-request" ) . should ( "not.exist" ) ; cy . getBySel ( "transaction-reject-request" ) . should ( "not.exist" ) ; cy . getBySel ( "transaction-detail-header" ) . should ( "be.visible" ) ; cy . visualSnapshot ( "Transaction Completed (not able to accept or reject)" ) ; } ) ; } ) ; } ) ;