Skip to content

Commit

Permalink
unknown error details and action message (#4271)
Browse files Browse the repository at this point in the history
* unknown error details and action message
  • Loading branch information
ian-hoyle authored Nov 12, 2024
1 parent e3951b7 commit e6bd3be
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 49 deletions.
2 changes: 2 additions & 0 deletions conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ draftMetadata.validation.details.SCHEMA_REQUIRED=There was at least one missing
draftMetadata.validation.action.SCHEMA_REQUIRED=Add the following column headers to your metadata file and re-load.
draftMetadata.validation.details.DUPLICATE_HEADER=There was at least one duplicate column in your metadata file.
draftMetadata.validation.action.DUPLICATE_HEADER=Ensure there is only one of the following duplicated columns.
draftMetadata.validation.details.UNKNOWN=An unknown error was identified.
draftMetadata.validation.action.UNKNOWN=Please contact your Digital Transfer Advisor on <a href="mailto:tdr@nationalarchives.gov.uk">tdr@nationalarchives.gov.uk</a> quoting the Consignment Reference.
98 changes: 49 additions & 49 deletions test/controllers/DraftMetadataChecksResultsControllerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ class DraftMetadataChecksResultsControllerSpec extends FrontEndTestHelper {
(
FailedValue.value,
FileError.UNKNOWN,
"Require details message for draftMetadata.validation.details.",
"Require action message for draftMetadata.validation.action.",
"An unknown error was identified.",
"Please contact your Digital Transfer Advisor on <a href=\"mailto:tdr@nationalarchives.gov.uk\">tdr@nationalarchives.gov.uk</a> quoting the Consignment Reference.",
Set[String]()
),
(
Expand Down Expand Up @@ -239,61 +239,61 @@ class DraftMetadataChecksResultsControllerSpec extends FrontEndTestHelper {
}
}
}
}

"downloadErrorReport" should {
"download the excel file with error data" in {

setConsignmentTypeResponse(wiremockServer, "standard")
setConsignmentReferenceResponse(wiremockServer)
val error = Error("BASE_SCHEMA", "FOI exemption code", "enum", "BASE_SCHEMA.foi_exmption_code.enum")
val metadata = List(Metadata("FOI exemption code", "abcd"), Metadata("Filepath", "/aa/bb/faq"))
val errorFileData = ErrorFileData(consignmentId, date = "2024-12-12", FileError.SCHEMA_VALIDATION, List(ValidationErrors("assetId", Set(error), metadata)))
val response = instantiateController(errorFileData = Some(errorFileData))
.downloadErrorReport(consignmentId)(FakeRequest(GET, s"/consignment/$consignmentId/draft-metadata/download-report"))

val responseByteArray: ByteString = contentAsBytes(response)
val bufferedSource = new ByteArrayInputStream(responseByteArray.toArray)
val wb: ReadableWorkbook = new ReadableWorkbook(bufferedSource)
val ws: Sheet = wb.getFirstSheet
val rows: List[Row] = ws.read.asScala.toList

rows.length must equal(2)

rows.head.getCell(0).asString must equal("Filepath")
rows.head.getCell(1).asString must equal("Field")
rows.head.getCell(2).asString must equal("Value")
rows.head.getCell(3).asString must equal("Error Message")

rows(1).getCell(0).asString must equal("/aa/bb/faq")
rows(1).getCell(1).asString must equal("FOI exemption code")
rows(1).getCell(2).asString must equal("abcd")
rows(1).getCell(3).asString must equal("BASE_SCHEMA.foi_exmption_code.enum")
}
"downloadErrorReport" should {
"download the excel file with error data" in {

"download the excel file without error data when the error type is not SCHEMA_VALIDATION" in {
setConsignmentTypeResponse(wiremockServer, "standard")
setConsignmentReferenceResponse(wiremockServer)
val error = Error("BASE_SCHEMA", "FOI exemption code", "enum", "BASE_SCHEMA.foi_exmption_code.enum")
val metadata = List(Metadata("FOI exemption code", "abcd"), Metadata("Filepath", "/aa/bb/faq"))
val errorFileData = ErrorFileData(consignmentId, date = "2024-12-12", FileError.SCHEMA_VALIDATION, List(ValidationErrors("assetId", Set(error), metadata)))
val response = instantiateController(errorFileData = Some(errorFileData))
.downloadErrorReport(consignmentId)(FakeRequest(GET, s"/consignment/$consignmentId/draft-metadata/download-report"))

val responseByteArray: ByteString = contentAsBytes(response)
val bufferedSource = new ByteArrayInputStream(responseByteArray.toArray)
val wb: ReadableWorkbook = new ReadableWorkbook(bufferedSource)
val ws: Sheet = wb.getFirstSheet
val rows: List[Row] = ws.read.asScala.toList

rows.length must equal(2)

rows.head.getCell(0).asString must equal("Filepath")
rows.head.getCell(1).asString must equal("Field")
rows.head.getCell(2).asString must equal("Value")
rows.head.getCell(3).asString must equal("Error Message")

rows(1).getCell(0).asString must equal("/aa/bb/faq")
rows(1).getCell(1).asString must equal("FOI exemption code")
rows(1).getCell(2).asString must equal("abcd")
rows(1).getCell(3).asString must equal("BASE_SCHEMA.foi_exmption_code.enum")
}

setConsignmentTypeResponse(wiremockServer, "standard")
setConsignmentReferenceResponse(wiremockServer)
val error = Error("FILE_VALIDATION", "draftmetadata.csv", "INVALID_CSV", "")
val errorFileData = ErrorFileData(consignmentId, date = "2024-12-12", FileError.INVALID_CSV, List(ValidationErrors("assetId", Set(error), Nil)))
"download the excel file without error data when the error type is not SCHEMA_VALIDATION" in {

when(draftMetaDataService.getErrorReport(any[UUID])).thenReturn(Future.successful(errorFileData))
setConsignmentTypeResponse(wiremockServer, "standard")
setConsignmentReferenceResponse(wiremockServer)
val error = Error("FILE_VALIDATION", "draftmetadata.csv", "INVALID_CSV", "")
val errorFileData = ErrorFileData(consignmentId, date = "2024-12-12", FileError.INVALID_CSV, List(ValidationErrors("assetId", Set(error), Nil)))

val response = instantiateController().downloadErrorReport(consignmentId)(FakeRequest(GET, s"/consignment/$consignmentId/draft-metadata/download-report"))
when(draftMetaDataService.getErrorReport(any[UUID])).thenReturn(Future.successful(errorFileData))

val responseByteArray: ByteString = contentAsBytes(response)
val bufferedSource = new ByteArrayInputStream(responseByteArray.toArray)
val wb: ReadableWorkbook = new ReadableWorkbook(bufferedSource)
val ws: Sheet = wb.getFirstSheet
val rows: List[Row] = ws.read.asScala.toList
val response = instantiateController().downloadErrorReport(consignmentId)(FakeRequest(GET, s"/consignment/$consignmentId/draft-metadata/download-report"))

rows.length must equal(1)
val responseByteArray: ByteString = contentAsBytes(response)
val bufferedSource = new ByteArrayInputStream(responseByteArray.toArray)
val wb: ReadableWorkbook = new ReadableWorkbook(bufferedSource)
val ws: Sheet = wb.getFirstSheet
val rows: List[Row] = ws.read.asScala.toList

rows.head.getCell(0).asString must equal("Filepath")
rows.head.getCell(1).asString must equal("Field")
rows.head.getCell(2).asString must equal("Value")
rows.head.getCell(3).asString must equal("Error Message")
}
rows.length must equal(1)

rows.head.getCell(0).asString must equal("Filepath")
rows.head.getCell(1).asString must equal("Field")
rows.head.getCell(2).asString must equal("Value")
rows.head.getCell(3).asString must equal("Error Message")
}
}

Expand Down

0 comments on commit e6bd3be

Please sign in to comment.