|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Spryker Commerce OS. |
|
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace PyzTest\Glue\Customer\RestApi; |
|
9
|
|
|
|
|
10
|
|
|
use Codeception\Example; |
|
11
|
|
|
use Generated\Shared\Transfer\CustomerTransfer; |
|
12
|
|
|
use Generated\Shared\Transfer\RestCustomerForgottenPasswordAttributesTransfer; |
|
13
|
|
|
use Generated\Shared\Transfer\RestErrorMessageTransfer; |
|
14
|
|
|
use PyzTest\Glue\Customer\CustomerApiTester; |
|
15
|
|
|
use Spryker\Glue\CustomersRestApi\CustomersRestApiConfig; |
|
16
|
|
|
use Spryker\Glue\RestRequestValidator\RestRequestValidatorConfig; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Auto-generated group annotations |
|
21
|
|
|
* |
|
22
|
|
|
* @group PyzTest |
|
23
|
|
|
* @group Glue |
|
24
|
|
|
* @group Customer |
|
25
|
|
|
* @group RestApi |
|
26
|
|
|
* @group CustomerForgottenPasswordCest |
|
27
|
|
|
* Add your own group annotations below this line |
|
28
|
|
|
* @group EndToEnd |
|
29
|
|
|
*/ |
|
30
|
|
|
class CustomerForgottenPasswordCest |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @var \PyzTest\Glue\Customer\RestApi\CustomerRestApiFixtures |
|
34
|
|
|
*/ |
|
35
|
|
|
protected CustomerRestApiFixtures $fixtures; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var \Generated\Shared\Transfer\CustomerTransfer |
|
39
|
|
|
*/ |
|
40
|
|
|
protected CustomerTransfer $customerTransfer; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param \PyzTest\Glue\Customer\CustomerApiTester $I |
|
44
|
|
|
* |
|
45
|
|
|
* @return void |
|
46
|
|
|
*/ |
|
47
|
|
|
public function _before(CustomerApiTester $I): void |
|
48
|
|
|
{ |
|
49
|
|
|
/** @var \PyzTest\Glue\Customer\RestApi\CustomerRestApiFixtures $fixtures */ |
|
50
|
|
|
$fixtures = $I->loadFixtures(CustomerRestApiFixtures::class); |
|
51
|
|
|
|
|
52
|
|
|
$this->fixtures = $fixtures; |
|
53
|
|
|
|
|
54
|
|
|
$this->customerTransfer = $I->haveCustomer( |
|
55
|
|
|
[ |
|
56
|
|
|
CustomerTransfer::NEW_PASSWORD => 'change123', |
|
57
|
|
|
CustomerTransfer::PASSWORD => 'change123', |
|
58
|
|
|
CustomerTransfer::RESTORE_PASSWORD_KEY => uniqid(), |
|
59
|
|
|
], |
|
60
|
|
|
); |
|
61
|
|
|
$I->confirmCustomer($this->customerTransfer); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @dataProvider requestPostCustomerForgottenPasswordFailsValidationDataProvider |
|
66
|
|
|
* |
|
67
|
|
|
* @param \PyzTest\Glue\Customer\CustomerApiTester $I |
|
68
|
|
|
* @param \Codeception\Example $example |
|
69
|
|
|
* |
|
70
|
|
|
* @return void |
|
71
|
|
|
*/ |
|
72
|
|
|
public function requestPostCustomerForgottenPasswordFailsValidation(CustomerApiTester $I, Example $example): void |
|
73
|
|
|
{ |
|
74
|
|
|
// Act |
|
75
|
|
|
$I->sendPost( |
|
76
|
|
|
$I->formatUrl(CustomersRestApiConfig::RESOURCE_FORGOTTEN_PASSWORD), |
|
77
|
|
|
[ |
|
78
|
|
|
'data' => [ |
|
79
|
|
|
'type' => CustomersRestApiConfig::RESOURCE_FORGOTTEN_PASSWORD, |
|
80
|
|
|
'attributes' => $example['attributes'], |
|
81
|
|
|
], |
|
82
|
|
|
], |
|
83
|
|
|
); |
|
84
|
|
|
|
|
85
|
|
|
// Assert |
|
86
|
|
|
$I->seeResponseCodeIs($example[RestErrorMessageTransfer::STATUS]); |
|
87
|
|
|
$I->seeResponseIsJson(); |
|
88
|
|
|
$I->seeResponseMatchesOpenApiSchema(); |
|
89
|
|
|
|
|
90
|
|
|
foreach ($example['errors'] as $index => $error) { |
|
91
|
|
|
$I->seeResponseErrorsHaveCode($error[RestErrorMessageTransfer::CODE], $index); |
|
92
|
|
|
$I->seeResponseErrorsHaveStatus($error[RestErrorMessageTransfer::STATUS], $index); |
|
93
|
|
|
$I->seeResponseErrorsHaveDetail($error[RestErrorMessageTransfer::DETAIL], $index); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return array |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function requestPostCustomerForgottenPasswordFailsValidationDataProvider(): array |
|
101
|
|
|
{ |
|
102
|
|
|
return [ |
|
103
|
|
|
[ |
|
104
|
|
|
'attributes' => [ |
|
105
|
|
|
RestCustomerForgottenPasswordAttributesTransfer::EMAIL => '', |
|
106
|
|
|
], |
|
107
|
|
|
RestErrorMessageTransfer::STATUS => Response::HTTP_UNPROCESSABLE_ENTITY, |
|
108
|
|
|
'errors' => [ |
|
109
|
|
|
[ |
|
110
|
|
|
RestErrorMessageTransfer::CODE => RestRequestValidatorConfig::RESPONSE_CODE_REQUEST_INVALID, |
|
111
|
|
|
RestErrorMessageTransfer::STATUS => Response::HTTP_UNPROCESSABLE_ENTITY, |
|
112
|
|
|
RestErrorMessageTransfer::DETAIL => 'email => This value should not be blank.', |
|
113
|
|
|
], |
|
114
|
|
|
], |
|
115
|
|
|
], |
|
116
|
|
|
]; |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|