Skip to content

Commit 10d5a10

Browse files
Pierluigi D'UffiziPierluigi D'Uffizi
authored andcommitted
[SELC-7326] feat: add field toAddOnAggregates to createOrUpdateByFiscalCode and createOrUpdateByUserId api
1 parent 1b36979 commit 10d5a10

File tree

8 files changed

+96
-0
lines changed

8 files changed

+96
-0
lines changed

apps/user-ms/src/main/docs/openapi.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,9 @@
19011901
},
19021902
"delegationId" : {
19031903
"type" : "string"
1904+
},
1905+
"toAddOnAggregates" : {
1906+
"type" : "boolean"
19041907
}
19051908
}
19061909
},
@@ -1924,6 +1927,9 @@
19241927
"items" : {
19251928
"type" : "string"
19261929
}
1930+
},
1931+
"toAddOnAggregates" : {
1932+
"type" : "boolean"
19271933
}
19281934
}
19291935
},

apps/user-ms/src/main/docs/openapi.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,8 @@ components:
13761376
type: string
13771377
delegationId:
13781378
type: string
1379+
toAddOnAggregates:
1380+
type: boolean
13791381
Product1:
13801382
required:
13811383
- productId
@@ -1396,6 +1398,8 @@ components:
13961398
type: array
13971399
items:
13981400
type: string
1401+
toAddOnAggregates:
1402+
type: boolean
13991403
QueueEvent:
14001404
enum:
14011405
- ADD

apps/user-ms/src/main/java/it/pagopa/selfcare/user/controller/request/AddUserRoleDto.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,7 @@ public static class Product {
3737
private List<String> productRoles;
3838

3939
private String delegationId;
40+
41+
private Boolean toAddOnAggregates;
4042
}
4143
}

apps/user-ms/src/main/java/it/pagopa/selfcare/user/controller/request/CreateUserDto.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,7 @@ public static class Product {
5151

5252
@NotNull(message = "productRoles is required")
5353
private List<String> productRoles;
54+
55+
private Boolean toAddOnAggregates;
5456
}
5557
}

apps/user-ms/src/main/java/it/pagopa/selfcare/user/mapper/UserInstitutionMapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ default List<OnboardedProduct> toNewOnboardedProduct(CreateUserDto.Product produ
6060
onboardedProduct.setProductId(product.getProductId());
6161
onboardedProduct.setTokenId(product.getTokenId());
6262
onboardedProduct.setProductRole(role);
63+
onboardedProduct.setToAddOnAggregates(product.getToAddOnAggregates());
6364
if(StringUtils.isNotBlank(product.getRole())) {
6465
onboardedProduct.setRole(PartyRole.valueOf(product.getRole()));
6566
}
@@ -79,6 +80,7 @@ default List<OnboardedProduct> toNewOnboardedProductFromAddUserRole(AddUserRoleD
7980
onboardedProduct.setProductId(product.getProductId());
8081
onboardedProduct.setTokenId(product.getTokenId());
8182
onboardedProduct.setProductRole(role);
83+
onboardedProduct.setToAddOnAggregates(product.getToAddOnAggregates());
8284
if(StringUtils.isNotBlank(product.getRole())) {
8385
onboardedProduct.setRole(PartyRole.valueOf(product.getRole()));
8486
}

apps/user-ms/src/test/java/it/pagopa/selfcare/user/integration_test/steps/UserSteps.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import jakarta.enterprise.context.ApplicationScoped;
1414
import lombok.extern.slf4j.Slf4j;
1515
import org.bson.types.ObjectId;
16+
import org.junit.jupiter.api.Assertions;
1617

1718
import java.time.OffsetDateTime;
1819
import java.time.ZoneOffset;
@@ -222,4 +223,27 @@ public void createMockInstitutionWithUnusedUser(String id, String onboardedProdu
222223
e.printStackTrace();
223224
}
224225
}
226+
227+
@And("The userInstitution with field toAddOnAggregates {string} was saved")
228+
public void theUserInstitutionWithFieldToAddOnAggregatesWasSaved(String arg0) {
229+
boolean toAddOnAggregates = Boolean.parseBoolean(arg0);
230+
UserInstitution.find("institutionId = ?1", mockInstitutionId2)
231+
.firstResult()
232+
.subscribe()
233+
.with(
234+
success -> {
235+
UserInstitution userInstitution = (UserInstitution) success;
236+
if(!Objects.isNull(userInstitution)) {
237+
List<OnboardedProduct> products = userInstitution.getProducts();
238+
Assertions.assertNotNull(products, "Products list is null");
239+
Assertions.assertFalse(products.isEmpty(), "Products list is empty");
240+
OnboardedProduct product = products.get(0);
241+
Assertions.assertEquals(toAddOnAggregates, product.getToAddOnAggregates(), String.format("The field toAddOnAggregates differ. Expected: %s, Current %s", toAddOnAggregates, product.getToAddOnAggregates()));
242+
} else {
243+
log.info("No userInstitution with institutionId {}", mockInstitutionId2);
244+
}
245+
},
246+
failure -> log.info("Failed to find userInstitution with institutionId {}", mockInstitutionId2)
247+
);
248+
}
225249
}

apps/user-ms/src/test/resources/features/user.feature

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3050,6 +3050,32 @@ Feature: User
30503050
| userId | 97a511a7-2acc-47b9-afed-2f3c65753b4a |
30513051
When I send a POST request to "users/{userId}"
30523052
Then The status code is 401
3053+
3054+
@RemoveUserInstitutionAfterCreateFromAPI
3055+
Scenario: Successfully updated or created userInstitution by userId with a new role can be added to aggregates
3056+
Given User login with username "j.doe" and password "test"
3057+
And The following request body:
3058+
"""
3059+
{
3060+
"institutionId": "e3a4c8d2-5b79-4f3e-92d7-184a9b6fcd21",
3061+
"product": {
3062+
"productId": "prod-io",
3063+
"role": "DELEGATE",
3064+
"tokenId": "7a3df825-8317-4601-9fea-12283b7ed97f",
3065+
"productRoles": [
3066+
"referente amministrativo"
3067+
],
3068+
"toAddOnAggregates" : true
3069+
},
3070+
"institutionDescription": "Comune di Bergamo",
3071+
"userMailUuid": "ID_MAIL#81956dd1-00fd-4423-888b-f77a48d26ba1"
3072+
}
3073+
"""
3074+
And The following path params:
3075+
| userId | 97a511a7-2acc-47b9-afed-2f3c65753b4a |
3076+
When I send a POST request to "users/{userId}"
3077+
Then The status code is 201
3078+
And The userInstitution with field toAddOnAggregates "true" was saved
30533079
######################### END POST /{userId} #########################
30543080

30553081
######################### BEGIN POST /{userId}/onboarding #########################
@@ -3506,6 +3532,35 @@ Feature: User
35063532
| prod-io | admin | SUB_DELEGATE | ACTIVE | asda8312-3311-5642-gsds-gfr2252341 |
35073533
| prod-pagopa | referente amministrativo | MANAGER | ACTIVE | aa1112-5132-4432-gsds-d12322 |
35083534

3535+
@RemoveUserInstitutionWithMockUser3
3536+
Scenario: Successfully created a new user or updated an existing one can be added to aggregates
3537+
Given User login with username "j.doe" and password "test"
3538+
And The following request body:
3539+
"""
3540+
{
3541+
"institutionId": "e3a4c8d2-5b79-4f3e-92d7-184a9b6fcd21",
3542+
"hasToSendEmail": false,
3543+
"user": {
3544+
"fiscalCode": "VRDMRA22T71F205A",
3545+
"institutionEmail": "prova@email.com"
3546+
},
3547+
"product": {
3548+
"productId": "prod-io",
3549+
"role": "DELEGATE",
3550+
"tokenId": "7a3df825-8317-4601-9fea-12283b7ed97f",
3551+
"productRoles": [
3552+
"referente amministrativo"
3553+
],
3554+
"toAddOnAggregates" : true
3555+
},
3556+
"institutionDescription": "Comune di Bergamo",
3557+
"userMailUuid": "ID_MAIL#81956dd1-00fd-4423-888b-f77a48d26ba1"
3558+
}
3559+
"""
3560+
When I send a POST request to "users/"
3561+
Then The status code is 201
3562+
And The userInstitution with field toAddOnAggregates "true" was saved
3563+
35093564
@RemoveUserInstitutionAndUserInfoAfterScenario
35103565
Scenario: Unsuccessfully create a new user or update an existing one with ACTIVE status (existing userInstitution with existing product)
35113566
Given User login with username "j.doe" and password "test"

libs/user-sdk-model/src/main/java/it.pagopa.selfcare.user.model/OnboardedProduct.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ public class OnboardedProduct {
2525
private OffsetDateTime createdAt;
2626
private OffsetDateTime updatedAt;
2727
private String delegationId;
28+
private Boolean toAddOnAggregates;
2829
}

0 commit comments

Comments
 (0)