Skip to content

Commit

Permalink
modify test to verify no null atributes are present in the response
Browse files Browse the repository at this point in the history
  • Loading branch information
Elmacioro committed Jan 9, 2025
1 parent 7f0981d commit 9e45096
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,27 +129,40 @@ class ProcessesResourcesSpec
}
}

test("/api/processes should return lighter details without ProcessAction's additional fields") {
test("/api/processes should return lighter details without ProcessAction's additional fields and null values") {
def hasNullAttributes(json: Json): Boolean = {
json.fold(
jsonNull = true, // null found
jsonBoolean = _ => false,
jsonNumber = _ => false,
jsonString = _ => false,
jsonArray = _.exists(hasNullAttributes),
jsonObject = _.values.exists(hasNullAttributes)
)
}
createDeployedScenario(processName, category = Category1)
Get(s"/api/processes") ~> withReaderUser() ~> applicationRoute ~> check {
status shouldEqual StatusCodes.OK
val loadedProcess = responseAs[List[ScenarioWithDetails]]

loadedProcess.head.lastAction should matchPattern {
// verify that unnecessary fields were omitted
val decodedScenarios = responseAs[List[ScenarioWithDetails]]
decodedScenarios.head.lastAction should matchPattern {
case Some(
ProcessAction(_, _, _, _, _, _, _, _, None, None, None, buildInfo)
) if buildInfo.isEmpty =>
}
loadedProcess.head.lastStateAction should matchPattern {
decodedScenarios.head.lastStateAction should matchPattern {
case Some(
ProcessAction(_, _, _, _, _, _, _, _, None, None, None, buildInfo)
) if buildInfo.isEmpty =>
}
loadedProcess.head.lastDeployedAction should matchPattern {
decodedScenarios.head.lastDeployedAction should matchPattern {
case Some(
ProcessAction(_, _, _, _, _, _, _, _, None, None, None, buildInfo)
) if buildInfo.isEmpty =>
}
// verify that null values were not present in JSON response
val rawFetchedScenarios = responseAs[Json]
hasNullAttributes(rawFetchedScenarios) shouldBe false
}
}

Expand Down

0 comments on commit 9e45096

Please sign in to comment.