From dc4b6b6bc13d3b30c904fef95193d0bb6426004e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Gardien?= Date: Fri, 3 Jun 2022 16:13:35 +0200 Subject: [PATCH] JME users can become adherents --- features/admin/adherent.feature | 80 ++++++++++++++++++- src/Entity/Adherent.php | 1 + .../EmailPersisterEventSubscriber.php | 1 + .../AdherentResetPasswordHandler.php | 2 +- tests/Test/Geocoder/DummyGeocoder.php | 4 + 5 files changed, 83 insertions(+), 5 deletions(-) diff --git a/features/admin/adherent.feature b/features/admin/adherent.feature index e72307da929..9d2a0dd21a9 100644 --- a/features/admin/adherent.feature +++ b/features/admin/adherent.feature @@ -1,18 +1,90 @@ @app Feature: Manage adherent from admin panel - Background: - When I am logged as "superadmin@en-marche-dev.fr" admin - Scenario: Display list of adherents + Given I am logged as "superadmin@en-marche-dev.fr" admin When I am on "/admin/app/adherent/list" Then the response status code should be 200 And I should see 32 "tbody tr" elements And I should see 14 "thead tr th" elements Scenario: A user update must trigger an event in RabbitMQ - Given I am on "/admin/app/adherent/list" + Given I am logged as "superadmin@en-marche-dev.fr" admin + When I am on "/admin/app/adherent/list" And I follow "SCHMIDT" And I clean the "api_sync" queue When I press "Mettre à jour" Then the response status code should be 200 + + @debug + Scenario: + As an administrator, I can manually register a user from another app. + The adherent can then change his password on the platform + Given I am logged as "superadmin@en-marche-dev.fr" admin + When I am on "/admin/app/adherent/list" + And I fill in the following: + | filter[emailAddress][value] | je-mengage-user-1@en-marche-dev.fr | + When I press "Filtrer" + Then I should be on "/admin/app/adherent/list" + And I should see "Jules Fullstack" + And I follow "EM" + Then I should be on "/" + + And I follow "Adhérer" + Then I should be on "/adhesion" + And I check "become_adherent[conditions]" + When I press "Je rejoins La République En Marche" + Then I should be on "/espace-adherent/accueil" + And I should see "Votre compte adhérent est maintenant actif." + Then I go to "/deconnexion" + Then I should be on "/" + + Then I follow "Connexion" + And I fill in the following: + | _login_email | je-mengage-user-1@en-marche-dev.fr | + | _login_password | secret!12345 | + And I press "Connexion" + And I should be on "/evenements" + Then I go to "/deconnexion" + Then I should be on "/" + + Then I follow "Connexion" + Then I should be on "/connexion" + And I should have 0 email + Then I follow "Mot de passe oublié ? Cliquez ici" + Then I should be on "/mot-de-passe-oublie" + And I fill in the following: + | form[email] | je-mengage-user-1@en-marche-dev.fr | + And I press "Envoyer un e-mail" + Then I should be on "/connexion" + And I should see "Si l'adresse que vous avez saisie est valide, un e-mail vous a été envoyé contenant un lien pour réinitialiser votre mot de passe." + And I should have 1 email + And I should have 1 email "AdherentResetPasswordMessage" for "je-mengage-user-1@en-marche-dev.fr" with payload: + """ + { + "template_name": "adherent-reset-password, + "template_content": [], + "message": { + "subject": "Réinitialisation de votre mot de passe", + "from_email": "contact@en-marche.fr", + "from_name": "La République En Marche !", + "global_merge_vars": [ + { + "name": "first_name", + "content": "Jules" + }, + { + "name": "reset_link", + "content": "http://enmarche.code/changer-mot-de-passe/@string@/@string@" + } + ], + "to": [ + { + "email": "je-mengage-user-1@en-marche-dev.fr", + "type": "to", + "name": "Jules Fullstack" + } + ] + } + } + """ diff --git a/src/Entity/Adherent.php b/src/Entity/Adherent.php index 69b7a2e1d36..03e4ae3619a 100644 --- a/src/Entity/Adherent.php +++ b/src/Entity/Adherent.php @@ -2173,6 +2173,7 @@ public function isUser(): bool public function join(): void { + $this->source = null; $this->adherent = true; } diff --git a/src/Mailer/EventSubscriber/EmailPersisterEventSubscriber.php b/src/Mailer/EventSubscriber/EmailPersisterEventSubscriber.php index d30657f582d..04bd06ccbd8 100644 --- a/src/Mailer/EventSubscriber/EmailPersisterEventSubscriber.php +++ b/src/Mailer/EventSubscriber/EmailPersisterEventSubscriber.php @@ -35,6 +35,7 @@ public function onMailerDeliveryMessage(MailerEvent $event): void $email = Email::createFromMessage($message, $emailTemplate->getHttpRequestPayload()); + dd($email); $this->manager->persist($email); $this->manager->flush(); $this->manager->detach($email); diff --git a/src/Membership/AdherentResetPasswordHandler.php b/src/Membership/AdherentResetPasswordHandler.php index ed3c34da49e..6ff6c2ad9db 100644 --- a/src/Membership/AdherentResetPasswordHandler.php +++ b/src/Membership/AdherentResetPasswordHandler.php @@ -63,7 +63,7 @@ public function reset(Adherent $adherent, AdherentResetPasswordToken $token, str $this->manager->flush(); - if (null === $adherent->getSource()) { + if (null === $adherent->getSource() || $adherent->isAdherent()) { $this->mailer->sendMessage(AdherentResetPasswordConfirmationMessage::createFromAdherent($adherent)); } else { if ($hasBeenActivated) { diff --git a/tests/Test/Geocoder/DummyGeocoder.php b/tests/Test/Geocoder/DummyGeocoder.php index ebdfa63b021..60391358166 100644 --- a/tests/Test/Geocoder/DummyGeocoder.php +++ b/tests/Test/Geocoder/DummyGeocoder.php @@ -129,6 +129,10 @@ class DummyGeocoder implements Geocoder 'latitude' => 48.5278939, 'longitude' => 2.6484923, ], + '2 avenue jean jaurès, 77000 melun, france' => [ + 'latitude' => 48.5278939, + 'longitude' => 2.6484923, + ], '30 boulevard louis guichoux, 13003 marseille 3e, fr' => [ 'latitude' => 43.325900, 'longitude' => 5.374680,