From 27adf6f5661fc4ce126eab717f521fcbd2936998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Gardien?= Date: Tue, 7 Jan 2025 12:31:35 +0100 Subject: [PATCH] Add tests --- .../api/adherent_zone_based_roles.feature | 40 +++++++++++++++++++ src/Entity/AdherentZoneBasedRole.php | 5 +++ src/Entity/Geo/Zone.php | 2 +- .../AdministratorActionHistorySubscriber.php | 2 +- 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 features/api/adherent_zone_based_roles.feature diff --git a/features/api/adherent_zone_based_roles.feature b/features/api/adherent_zone_based_roles.feature new file mode 100644 index 00000000000..2fa38259e36 --- /dev/null +++ b/features/api/adherent_zone_based_roles.feature @@ -0,0 +1,40 @@ +@api +@debug +Feature: + In order to manage adherent mandates + As a logged-in user + I should be able to access adherent mandates API + + Scenario Outline: As a user granted with local scope, I can create an adherent zone based role + Given I am logged with "" via OAuth client "JeMengage Web" with scope "jemengage_admin" + And I send a "POST" request to "/api/v3/zone_based_role?scope=" with body: + """ + { + "adherent": "d0a0935f-da7c-4caa-b582-a8c2376e5158", + "type": "deputy", + "zones": ["e3efe6fd-906e-11eb-a875-0242ac150002"] + } + """ + Then the response status code should be 201 + And the response should be in JSON + And the JSON should be equal to: + """ + { + "type": "deputy", + "adherent": { + "uuid": "d0a0935f-da7c-4caa-b582-a8c2376e5158", + "zones": [ + { + "uuid": "@uuid@" + } + ] + }, + "uuid": "@uuid@", + "zones": [] + } + """ + + Examples: + | user | scope | + | referent@en-marche-dev.fr | president_departmental_assembly | + | senateur@en-marche-dev.fr | delegated_08f40730-d807-4975-8773-69d8fae1da74 | diff --git a/src/Entity/AdherentZoneBasedRole.php b/src/Entity/AdherentZoneBasedRole.php index 413a24bc6f4..9a1d3814a30 100644 --- a/src/Entity/AdherentZoneBasedRole.php +++ b/src/Entity/AdherentZoneBasedRole.php @@ -119,6 +119,11 @@ public function setType(?string $type): void $this->type = $type; } + public function getAdherent(): ?Adherent + { + return $this->adherent; + } + public function setAdherent(Adherent $adherent): void { $this->adherent = $adherent; diff --git a/src/Entity/Geo/Zone.php b/src/Entity/Geo/Zone.php index 8feadd4b47b..4d9e89df28c 100644 --- a/src/Entity/Geo/Zone.php +++ b/src/Entity/Geo/Zone.php @@ -95,7 +95,7 @@ class Zone implements GeoInterface, UuidEntityInterface * @var UuidInterface */ #[ApiProperty(identifier: true, openapiContext: ['type' => 'string', 'format' => 'uuid', 'example' => 'b4219d47-3138-5efd-9762-2ef9f9495084'])] - #[Groups(['zone_read', 'survey_write_dc', 'scopes', 'scope', 'jecoute_news_read_dc', 'audience_read', 'audience_segment_read', 'phoning_campaign_read', 'survey_list_dc', 'survey_read_dc', 'team_read', 'team_list_read', 'pap_campaign_read', 'pap_campaign_read_after_write', 'phoning_campaign_read', 'phoning_campaign_list', 'department_site_read', 'department_site_read_list', 'elected_representative_read', 'elected_representative_list', 'formation_list_read', 'formation_read', 'formation_write', 'elected_mandate_read', 'adherent_elect_read', 'general_meeting_report_list_read', 'general_meeting_report_read', 'committee:read', 'managed_users_list', 'managed_user_read', 'procuration_request_read', 'procuration_request_list', 'procuration_proxy_list', 'procuration_matched_proxy', 'general_meeting_report_write', 'elected_mandate_write', 'action_read', 'department_site_write', 'committee:write', 'audience_write', 'profile_read'])] + #[Groups(['zone_read', 'survey_write_dc', 'scopes', 'scope', 'jecoute_news_read_dc', 'audience_read', 'audience_segment_read', 'phoning_campaign_read', 'survey_list_dc', 'survey_read_dc', 'team_read', 'team_list_read', 'pap_campaign_read', 'pap_campaign_read_after_write', 'phoning_campaign_read', 'phoning_campaign_list', 'department_site_read', 'department_site_read_list', 'elected_representative_read', 'elected_representative_list', 'formation_list_read', 'formation_read', 'formation_write', 'elected_mandate_read', 'adherent_elect_read', 'general_meeting_report_list_read', 'general_meeting_report_read', 'committee:read', 'managed_users_list', 'managed_user_read', 'procuration_request_read', 'procuration_request_list', 'procuration_proxy_list', 'procuration_matched_proxy', 'general_meeting_report_write', 'elected_mandate_write', 'action_read', 'department_site_write', 'committee:write', 'audience_write', 'profile_read', 'zone_based_role_read'])] #[ORM\Column(type: 'uuid', unique: true)] protected $uuid; diff --git a/src/History/Listener/AdministratorActionHistorySubscriber.php b/src/History/Listener/AdministratorActionHistorySubscriber.php index f084ba976c6..a03f0f01f1c 100644 --- a/src/History/Listener/AdministratorActionHistorySubscriber.php +++ b/src/History/Listener/AdministratorActionHistorySubscriber.php @@ -87,7 +87,7 @@ public function onKernelResponse(ResponseEvent $event): void $request = $event->getRequest(); $routeName = $request->get('_route'); - if (!preg_match('/^admin_(.)+_export$/', $routeName)) { + if (!$routeName || !preg_match('/^admin_(.)+_export$/', $routeName)) { return; }