From 5cd282c3c9ad87c1e6736e1385a0c5a77bac26f5 Mon Sep 17 00:00:00 2001 From: stevomcallister Date: Fri, 13 Oct 2023 10:23:04 +0100 Subject: [PATCH] PI-1555 added document endpoints --- .../justice/digital/hmpps/data/DataLoader.kt | 1 + .../hmpps/data/generator/DocumentGenerator.kt | 20 ++++++++++++++++++- .../digital/hmpps/DocIntegrationTest.kt | 19 ++++++++++-------- .../digital/hmpps/DocumentIntegrationTest.kt | 2 +- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt index f743202bfa..49b5c87f20 100644 --- a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt +++ b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt @@ -196,6 +196,7 @@ class DataLoader( referralRepository.save(ReferralGenerator.EXISTING_REFERRAL) documentRepository.save(DocumentGenerator.EVENT_DOC) + documentRepository.save(DocumentGenerator.PERSON_DOC) probationCaseDataLoader.loadData() } diff --git a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/DocumentGenerator.kt b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/DocumentGenerator.kt index 8183fb69a7..4d2da81712 100644 --- a/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/DocumentGenerator.kt +++ b/projects/approved-premises-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/DocumentGenerator.kt @@ -4,11 +4,13 @@ import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.referra import uk.gov.justice.digital.hmpps.integrations.delius.document.entity.DocEvent import uk.gov.justice.digital.hmpps.integrations.delius.document.entity.DocumentType import uk.gov.justice.digital.hmpps.integrations.delius.document.entity.EventDocument +import uk.gov.justice.digital.hmpps.integrations.delius.document.entity.OffenderDocument import uk.gov.justice.digital.hmpps.integrations.delius.person.Person import java.time.ZonedDateTime object DocumentGenerator { val EVENT_DOC = generateEventDoc() + val PERSON_DOC = generatePersonDoc() fun generateEventDoc( event: Event = PersonGenerator.ANOTHER_EVENT, @@ -26,6 +28,22 @@ object DocumentGenerator { return doc } + fun generatePersonDoc( + id: Long = IdGenerator.getAndIncrement() + ): OffenderDocument { + val doc = OffenderDocument() + doc.id = id + doc.person = PersonGenerator.DEFAULT + doc.name = "offender.doc" + doc.primaryKeyId = PersonGenerator.DEFAULT.id + doc.alfrescoId = "uuid2" + doc.lastSaved = ZonedDateTime.now().minusDays(7) + doc.dateProduced = null + doc.type = DocumentType.DOCUMENT + + return doc + } + private fun Event.toDocEvent() = - DocEvent(id, Person(personId, "", false ), true, number, null, null) + DocEvent(id, Person(personId, "", false), true, number, null, null) } diff --git a/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/DocIntegrationTest.kt b/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/DocIntegrationTest.kt index 364ef10df7..0476a5d41c 100644 --- a/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/DocIntegrationTest.kt +++ b/projects/approved-premises-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/DocIntegrationTest.kt @@ -46,13 +46,16 @@ internal class DocIntegrationTest { fun `list documents`() { mockMvc.perform(get("/document/${PersonGenerator.DEFAULT.crn}/all").withOAuth2Token(wireMockserver)) .andExpect(status().isOk) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].id",Matchers.equalTo("uuid1"))) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].level",Matchers.equalTo("Conviction"))) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].eventNumber",Matchers.equalTo("8"))) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].filename",Matchers.equalTo("test.doc"))) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].typeCode",Matchers.equalTo("EVENT"))) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].typeDescription",Matchers.equalTo("Event"))) - - + .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.equalTo("uuid1"))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].level", Matchers.equalTo("Conviction"))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].eventNumber", Matchers.equalTo("8"))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].filename", Matchers.equalTo("test.doc"))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].typeCode", Matchers.equalTo("EVENT"))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].typeDescription", Matchers.equalTo("Event"))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].id", Matchers.equalTo("uuid2"))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].level", Matchers.equalTo("Offender"))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].filename", Matchers.equalTo("offender.doc"))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].typeCode", Matchers.equalTo("PERSON"))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].typeDescription", Matchers.equalTo("Person"))) } } diff --git a/projects/make-recall-decisions-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/DocumentIntegrationTest.kt b/projects/make-recall-decisions-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/DocumentIntegrationTest.kt index 4bd02378ef..86ae03197b 100644 --- a/projects/make-recall-decisions-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/DocumentIntegrationTest.kt +++ b/projects/make-recall-decisions-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/DocumentIntegrationTest.kt @@ -22,7 +22,7 @@ internal class DocumentIntegrationTest { @Test fun `document is downloaded`() { - mockMvc.perform(get("/document/A000001/uuid1").accept("application/octet-stream").withOAuth2Token(wireMockserver)) + mockMvc.perform(get("/document/X000004/uuid1").accept("application/octet-stream").withOAuth2Token(wireMockserver)) .andExpect(status().is2xxSuccessful) .andExpect(header().string("Content-Type", "application/octet-stream")) .andExpect(header().string("Content-Disposition", "attachment; filename=\"=?UTF-8?Q?doc1?=\"; filename*=UTF-8''doc1"))