2021-09-27 10:04:21 +00:00
/// <reference types="cypress"/>
/// <reference types="../support"/>
2021-07-23 09:46:44 +00:00
import faker from "faker" ;
2023-05-23 07:51:36 +00:00
import {
BUTTON _SELECTORS ,
HOMEPAGE _SELECTORS ,
INVITE _STAFF _MEMBER _FORM _SELECTORS ,
SHARED _ELEMENTS ,
STAFF _MEMBER _DETAILS _SELECTORS ,
STAFF _MEMBERS _LIST _SELECTORS ,
} from "../elements/" ;
2021-12-05 15:03:29 +00:00
import { LOGIN _SELECTORS } from "../elements/account/login-selectors" ;
2023-07-28 07:48:41 +00:00
import {
MESSAGES ,
TEST _ADMIN _USER ,
urlList ,
} from "../fixtures" ;
2023-05-23 07:51:36 +00:00
import { userDetailsUrl } from "../fixtures/urlList" ;
2021-07-23 09:46:44 +00:00
import {
2023-05-23 07:51:36 +00:00
activatePlugin ,
updatePlugin ,
2022-06-27 16:49:35 +00:00
updateStaffMember ,
2023-05-23 07:51:36 +00:00
} from "../support/api/requests/" ;
2021-07-23 09:46:44 +00:00
import {
getMailActivationLinkForUser ,
2021-12-05 15:03:29 +00:00
getMailActivationLinkForUserAndSubject ,
2022-06-27 16:49:35 +00:00
inviteStaffMemberWithFirstPermission ,
2023-05-23 07:51:36 +00:00
} from "../support/api/utils/" ;
2021-09-27 10:04:21 +00:00
import {
2023-05-23 07:51:36 +00:00
expectMainMenuAvailableSections ,
expectWelcomeMessageIncludes ,
2022-12-23 10:30:21 +00:00
fillUpOnlyUserDetails ,
2021-09-27 10:04:21 +00:00
fillUpSetPassword ,
2022-12-23 10:30:21 +00:00
fillUpUserDetailsAndAddFirstPermission ,
2022-06-27 16:49:35 +00:00
updateUserActiveFlag ,
2023-05-23 07:51:36 +00:00
} from "../support/pages/" ;
2021-07-23 09:46:44 +00:00
2022-06-27 09:30:51 +00:00
describe ( "Staff members" , ( ) => {
2023-05-29 07:15:07 +00:00
const startsWith = "StaffMembers" + Date . now ( ) ;
2022-06-27 09:30:51 +00:00
const password = Cypress . env ( "USER_PASSWORD" ) ;
const lastName = faker . name . lastName ( ) ;
const email = ` ${ startsWith } ${ lastName } @example.com ` ;
2022-12-23 10:30:21 +00:00
2022-06-27 09:30:51 +00:00
let user ;
2021-07-23 09:46:44 +00:00
2022-06-27 09:30:51 +00:00
before ( ( ) => {
2023-07-28 07:48:41 +00:00
cy . loginUserViaRequest ( ) ;
2022-11-16 12:44:34 +00:00
activatePlugin ( { id : "mirumee.notifications.admin_email" } ) ;
2022-06-27 09:30:51 +00:00
inviteStaffMemberWithFirstPermission ( { email } )
. then ( ( { user : userResp } ) => {
user = userResp ;
getMailActivationLinkForUser ( email ) ;
} )
. then ( urlLink => {
2021-07-23 09:46:44 +00:00
cy . clearSessionData ( ) . visit ( urlLink ) ;
fillUpSetPassword ( password ) ;
2022-06-27 09:30:51 +00:00
cy . clearSessionData ( ) ;
2023-01-16 13:55:38 +00:00
cy . checkIfDataAreNotNull ( { user } ) ;
2021-07-23 09:46:44 +00:00
} ) ;
2022-06-27 09:30:51 +00:00
} ) ;
beforeEach ( ( ) => {
2023-07-28 07:48:41 +00:00
cy . loginUserViaRequest ( ) ;
2022-06-27 09:30:51 +00:00
} ) ;
2022-12-23 10:30:21 +00:00
it (
"should be able to invite staff user. TC: SALEOR_3501" ,
2023-05-23 07:51:36 +00:00
{ tags : [ "@staffMembers" , "@allEnv" , "@critical" ] } ,
2022-12-23 10:30:21 +00:00
( ) => {
const firstName = faker . name . firstName ( ) ;
const emailInvite = ` ${ startsWith } ${ firstName } @example.com ` ;
cy . visit ( urlList . staffMembers )
. expectSkeletonIsVisible ( )
2023-03-09 08:18:07 +00:00
. get ( STAFF _MEMBERS _LIST _SELECTORS . inviteStaffMemberButton )
2022-12-23 10:30:21 +00:00
. click ( { force : true } ) ;
fillUpUserDetailsAndAddFirstPermission ( firstName , lastName , emailInvite ) ;
getMailActivationLinkForUser ( emailInvite ) . then ( urlLink => {
cy . clearSessionData ( ) . visit ( urlLink ) ;
fillUpSetPassword ( password ) ;
expectWelcomeMessageIncludes ( ` ${ firstName } ${ lastName } ` ) ;
} ) ;
} ,
) ;
2021-07-23 09:46:44 +00:00
2022-06-27 09:30:51 +00:00
it (
2022-12-23 10:30:21 +00:00
"should deactivate user. TC: SALEOR_3502" ,
2023-01-16 14:05:07 +00:00
{ tags : [ "@staffMembers" , "@allEnv" ] } ,
2022-06-27 09:30:51 +00:00
( ) => {
2021-07-23 09:46:44 +00:00
updateStaffMember ( { userId : user . id , isActive : true } ) ;
updateUserActiveFlag ( user . id ) ;
cy . clearSessionData ( )
. loginUserViaRequest ( "auth" , { email , password } )
. its ( "body.data.tokenCreate" )
. then ( tokenCreate => {
2022-06-27 09:30:51 +00:00
expect (
tokenCreate . errors [ 0 ] . code ,
2022-06-27 16:49:35 +00:00
"logging in should return error" ,
2022-06-27 09:30:51 +00:00
) . to . be . eq ( "INACTIVE" ) ;
2021-07-23 09:46:44 +00:00
expect ( tokenCreate . token ) . to . be . not . ok ;
} ) ;
2022-06-27 16:49:35 +00:00
} ,
2022-06-27 09:30:51 +00:00
) ;
2021-07-23 09:46:44 +00:00
2022-12-23 10:30:21 +00:00
it (
"should activate user. TC: SALEOR_3503" ,
2023-05-23 07:51:36 +00:00
{ tags : [ "@staffMembers" , "@allEnv" , "@critical" ] } ,
2022-12-23 10:30:21 +00:00
( ) => {
const serverStoredEmail = email . toLowerCase ( ) ;
2022-12-07 09:52:39 +00:00
2022-12-23 10:30:21 +00:00
updateStaffMember ( { userId : user . id , isActive : false } ) ;
updateUserActiveFlag ( user . id ) ;
cy . clearSessionData ( )
. loginUserViaRequest ( "auth" , { email , password } )
. visit ( urlList . homePage ) ;
expectWelcomeMessageIncludes ( serverStoredEmail ) ;
} ,
) ;
2021-07-23 09:46:44 +00:00
2022-06-27 09:30:51 +00:00
it (
2022-12-23 10:30:21 +00:00
"should remove user permissions. TC: SALEOR_3504" ,
2023-01-16 14:05:07 +00:00
{ tags : [ "@staffMembers" , "@allEnv" ] } ,
2022-06-27 09:30:51 +00:00
( ) => {
2022-12-07 09:52:39 +00:00
const serverStoredEmail = email . toLowerCase ( ) ;
2021-07-23 09:46:44 +00:00
cy . visit ( userDetailsUrl ( user . id ) )
2023-03-09 08:18:07 +00:00
. get ( STAFF _MEMBER _DETAILS _SELECTORS . removePermissionButton )
2021-07-23 09:46:44 +00:00
. click ( )
. addAliasToGraphRequest ( "StaffMemberUpdate" )
. get ( BUTTON _SELECTORS . confirm )
2021-09-27 10:04:21 +00:00
. click ( )
. confirmationMessageShouldDisappear ( )
. waitForRequestAndCheckIfNoErrors ( "@StaffMemberUpdate" )
2021-07-23 09:46:44 +00:00
. clearSessionData ( )
. loginUserViaRequest ( "auth" , { email , password } )
. visit ( urlList . homePage ) ;
2022-12-07 09:52:39 +00:00
expectWelcomeMessageIncludes ( serverStoredEmail ) ;
2023-05-23 07:51:36 +00:00
expectMainMenuAvailableSections ( 1 ) ;
cy . get ( HOMEPAGE _SELECTORS . activity ) . should ( "not.exist" ) ;
cy . get ( HOMEPAGE _SELECTORS . topProducts ) . should ( "not.exist" ) ;
2022-06-27 16:49:35 +00:00
} ,
2022-06-27 09:30:51 +00:00
) ;
2021-12-05 15:03:29 +00:00
2022-06-27 09:30:51 +00:00
it (
2022-12-23 10:30:21 +00:00
"should reset password. TC: SALEOR_3505" ,
2023-05-23 07:51:36 +00:00
{ tags : [ "@staffMembers" , "@allEnv" , "@critical" ] } ,
2022-06-27 09:30:51 +00:00
( ) => {
2021-12-05 15:03:29 +00:00
const newPassword = faker . random . alphaNumeric ( 8 ) ;
updatePlugin (
"mirumee.notifications.admin_email" ,
"staff_password_reset_subject" ,
2022-06-27 16:49:35 +00:00
"Reset" ,
2021-12-05 15:03:29 +00:00
)
. then ( ( ) => {
cy . clearSessionData ( )
. visit ( urlList . homePage )
. get ( LOGIN _SELECTORS . resetPasswordLink )
. click ( )
. get ( LOGIN _SELECTORS . emailAddressInput )
. type ( email )
. get ( BUTTON _SELECTORS . submit )
. click ( ) ;
getMailActivationLinkForUserAndSubject ( email , "Reset" ) ;
} )
. then ( link => {
cy . visit ( link )
. get ( LOGIN _SELECTORS . emailPasswordInput )
. type ( newPassword )
. get ( LOGIN _SELECTORS . confirmPassword )
. type ( newPassword )
. get ( BUTTON _SELECTORS . confirm )
. click ( )
. get ( LOGIN _SELECTORS . welcomePage )
. should ( "be.visible" )
. loginUserViaRequest ( { email , password : newPassword } ) ;
} ) ;
2022-06-27 16:49:35 +00:00
} ,
2022-06-27 09:30:51 +00:00
) ;
2022-12-23 10:30:21 +00:00
it (
"should not be able to create staff member with not unique email. TC: SALEOR_3508" ,
2023-05-23 07:51:36 +00:00
{ tags : [ "@staffMembers" , "@allEnv" , "@critical" ] } ,
2022-12-23 10:30:21 +00:00
( ) => {
const firstName = faker . name . firstName ( ) ;
const emailInvite = TEST _ADMIN _USER . email ;
cy . visit ( urlList . staffMembers )
. expectSkeletonIsVisible ( )
2023-03-09 08:18:07 +00:00
. get ( STAFF _MEMBERS _LIST _SELECTORS . inviteStaffMemberButton )
2022-12-23 10:30:21 +00:00
. click ( { force : true } ) ;
fillUpOnlyUserDetails ( firstName , lastName , emailInvite ) ;
2023-03-09 08:18:07 +00:00
cy . get ( INVITE _STAFF _MEMBER _FORM _SELECTORS . emailValidationMessage ) . should (
2023-01-30 10:54:58 +00:00
"be.visible" ,
) ;
cy . get ( BUTTON _SELECTORS . dialogBackButton ) . click ( ) ;
2022-12-23 10:30:21 +00:00
cy . confirmationErrorMessageShouldAppear ( ) ;
} ,
) ;
it (
"should not be able to update staff member with not unique email. TC: SALEOR_3509" ,
2023-01-16 14:05:07 +00:00
{ tags : [ "@staffMembers" , "@allEnv" ] } ,
2022-12-23 10:30:21 +00:00
( ) => {
2023-05-23 07:51:36 +00:00
cy . addAliasToGraphRequest ( "StaffList" ) ;
2022-12-23 10:30:21 +00:00
cy . visit ( urlList . staffMembers )
2023-05-23 07:51:36 +00:00
. waitForRequestAndCheckIfNoErrors ( "@StaffList" )
2022-12-23 10:30:21 +00:00
. get ( SHARED _ELEMENTS . searchInput )
2023-05-23 07:51:36 +00:00
. type ( ` ${ email } {enter} ` )
. waitForRequestAndCheckIfNoErrors ( "@StaffList" ) ;
cy . get ( STAFF _MEMBERS _LIST _SELECTORS . usersEmails )
. should ( "contain.text" , email . toLowerCase ( ) )
2022-12-23 10:30:21 +00:00
. click ( ) ;
2023-03-09 08:18:07 +00:00
cy . get ( STAFF _MEMBER _DETAILS _SELECTORS . staffEmail )
2022-12-23 10:30:21 +00:00
. click ( )
. clear ( )
. type ( ` ${ TEST _ADMIN _USER . email } {enter} ` )
. get ( BUTTON _SELECTORS . confirm )
. click ( )
. confirmationErrorMessageShouldAppear ( ) ;
2023-05-23 07:51:36 +00:00
cy . contains ( MESSAGES . invalidEmailAddress ) . should ( "be.visible" ) ;
2022-12-23 10:30:21 +00:00
} ,
) ;
// Test blocked by https://github.com/saleor/saleor-dashboard/issues/2847
it . skip (
"should update staff member name and email. TC: SALEOR_3507" ,
2023-01-16 14:05:07 +00:00
{ tags : [ "@staffMembers" , "@allEnv" ] } ,
2022-12-23 10:30:21 +00:00
( ) => {
const newLastName = faker . name . lastName ( ) ;
const newEmail = ` ${ startsWith } ${ newLastName } @example.com ` ;
const changedName = faker . name . lastName ( ) ;
const changedEmail = ` ${ startsWith } ${ changedName } @example.com ` ;
inviteStaffMemberWithFirstPermission ( { email : newEmail } )
. then ( ( { user : userResp } ) => {
user = userResp ;
getMailActivationLinkForUser ( newEmail ) ;
} )
. then ( urlLink => {
cy . clearSessionData ( ) . visit ( urlLink ) ;
fillUpSetPassword ( password ) ;
cy . clearSessionData ( ) ;
} ) ;
cy . clearSessionData ( ) . loginUserViaRequest ( "auth" , {
email : newEmail ,
password : Cypress . env ( "USER_PASSWORD" ) ,
} ) ;
2023-01-25 12:32:30 +00:00
cy . visit ( urlList . staffMembers ) . get ( LOGIN _SELECTORS . userMenu ) . click ( ) ;
2022-12-23 10:30:21 +00:00
cy . get ( LOGIN _SELECTORS . accountSettings ) . click ( ) ;
2023-03-09 08:18:07 +00:00
cy . get ( STAFF _MEMBER _DETAILS _SELECTORS . staffFirstName )
. clear ( )
. type ( "สมชาย" ) ;
cy . get ( STAFF _MEMBER _DETAILS _SELECTORS . staffLastName )
. clear ( )
. type ( newLastName ) ;
cy . get ( STAFF _MEMBER _DETAILS _SELECTORS . staffEmail )
. clear ( )
. type ( changedEmail ) ;
2022-12-23 10:30:21 +00:00
// Test blocked from this point by https://github.com/saleor/saleor-dashboard/issues/2847
cy . get ( BUTTON _SELECTORS . confirm ) . confirmationMessageShouldAppear ( ) ;
cy . clearSessionData ( ) . loginUserViaRequest ( "auth" , {
email : changedEmail ,
password : Cypress . env ( "USER_PASSWORD" ) ,
} ) ;
cy . visit ( urlList . staffMembers ) ;
expectWelcomeMessageIncludes ( ` ${ changedName } ` ) ;
} ,
) ;
it (
"should create new user and successfully change password. TC: SALEOR_3510" ,
2023-05-23 07:51:36 +00:00
{ tags : [ "@staffMembers" , "@allEnv" , "@critical" ] } ,
2022-12-23 10:30:21 +00:00
( ) => {
const newPass = "newTestPass" ;
const newLastName = faker . name . lastName ( ) ;
const newEmail = ` ${ startsWith } ${ newLastName } @example.com ` ;
inviteStaffMemberWithFirstPermission ( { email : newEmail } )
. then ( ( { user : userResp } ) => {
user = userResp ;
getMailActivationLinkForUser ( newEmail ) ;
} )
. then ( urlLink => {
cy . clearSessionData ( ) . visit ( urlLink ) ;
fillUpSetPassword ( password ) ;
cy . clearSessionData ( ) ;
} ) ;
cy . clearSessionData ( ) . loginUserViaRequest ( "auth" , {
email : newEmail ,
password : Cypress . env ( "USER_PASSWORD" ) ,
} ) ;
2023-01-25 12:32:30 +00:00
cy . visit ( urlList . staffMembers ) . get ( LOGIN _SELECTORS . userMenu ) . click ( ) ;
2022-12-23 10:30:21 +00:00
cy . get ( LOGIN _SELECTORS . accountSettings ) . click ( ) ;
2023-05-23 07:51:36 +00:00
cy . get ( STAFF _MEMBER _DETAILS _SELECTORS . changePasswordBtn ) . should (
"be.visible" ,
) ;
// there is small bug which keep control panel opens and block any interaction via cypress - it does not affect real user - click on body can be removed when this pr is done https://github.com/saleor/saleor-dashboard/issues/3675
cy . get ( SHARED _ELEMENTS . body ) . click ( { force : true } ) ;
2023-03-09 08:18:07 +00:00
cy . get ( STAFF _MEMBER _DETAILS _SELECTORS . changePasswordBtn ) . click ( ) ;
cy . get (
STAFF _MEMBER _DETAILS _SELECTORS . changePasswordModal . oldPassword ,
) . type ( Cypress . env ( "USER_PASSWORD" ) ) ;
cy . get (
STAFF _MEMBER _DETAILS _SELECTORS . changePasswordModal . newPassword ,
) . type ( newPass ) ;
2023-05-23 07:51:36 +00:00
cy . addAliasToGraphRequest ( "ChangeUserPassword" )
. get ( BUTTON _SELECTORS . submit )
. click ( )
. confirmationMessageShouldAppear ( )
. waitForRequestAndCheckIfNoErrors ( "@ChangeUserPassword" ) ;
2022-12-23 10:30:21 +00:00
cy . clearSessionData ( ) . loginUserViaRequest ( "auth" , {
email : newEmail ,
password : newPass ,
} ) ;
2023-05-23 07:51:36 +00:00
cy . visit ( urlList . homePage )
. get ( HOMEPAGE _SELECTORS . welcomeMessage )
. should ( "be.visible" ) ;
cy . get ( HOMEPAGE _SELECTORS . activity ) . should ( "be.visible" ) ;
cy . get ( HOMEPAGE _SELECTORS . topProducts ) . should ( "be.visible" ) ;
2022-12-23 10:30:21 +00:00
} ,
) ;
2021-07-23 09:46:44 +00:00
} ) ;