<?xml version="1.0" encoding="UTF-8"?>
<!--
 /**
  * Copyright © Magento, Inc. All rights reserved.
  * See COPYING.txt for license details.
  */
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
    <test name="StorefrontResetCustomerPasswordFailedTest">
        <annotations>
            <features value="Customer"/>
            <stories value="Reset password"/>
            <title value="Customer tries to reset password several times"/>
            <description value="Customer tries to reset password several times"/>
            <severity value="CRITICAL" />
            <testCaseId value="MC-14374" />
            <group value="Customer"/>
            <group value="security"/>
            <group value="mtf_migrated"/>
            <group value="pr_exclude"/>
        </annotations>
        <before>
            <magentoCLI command="config:set {{StorefrontCustomerCaptchaDisableConfigData.path}} {{StorefrontCustomerCaptchaDisableConfigData.value}}" stepKey="disableCaptcha"/>
            <magentoCLI command="config:set customer/password/password_reset_protection_type 3" stepKey="setProtectionOnEmail"/>
            <magentoCLI command="config:set customer/password/min_time_between_password_reset_requests 30" stepKey="increaseThresholdBetweenRequests"/>
            <createData stepKey="customer" entity="Simple_US_Customer"/>
        </before>
        <after>
            <!-- Preferred `Use system value` which is not available from CLI -->
            <magentoCLI command="config:set customer/password/password_reset_protection_type 1" stepKey="setDefaultProtection"/>
            <magentoCLI command="config:set customer/password/min_time_between_password_reset_requests 30" stepKey="setDefaultThresholdBetweenRequests"/>
            <magentoCLI command="config:set {{StorefrontCustomerCaptchaEnableConfigData.path}} {{StorefrontCustomerCaptchaEnableConfigData.value}}" stepKey="enableCaptcha"/>
            <deleteData stepKey="deleteCustomer" createDataKey="customer" />
        </after>

        <actionGroup ref="StorefrontCustomerResetPasswordActionGroup" stepKey="resetPasswordFirstAttempt">
            <argument name="email" value="$$customer.email$$" />
        </actionGroup>
        <actionGroup ref="AssertCustomerResetPasswordActionGroup" stepKey="seePageWithSuccessMessage">
            <argument name="url" value="{{StorefrontCustomerSignInPage.url}}"/>
            <argument name="message" value="If there is an account associated with $$customer.email$$ you will receive an email with a link to reset your password."/>
        </actionGroup>
        <actionGroup ref="StorefrontCustomerResetPasswordActionGroup" stepKey="resetPasswordSecondAttempt">
            <argument name="email" value="$$customer.email$$" />
        </actionGroup>
        <actionGroup ref="AssertCustomerResetPasswordActionGroup" stepKey="seePageWithErrorMessage">
            <argument name="url" value="{{StorefrontForgotPasswordPage.url}}"/>
            <argument name="message" value="We received too many requests for password resets. Please wait and try again later or contact hello@example.com."/>
            <argument name="messageType" value="error" />
        </actionGroup>
    </test>
</tests>
