Skip to content

Commit

Permalink
Stronger tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ewan Donovan committed Feb 26, 2025
1 parent 5869602 commit 034308b
Showing 1 changed file with 87 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,94 @@ class SubjectAccessRequestIntegrationTest : IntegrationTestBase() {
.expectStatus().isOk
.expectBody()
.jsonPath("$.content").isArray
.jsonPath("$.content[0].nomisId").isEqualTo("A12345")
.jsonPath("$.content[1].nomisId").doesNotExist()
.jsonPath("$.content[0].givenName").isEqualTo("Jonathan")
.jsonPath("$.content[1]").doesNotExist()
}

@Test
fun `should return data if prisoner exists and a fromDate is specified`() {
val today = LocalDate.now()
val fromDate = today.minusDays(10)
val toDate = today.plusDays(20)

val validExact = today.atStartOfDay()
val invalidBefore = fromDate.minusDays(1).atStartOfDay()

val entitiesToSave = listOf(
MatchEntity(null, "A12345", "765", "Jon", "Test", dateCreated = invalidBefore),
MatchEntity(null, "A12345", "3213", "Jonathan", "Test", dateCreated = validExact),
MatchEntity(null, "A12345", "3213", "John", "Test", dateCreated = validExact.plusDays(5)),
)

matchRepository.saveAll(entitiesToSave)

webTestClient.get().uri("/subject-access-request?prn=A12345&fromDate=$fromDate&toDate=$toDate")
.headers(setAuthorisation(roles = listOf("ROLE_SAR_DATA_ACCESS")))
.exchange()
.expectStatus().isOk
.expectBody()
.jsonPath("$.content").isArray
.jsonPath("$.content[0].givenName").isEqualTo("Jonathan")
.jsonPath("$.content[1].givenName").isEqualTo("John")
.jsonPath("$.content[2]").doesNotExist()
}

@Test
fun `should return data if prisoner exists and a toDate is specified`() {
val today = LocalDate.now()
val fromDate = today.minusDays(10)
val toDate = today.plusDays(20)

val validExact = today.atStartOfDay()
val invalidAfter = toDate.plusDays(1).atStartOfDay()

val entitiesToSave = listOf(
MatchEntity(null, "A12345", "3213", "Jonathan", "Test", dateCreated = validExact.minusDays(5)),
MatchEntity(null, "A12345", "3213", "John", "Test", dateCreated = validExact),
MatchEntity(null, "A12345", "765", "Jon", "Test", dateCreated = invalidAfter),
)

matchRepository.saveAll(entitiesToSave)

webTestClient.get().uri("/subject-access-request?prn=A12345&fromDate=$fromDate&toDate=$toDate")
.headers(setAuthorisation(roles = listOf("ROLE_SAR_DATA_ACCESS")))
.exchange()
.expectStatus().isOk
.expectBody()
.jsonPath("$.content").isArray
.jsonPath("$.content[0].givenName").isEqualTo("Jonathan")
.jsonPath("$.content[1].givenName").isEqualTo("John")
.jsonPath("$.content[2]").doesNotExist()
}
}

@Nested
inner class SadPath {

@Autowired
lateinit var matchRepository: MatchRepository

@BeforeEach
fun clearRepository() {
matchRepository.deleteAll()
}

@Test
fun `should return no content if no data exists`() {
webTestClient.get().uri("/subject-access-request?prn=A12345")
.headers(setAuthorisation(roles = listOf("ROLE_SAR_DATA_ACCESS")))
.exchange()
.expectStatus().isNoContent
}

@Test
fun `should return 209 status if wrong identifier is supplied`() {
webTestClient.get().uri("/subject-access-request?crn=123456")
.headers(setAuthorisation(roles = listOf("ROLE_SAR_DATA_ACCESS")))
.exchange()
.expectStatus()
.isEqualTo(209)
}
}
}
}

// Try using the old code, with the param fixed

0 comments on commit 034308b

Please sign in to comment.