Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Remg committed Jan 7, 2025
1 parent 362ece4 commit 27adf6f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
40 changes: 40 additions & 0 deletions features/api/adherent_zone_based_roles.feature
Original file line number Diff line number Diff line change
@@ -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 "<user>" via OAuth client "JeMengage Web" with scope "jemengage_admin"
And I send a "POST" request to "/api/v3/zone_based_role?scope=<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 |
5 changes: 5 additions & 0 deletions src/Entity/AdherentZoneBasedRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Geo/Zone.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 27adf6f

Please sign in to comment.