Skip to content

Commit

Permalink
fix: delete id for comrequests and status from get requests
Browse files Browse the repository at this point in the history
  • Loading branch information
davdarras committed Sep 12, 2024
1 parent 0e611fa commit 3bbe260
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@

/**
* Record representing a CommunicationRequestResponseDto
* @param id The ID of the communication request
* @param communicationTemplateId configuration id of the communication
* @param reason The reason for the communication request
* @param emitter The emitter of the communication request
* @param status The status of the communication request
*/
public record CommunicationRequestResponseDto(
Long id,
Long communicationTemplateId,
CommunicationRequestReason reason,
CommunicationRequestEmitter emitter,
Expand All @@ -31,7 +29,7 @@ public static List<CommunicationRequestResponseDto> fromModel(Set<CommunicationR
List<CommunicationRequestStatusDto> status = request.status().stream()
.map(CommunicationRequestStatusDto::fromModel)
.toList();
return new CommunicationRequestResponseDto(request.id(),
return new CommunicationRequestResponseDto(
request.communicationTemplateId(),
request.reason(),
request.emitter(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
/**
* Record representing a CommunicationRequestStatusDto
*
* @param id The ID of the communication request status
* @param date The date of the communication request status
* @param status The status type of the communication request
*/
public record CommunicationRequestStatusDto(
Long id,
Long date,
CommunicationStatusType status) {

Expand All @@ -22,16 +20,6 @@ public record CommunicationRequestStatusDto(
* @return A new CommunicationRequestStatusDto instance.
*/
public static CommunicationRequestStatusDto fromModel(CommunicationRequestStatus requestStatus) {
return new CommunicationRequestStatusDto(requestStatus.id(), requestStatus.date(), requestStatus.status());
}

/**
* Converts a CommunicationRequestStatusDto to a CommunicationRequestStatus model.
*
* @param requestStatus The CommunicationRequestStatusDto to convert.
* @return A new CommunicationRequestStatus model instance.
*/
public static CommunicationRequestStatus toModel(CommunicationRequestStatusDto requestStatus) {
return new CommunicationRequestStatus(requestStatus.id(), requestStatus.date(), requestStatus.status());
return new CommunicationRequestStatusDto(requestStatus.date(), requestStatus.status());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,21 @@ void testCreateCommunicationRequests01() {
SurveyUnitDetailDto surveyUnitDetailDto = new SurveyUnitDetailDto(surveyUnit);

List<CommunicationRequestStatusDto> status1Expected = List.of(
new CommunicationRequestStatusDto(null, 1233456789L, CommunicationStatusType.INITIATED),
new CommunicationRequestStatusDto(2L, 123345678910L, CommunicationStatusType.FAILED)
new CommunicationRequestStatusDto(1233456789L, CommunicationStatusType.INITIATED),
new CommunicationRequestStatusDto(123345678910L, CommunicationStatusType.FAILED)
);

List<CommunicationRequestStatusDto> status2Expected = List.of(
new CommunicationRequestStatusDto(3L, 123345678911L, CommunicationStatusType.READY),
new CommunicationRequestStatusDto(4L, 123345678912L, CommunicationStatusType.CANCELLED)
new CommunicationRequestStatusDto(123345678911L, CommunicationStatusType.READY),
new CommunicationRequestStatusDto(123345678912L, CommunicationStatusType.CANCELLED)
);

assertThat(surveyUnitDetailDto.getCommunicationRequests())
.containsExactlyInAnyOrder(
new CommunicationRequestResponseDto(10L, 1L,
new CommunicationRequestResponseDto(1L,
CommunicationRequestReason.UNREACHABLE,
CommunicationRequestEmitter.INTERVIEWER, status1Expected),
new CommunicationRequestResponseDto(11L, 2L,
new CommunicationRequestResponseDto(2L,
CommunicationRequestReason.REFUSAL,
CommunicationRequestEmitter.TOOL, status2Expected)
);
Expand Down
253 changes: 125 additions & 128 deletions src/test/java/fr/insee/pearljam/integration/surveyunit/SurveyUnitIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,41 +227,34 @@ void testGetSurveyUnitDetail() throws Exception {
},
"communicationRequests":[
{
"id":2,
"communicationTemplateId":2,
"reason":"UNREACHABLE",
"emitter":"INTERVIEWER",
"status":[
{
"id":4,
"date":1721903754305,
"status":"INITIATED"
},
{
"id":5,
"date":1721903756310,
"status":"READY"
}
]
},
{
"id":1,
"communicationTemplateId":1,
"reason":"REFUSAL",
"emitter":"INTERVIEWER",
"status":[
{
"id":1,
"date":1721903754305,
"status":"INITIATED"
},
{
"id":2,
"date":1721903755305,
"status":"READY"
},
{
"id":3,
"date":1721903756305,
"status":"SUBMITTED"
}
Expand Down Expand Up @@ -393,139 +386,143 @@ void testPutSurveyUnitDetail() throws Exception {

String resultJson = result.getResponse().getContentAsString();
String expectedJson = """
{
"id":"20",
"persons":[
{
"id":"20",
"persons":[
"id":10,
"title":"MISTER",
"firstName":"Harriette",
"lastName":"Raymond",
"email":"[email protected]",
"birthdate":11111111,
"favoriteEmail":true,
"privileged":true,
"phoneNumbers":[
{
"id":10,
"title":"MISTER",
"firstName":"Harriette",
"lastName":"Raymond",
"email":"[email protected]",
"birthdate":11111111,
"favoriteEmail":true,
"privileged":true,
"phoneNumbers":[
{
"source":"FISCAL",
"favorite":true,
"number":"test"
}
]
"source":"FISCAL",
"favorite":true,
"number":"test"
}
],
"address":{
"l1":"test1",
"l2":"test2",
"l3":"test3",
"l4":"test4",
"l5":"test5",
"l6":"test6",
"l7":"test7",
"elevator":true,
"building":"testBuilding",
"floor":"testFloor",
"door":"testDoor",
"staircase":"testStaircase",
"cityPriorityDistrict":true
},
"priority":false,
"campaign":"VQS2021X00",
"comments":[
{
"type":"MANAGEMENT",
"value":"test-management-comment"
},
]
}
],
"address":{
"l1":"test1",
"l2":"test2",
"l3":"test3",
"l4":"test4",
"l5":"test5",
"l6":"test6",
"l7":"test7",
"elevator":true,
"building":"testBuilding",
"floor":"testFloor",
"door":"testDoor",
"staircase":"testStaircase",
"cityPriorityDistrict":true
},
"priority":false,
"campaign":"VQS2021X00",
"comments":[
{
"type":"INTERVIEWER",
"value":"test-interviewer-comment"
},
{
"type":"MANAGEMENT",
"value":"test-management-comment"
}
],
"sampleIdentifiers":{
"bs":20,
"ec":"2",
"le":20,
"noi":20,
"numfa":20,
"rges":20,
"ssech":1,
"nolog":20,
"nole":20,
"autre":"20",
"nograp":"20"
},
"states":[
{
"id":9,
"date":1590504478334,
"type":"VIC"
},
{
"id":13,
"date":1590504459838,
"type":"AOC"
}
],
"contactAttempts":[
{
"date":1589268626000,
"status":"NOC",
"medium":"TEL"
},
{
"date":1589268800000,
"status":"INA",
"medium":"TEL"
}
],
"contactOutcome":{
"date":1589268626000,
"type":"IMP",
"totalNumberOfContactAttempts":2
},
"communicationRequests":[
{
"communicationTemplateId":4,
"reason":"REFUSAL",
"emitter":"INTERVIEWER",
"status":[
{
"type":"INTERVIEWER",
"value":"test-interviewer-comment"
"date":1721903754305,
"status":"INITIATED"
}
],
"sampleIdentifiers":{
"bs":20,
"ec":"2",
"le":20,
"noi":20,
"numfa":20,
"rges":20,
"ssech":1,
"nolog":20,
"nole":20,
"autre":"20",
"nograp":"20"
},
"states":[
{
"id":9,
"date":1590504478334,
"type":"VIC"
},
{
"id":13,
"date":1590504459838,
"type":"AOC"
}
],
"contactAttempts":[
{
"date":1589268626000,
"status":"NOC",
"medium":"TEL"
},
]
},
{
"communicationTemplateId":4,
"reason":"UNREACHABLE",
"emitter":"INTERVIEWER",
"status":[
{
"date":1589268800000,
"status":"INA",
"medium":"TEL"
"date":1721903754205,
"status":"INITIATED"
}
],
"contactOutcome":{
"date":1589268626000,
"type":"IMP",
"totalNumberOfContactAttempts":2
},
"communicationRequests":[
{
"id":4,
"communicationTemplateId":4,
"reason":"UNREACHABLE",
"emitter":"INTERVIEWER",
"status":[
{
"id":7,
"date":1721903754205,
"status":"INITIATED"
}
]
},
]
},
{
"communicationTemplateId":5,
"reason":"UNREACHABLE",
"emitter":"INTERVIEWER",
"status":[
{
"id":3,
"communicationTemplateId":3,
"reason":"REFUSAL",
"emitter":"INTERVIEWER",
"status":[
{
"id":6,
"date":1721903754205,
"status":"INITIATED"
}
]
},
"date":1721903754405,
"status":"INITIATED"
}
]
},
{
"communicationTemplateId":3,
"reason":"REFUSAL",
"emitter":"INTERVIEWER",
"status":[
{
"id":5,
"communicationTemplateId":5,
"reason":"UNREACHABLE",
"emitter":"INTERVIEWER",
"status":[
{
"id":8,
"date":1721903754405,
"status":"INITIATED"
}
]
"date":1721903754205,
"status":"INITIATED"
}
]
}
""";
]
}""";
JSONAssert.assertEquals(expectedJson, resultJson, JSONCompareMode.NON_EXTENSIBLE);
}
}

0 comments on commit 3bbe260

Please sign in to comment.