Skip to content

Commit

Permalink
Merge pull request #3851 from nationalarchives/add-unit-tests-for-dra…
Browse files Browse the repository at this point in the history
…ft-metadata-upload

Add unit tests related to errors for the draft metadata upload
  • Loading branch information
vimleshtna authored Apr 18, 2024
2 parents add503e + 027f2b7 commit 1227b47
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/controllers/DraftMetadataUploadControllerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ class DraftMetadataUploadControllerSpec extends FrontEndTestHelper {
pageAsString must include("<title>Page not found - Transfer Digital Records - GOV.UK</title>")
}

"return a redirect to the auth server with an unauthenticated user" in {
val controller = instantiateDraftMetadataUploadController(securityComponents = getUnauthorisedSecurityComponents, blockDraftMetadataUpload = false)

val draftMetadataUploadPage = controller
.draftMetadataUploadPage(consignmentId)
.apply(FakeRequest(GET, "/draft-metadata/upload").withCSRFToken)

playStatus(draftMetadataUploadPage) mustBe FOUND
redirectLocation(draftMetadataUploadPage).get must startWith("/auth/realms/tdr/protocol/openid-connect/auth")
}

"return forbidden if the pages are accessed by a judgment user" in {
setConsignmentTypeResponse(wiremockServer, "judgment")
setConsignmentReferenceResponse(wiremockServer)
val controller = instantiateDraftMetadataUploadController(keycloakConfiguration = getValidJudgmentUserKeycloakConfiguration, blockDraftMetadataUpload = false)
val draftMetadataUploadPage = controller
.draftMetadataUploadPage(consignmentId)
.apply(FakeRequest(GET, "/draft-metadata/upload").withCSRFToken)

playStatus(draftMetadataUploadPage) mustBe FORBIDDEN
}

"redirect to draft metadata checks page when upload successful" in {
val uploadServiceMock = mock[UploadService]
val putObjectResponse = PutObjectResponse.builder().eTag("testEtag").build()
Expand Down

0 comments on commit 1227b47

Please sign in to comment.