-
Notifications
You must be signed in to change notification settings - Fork 0
Dev/dd 41915 #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dev/dd 41915 #116
Changes from 8 commits
a0da268
3640e04
2f79aa4
676a735
301b6f1
9a3dbb2
a7b9dea
6a7da69
d908299
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "id": "http://moj.gov.uk/cpp/results/domain/event/results.event.migrated-inactive-nces-fin-acccount-number-absent.json", | ||
Iamfrenzy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "type": "object", | ||
| "properties": { | ||
| "masterDefendantId": { | ||
| "$ref": "http://justice.gov.uk/domain/core/common/definitions.json#/definitions/uuid" | ||
| }, | ||
| "defendantId": { | ||
| "$ref": "http://justice.gov.uk/domain/core/common/definitions.json#/definitions/uuid" | ||
| }, | ||
| "caseId": { | ||
| "$ref": "http://justice.gov.uk/domain/core/common/definitions.json#/definitions/uuid" | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| import static org.hamcrest.CoreMatchers.allOf; | ||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.containsString; | ||
| import static org.junit.jupiter.api.Assertions.fail; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.eq; | ||
|
|
@@ -18,6 +19,7 @@ | |
| import static uk.gov.justice.services.test.utils.core.matchers.JsonEnvelopeMetadataMatcher.metadata; | ||
| import static uk.gov.justice.services.test.utils.core.matchers.JsonEnvelopePayloadMatcher.payloadIsJson; | ||
| import static uk.gov.justice.services.test.utils.core.messaging.MetadataBuilderFactory.metadataWithRandomUUID; | ||
| import static uk.gov.moj.cpp.results.event.processor.StagingEnforcementAcknowledgmentEventProcessor.FINA_ACCOUNT_NOT_PRESENT; | ||
|
|
||
| import uk.gov.justice.services.core.sender.Sender; | ||
| import uk.gov.justice.services.messaging.Envelope; | ||
|
|
@@ -186,6 +188,7 @@ public void shouldCallUpdatecorrelationId() { | |
|
|
||
| } | ||
|
|
||
|
|
||
| @Test | ||
| void shouldProcessSendNcesMailForNewApplication() { | ||
| // GIVEN | ||
|
|
@@ -218,10 +221,12 @@ void shouldProcessSendNcesMailForNewApplication() { | |
| // THEN | ||
| verify(progressionService).getInactiveMigratedCasesByCaseIds(List.of(caseId1, caseId2, caseId3)); | ||
|
|
||
| verify(sender, times(4)).sendAsAdmin(envelopeArgumentCaptor.capture()); | ||
| // Updated to 5: (3 from Case1 + 1 from Case2 + 1 Final Notification) | ||
Iamfrenzy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| verify(sender, times(5)).sendAsAdmin(envelopeArgumentCaptor.capture()); | ||
|
|
||
| List<Envelope<JsonObject>> allEnvelopes = envelopeArgumentCaptor.getAllValues(); | ||
|
|
||
| // 0: Case 1 - Garfield (12345) | ||
|
||
| assertThat(JsonEnvelope.envelopeFrom(allEnvelopes.get(0).metadata(), allEnvelopes.get(0).payload()), | ||
| jsonEnvelope( | ||
| metadata().withName("result.command.send-migrated-inactive-nces-email-for-application"), | ||
|
|
@@ -236,6 +241,7 @@ void shouldProcessSendNcesMailForNewApplication() { | |
| withJsonPath("$.migratedMasterDefendantCourtEmailAndFineAccount.originalDateOfConviction", is("09/11/2025, 10/11/2025")) | ||
| )))); | ||
|
|
||
| // 1: Case 1 - Junior (54321) | ||
|
||
| assertThat(JsonEnvelope.envelopeFrom(allEnvelopes.get(1).metadata(), allEnvelopes.get(1).payload()), | ||
| jsonEnvelope( | ||
| metadata().withName("result.command.send-migrated-inactive-nces-email-for-application"), | ||
|
|
@@ -247,7 +253,19 @@ void shouldProcessSendNcesMailForNewApplication() { | |
| withJsonPath("$.migratedMasterDefendantCourtEmailAndFineAccount.defendantEmail", is("junior@gmail.com")) | ||
| )))); | ||
|
|
||
| // 2: Case 1 - Jane (NOT PRESENT) | ||
|
||
| assertThat(JsonEnvelope.envelopeFrom(allEnvelopes.get(2).metadata(), allEnvelopes.get(2).payload()), | ||
| jsonEnvelope( | ||
| metadata().withName("result.command.send-migrated-inactive-nces-email-for-application"), | ||
| payloadIsJson(allOf( | ||
| withJsonPath("$.migratedMasterDefendantCourtEmailAndFineAccount.caseId", is(caseId1)), | ||
| withJsonPath("$.migratedMasterDefendantCourtEmailAndFineAccount.fineAccountNumber", is(FINA_ACCOUNT_NOT_PRESENT)), | ||
| withJsonPath("$.migratedMasterDefendantCourtEmailAndFineAccount.defendantName", is("Jane Dare")), | ||
| withJsonPath("$.migratedMasterDefendantCourtEmailAndFineAccount.defendantEmail", is("jane.dare@gmail.com")) | ||
| )))); | ||
|
|
||
| // 3: Case 2 - Garfield (67890) | ||
Iamfrenzy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assertThat(JsonEnvelope.envelopeFrom(allEnvelopes.get(3).metadata(), allEnvelopes.get(3).payload()), | ||
| jsonEnvelope( | ||
| metadata().withName("result.command.send-migrated-inactive-nces-email-for-application"), | ||
| payloadIsJson(allOf( | ||
|
|
@@ -256,6 +274,65 @@ void shouldProcessSendNcesMailForNewApplication() { | |
| withJsonPath("$.migratedMasterDefendantCourtEmailAndFineAccount.defendantName", is("Garfield Dare")) | ||
| )))); | ||
|
|
||
| // 4: Final notification | ||
Iamfrenzy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assertThat(allEnvelopes.get(4).metadata().name(), is("result.command.send-nces-email-for-application")); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldProcessSendNcesMailForNewApplicationWhenDefendantFineAccountNumbersMissing() { | ||
| // GIVEN | ||
| final String masterDefendantId = "1a9176f4-3adc-4ea1-a808-26c4632f38ab"; | ||
| final String caseId1 = "b00acc1c-eb69-4b3c-960e-76be9153125a"; | ||
| final String caseId2 = "7776f4-3adc-4ea1-a808-26c4632f38ab"; | ||
| final String caseId3 = "b10acc1c-eb69-4b3c-960e-76be9153125a"; | ||
| final String hearingCourtCentreId = "faa91bb2-19cb-384b-bcc1-06d31d12cc67"; | ||
|
|
||
| final JsonObject notificationPayload = createObjectBuilder() | ||
| .add("masterDefendantId", masterDefendantId) | ||
| .add("caseIds", createCaseIds(caseId1, caseId2, caseId3)) | ||
| .add("hearingCourtCentreId", hearingCourtCentreId) | ||
| .build(); | ||
|
|
||
| final JsonObject progressionResponse = getPayload("inactive-migrated-cases-without-defendant-fine-account-numbers.json"); | ||
|
|
||
| when(progressionService.getInactiveMigratedCasesByCaseIds(List.of(caseId1, caseId2, caseId3))) | ||
| .thenReturn(Optional.of(progressionResponse)); | ||
|
|
||
| final JsonObject payload = getPayload("organisation-units.json"); | ||
| when(referenceDataService.getOrganisationUnit(eq(hearingCourtCentreId), any())).thenReturn(payload); | ||
|
|
||
| final JsonEnvelope event = JsonEnvelope.envelopeFrom( | ||
| metadataWithRandomUUID("public.hearing.nces-email-notification-for-application"), notificationPayload); | ||
|
|
||
| // WHEN | ||
| stagingEnforcementAcknowledgmentEventProcessor.processSendNcesMailForNewApplication(event); | ||
|
|
||
| // THEN | ||
| verify(progressionService).getInactiveMigratedCasesByCaseIds(List.of(caseId1, caseId2, caseId3)); | ||
|
|
||
| // UPDATED: 2 from Case 1 (NOT PRESENT) + 1 from Case 2 + 1 Final = 4 total | ||
Iamfrenzy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| verify(sender, times(4)).sendAsAdmin(envelopeArgumentCaptor.capture()); | ||
|
|
||
| List<Envelope<JsonObject>> allEnvelopes = envelopeArgumentCaptor.getAllValues(); | ||
|
|
||
| // 0: Case 1 - Garfield (NOT PRESENT) | ||
| assertThat(allEnvelopes.get(0).payload().getJsonObject("migratedMasterDefendantCourtEmailAndFineAccount").getString("fineAccountNumber"), is(FINA_ACCOUNT_NOT_PRESENT)); | ||
| assertThat(allEnvelopes.get(0).payload().getJsonObject("migratedMasterDefendantCourtEmailAndFineAccount").getString("caseId"), is(caseId1)); | ||
|
|
||
| // 1: Case 1 - Junior (NOT PRESENT) | ||
| assertThat(allEnvelopes.get(1).payload().getJsonObject("migratedMasterDefendantCourtEmailAndFineAccount").getString("fineAccountNumber"), is(FINA_ACCOUNT_NOT_PRESENT)); | ||
| assertThat(allEnvelopes.get(1).payload().getJsonObject("migratedMasterDefendantCourtEmailAndFineAccount").getString("defendantName"), containsString("Junior")); | ||
|
|
||
| // 2: Case 2 - Garfield (67890) | ||
Iamfrenzy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assertThat(JsonEnvelope.envelopeFrom(allEnvelopes.get(2).metadata(), allEnvelopes.get(2).payload()), | ||
| jsonEnvelope( | ||
| metadata().withName("result.command.send-migrated-inactive-nces-email-for-application"), | ||
| payloadIsJson(allOf( | ||
| withJsonPath("$.migratedMasterDefendantCourtEmailAndFineAccount.caseId", is(caseId2)), | ||
| withJsonPath("$.migratedMasterDefendantCourtEmailAndFineAccount.fineAccountNumber", is("67890")) | ||
| )))); | ||
|
|
||
| // 3: Final command | ||
Iamfrenzy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assertThat(allEnvelopes.get(3).metadata().name(), is("result.command.send-nces-email-for-application")); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.