Feature: User functionality
I as admin
Will create a new user

@auth @deleteuser @logout
Scenario: Creating and editing New user with Sun-Strategy domain
	Given I create a new user
		| Mail                     | FirstName | MiddleNames | LastName | Domain       |
		| tww44@inbox.testmail.app | Wolfgang  | Amadeus     | Mozart   | Sun-Strategy |
	And I logout
	When I click on the Link in the sent email
	Then I enter a new password and confirm it
		| Password  |
		| Pa55W()rD |
	And I successfully login with new credentials and I do not see the login page anymore
	When I edit an existing user
		| EditedFirstName | EditedMiddleNames | EditedLastName | Password       |
		| Test QA Edit    | Middle QA Edit    | User-1 QA Edit | Pa55W()rD12345 |
	And I logout
	Then I successfully login with new credentials and I do not see the login page anymore
	And I logout
	When I login as Admin
	Then I check edited data on edit user page
	And I check Users Audit logs
		| Timing | UserName | Comment | EntityDisplayName    | Type   | DisplayName          | Changes |
		|        |          |         | scenarioDataInstance | Update | scenarioDataInstance |         |

@auth @deleteuser @logout
Scenario: Creating and editing New user with Sun-Strategy domain 2FA
	Given I create a new user
		| Mail                     | FirstName | MiddleNames | LastName | Domain       |
		| tww44@inbox.testmail.app | Wolfgang  | Amadeus     | Mozart   | Sun-Strategy |
	And I logout
	When I click on the Link in the sent email
	Then I enter a new password and confirm it and add 2FA
		| Password  | MFA  |
		| Pa55W()rD | true |
	And I successfully login with new credentials and 2FA
	When I edit an existing user
		| EditedFirstName | EditedMiddleNames | EditedLastName | MFA   |
		| Test QA Edit    | Middle QA Edit    | User-1 QA Edit | false |
	Then I logout
	And I successfully login with new credentials and I do not see the login page anymore
	And I logout
	When I login as Admin
	Then I check edited data on edit user page
	And I check Users Audit logs
		| Timing | UserName | Comment | EntityDisplayName    | Type   | DisplayName          | Changes |
		|        |          |         | scenarioDataInstance | Update | scenarioDataInstance |         |

@auth @createuser @logout
Scenario: Creating a new user by API and delete user and check audit log
	Then I check Users Audit logs
		| Timing | UserName | Comment | EntityDisplayName    | Type   | DisplayName          | Changes |
		|        |          |         | scenarioDataInstance | Create | scenarioDataInstance |         |
	When I delete existing user
	Then I check Users Audit logs
		| Timing | UserName | Comment | EntityDisplayName    | Type   | DisplayName          | Changes |
		|        |          |         | scenarioDataInstance | Delete | scenarioDataInstance |         |

@createdomain @deleteuserapi @deletedomain @logout
Scenario: Admin user can't delete himself
	Given I create a new user via API
	When I click on the Link in the sent email
	Then I enter a new password and confirm it
		| Password  |
		| Pa55W()rD |
	And I assign Admin role to the user
	And I successfully login with new credentials and I do not see the login page anymore
	When I try to delete existing user
	Then I can't delete myself

#@auth @logout
#Scenario: Creating a new user by API and Reset Password
#	Given I create a new user through an API call
#	| Mail                       | FirstName | MiddleNames | LastName | Domain       |
#	| apiuser@inbox.testmail.app | Test      | API         | User     | Sun-Strategy |
#	When I click on the Link in the sent email
#	Then I enter a new password and confirm it
#	| Password  | FormMessage                                            |
#	| Pa55W()rD | Success, your e-mail is confirmed. You can now log in. |
#	When I logout
#	Then I am resetting the password for the newly created user
#	When I click on the Link in the reset password email
#	Then I enter a new password and save it
#	| Password     |
#	| Reset@123456 |
#	Then I successfully login with new credentials and I do not see the login page anymore