import { KYCStatus , UserStatus } from '@energyweb/origin-backend-core' ; Cypress . Commands . add ( 'login' , ( email , password ) => { cy . visit ( '/login' ) ; cy . fillUserLogin ( { email , password } ) ; cy . dataCy ( 'login-button' ) . click ( ) ; } ) ; Cypress . Commands . add ( 'fillUserRegister' , ( user ) => { cy . dataCy ( 'register-title-select' ) . parent ( ) . click ( ) ; cy . contains ( 'Mr' ) . click ( ) ; cy . dataCy ( 'firstName' ) . type ( user . firstName ) ; cy . dataCy ( 'lastName' ) . type ( user . lastName ) ; cy . dataCy ( 'email' ) . type ( user . email ) ; cy . dataCy ( 'telephone' ) . type ( user . telephone ) ; cy . dataCy ( 'password' ) . type ( user . password ) ; } ) ; Cypress . Commands . add ( 'apiRegisterUser' , ( user ) => { const registerUrl = `${ Cypress . env ( 'apiUrl' ) }/user/register` ; cy . request ( { url : registerUrl , method : 'POST' , body : JSON . stringify ( user ) , headers : { 'Content-Type' : 'application/json;charset=UTF-8' , } , } ) . then ( ( response ) => { const registeredUser = response . body ; return registeredUser ; } ) ; } ) ; Cypress . Commands . add ( 'fillUserLogin' , ( loginData ) => { cy . dataCy ( 'email' ) . type ( loginData . email ) ; cy . dataCy ( 'password' ) . type ( loginData . password ) ; } ) ; Cypress . Commands . add ( 'apiLoginUser' , ( loginData ) => { const { email , password } = loginData ; const loginUrl = `${ Cypress . env ( 'apiUrl' ) }/auth/login` ; const reqBody = { username : email , password } ; cy . request ( { url : loginUrl , method : 'POST' , body : JSON . stringify ( reqBody ) , headers : { 'Content-Type' : 'application/json;charset=UTF-8' , } , } ) . then ( ( res ) => { localStorage . setItem ( 'AUTHENTICATION_TOKEN' , res . body . accessToken ) ; return res . body . accessToken ; } ) ; } ) ; Cypress . Commands . add ( 'apiRegisterAndApproveUser' , ( userData ) => { const apiUrl = Cypress . env ( 'apiUrl' ) ; const adminLoginData = Cypress . env ( 'adminUser' ) ; cy . apiRegisterUser ( userData ) . then ( ( userToApprove ) => { const approveBody = { ... userToApprove , status : UserStatus . Active , kycStatus : KYCStatus . Passed , } ; cy . apiLoginUser ( adminLoginData ) . then ( ( token ) => { cy . request ( { url : `${ apiUrl }/admin/users/${ userToApprove . id }` , method : 'PUT' , body : JSON . stringify ( approveBody ) , headers : { Authorization : `Bearer ${ token }` , 'Content-Type' : 'application/json;charset=UTF-8' , } , } ) ; cy . clearLocalStorage ( ) ; } ) ; } ) ; } ) ; Cypress . Commands . add ( 'apiUserProceedInvitation' , ( userData , status ) => { const invitationUrl = `${ Cypress . env ( 'apiUrl' ) }/invitation` ; cy . apiLoginUser ( userData ) . then ( ( token ) => { cy . request ( { url : invitationUrl , method : 'GET' , headers : { Authorization : `Bearer ${ token }` , 'Content-Type' : 'application/json;charset=UTF-8' , } , } ) . then ( ( response ) => { const inviteId = response . body [ 0 ] . id ; return inviteId ; } ) . then ( ( inviteId ) => { cy . request ( { url : `${ invitationUrl }/${ inviteId }/${ status }` , method : 'PUT' , headers : { Authorization : `Bearer ${ token }` , 'Content-Type' : 'application/json;charset=UTF-8' , } , } ) ; cy . clearLocalStorage ( ) ; } ) ; } ) ; } ) ;