@@ -200,6 +200,27 @@ public function iTryToVerifyUsing(string $token): void
200200 $ this ->verifyAccount ($ token );
201201 }
202202
203+ /**
204+ * @When I resend the verification email
205+ */
206+ public function iResendVerificationEmail (): void
207+ {
208+ /** @var ShopUserInterface $user */
209+ $ user = $ this ->sharedStorage ->get ('user ' );
210+
211+ $ this ->resendVerificationEmail ($ user ->getEmail ());
212+ }
213+
214+ /**
215+ * @When I use the verification link from the first email to verify
216+ */
217+ public function iUseVerificationLinkFromFirstEmailToVerify (): void
218+ {
219+ $ token = $ this ->sharedStorage ->get ('verification_token ' );
220+
221+ $ this ->verifyAccount ($ token );
222+ }
223+
203224 /**
204225 * @When I register with email :email and password :password
205226 */
@@ -217,6 +238,14 @@ public function iShouldBeNotifiedThatItHasBeenSuccessfullyEdited(): void
217238 Assert::true ($ this ->responseChecker ->isUpdateSuccessful ($ this ->customerClient ->getLastResponse ()));
218239 }
219240
241+ /**
242+ * @Then I should be notified that the verification email has been sent
243+ */
244+ public function iShouldBeNotifiedThatTheVerificationEmailHasBeenSent (): void
245+ {
246+ Assert::same ($ this ->customerClient ->getLastResponse ()->getStatusCode (), 202 );
247+ }
248+
220249 /**
221250 * @Then my email should be :email
222251 * @Then my email should still be :email
@@ -419,14 +448,36 @@ public function iShouldBeNotifiedThatTheElementShouldBe(string $elementName, str
419448 * @Then my account should be verified
420449 */
421450 public function myAccountShouldBeVerified (): void
451+ {
452+ $ response = $ this ->getResponseWithAccountData ();
453+
454+ Assert::true ($ this ->responseChecker ->getResponseContent ($ response )['user ' ]['verified ' ]);
455+ }
456+
457+ /**
458+ * @Then /^(?:my|his|her) account should not be verified$/
459+ */
460+ public function myAccountShouldNotBeVerified (): void
461+ {
462+ $ response = $ this ->getResponseWithAccountData ();
463+
464+ Assert::false ($ this ->responseChecker ->getResponseContent ($ response )['user ' ]['verified ' ]);
465+ }
466+
467+ /**
468+ * @Then I should not be able to resend the verification email
469+ */
470+ public function iShouldBeUnableToResendVerificationEmail (): void
422471 {
423472 /** @var ShopUserInterface $user */
424473 $ user = $ this ->sharedStorage ->get ('user ' );
425- $ this ->loginContext ->iLogInAsWithPassword ($ user ->getEmail (), 'sylius ' );
426474
427- $ response = $ this ->customerClient -> show (( string ) $ user ->getCustomer ()-> getId ());
475+ $ this ->resendVerificationEmail ( $ user ->getEmail ());
428476
429- Assert::true ($ this ->responseChecker ->getResponseContent ($ response )['user ' ]['verified ' ]);
477+ Assert::same ($ this ->responseChecker ->getError ($ this ->customerClient ->getLastResponse ()),
478+ \sprintf ('Account with email %s is currently verified. ' , $ user ->getEmail ()),
479+ 'Validation message is different then expected. '
480+ );
430481 }
431482
432483 private function isViolationWithMessageInResponse (Response $ response , string $ message ): bool
@@ -464,4 +515,22 @@ private function registerAccount(?string $email = '
[email protected] ', ?string
464515
465516 $ this ->customerClient ->executeCustomRequest ($ request );
466517 }
518+
519+ private function resendVerificationEmail (string $ email ): void
520+ {
521+ $ request = Request::create ('shop ' , 'account-verification-requests ' , 'Bearer ' );
522+
523+ $ request ->setContent (['email ' => $ email ]);
524+
525+ $ this ->customerClient ->executeCustomRequest ($ request );
526+ }
527+
528+ private function getResponseWithAccountData (): Response
529+ {
530+ /** @var ShopUserInterface $user */
531+ $ user = $ this ->sharedStorage ->get ('user ' );
532+ $ this ->loginContext ->iLogInAsWithPassword ($ user ->getEmail (), 'sylius ' );
533+
534+ return $ this ->customerClient ->show ((string ) $ user ->getCustomer ()->getId ());
535+ }
467536}
0 commit comments