Skip to content

Commit

Permalink
PI-1555 added document endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
stevomcallister committed Oct 13, 2023
1 parent 79fd947 commit 5cd282c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class DataLoader(
referralRepository.save(ReferralGenerator.EXISTING_REFERRAL)

documentRepository.save(DocumentGenerator.EVENT_DOC)
documentRepository.save(DocumentGenerator.PERSON_DOC)

probationCaseDataLoader.loadData()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit 5cd282c

Please sign in to comment.