Skip to content

Commit

Permalink
#118: test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lsulak committed Mar 28, 2024
1 parent 57aa01b commit bed8a55
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class DoobieMultipleResultFunctionWithStatusTest extends AnyFunSuite with Doobie
}

class GetActorsByLastname(implicit schema: DBSchema, dbEngine: DoobieEngine[IO])
extends DoobieMultipleResultFunctionWithStatus[GetActorsByLastnameQueryParameters, Actor, IO](getActorsByLastnameQueryFragments)
// Option[Actor] because: Actor might not exist, and the function would return only status info without actor data
extends DoobieMultipleResultFunctionWithStatus[GetActorsByLastnameQueryParameters, Option[Actor], IO](getActorsByLastnameQueryFragments)
with StandardStatusHandling {
override def fieldsToSelect: Seq[String] = super.fieldsToSelect ++ Seq("actor_id", "first_name", "last_name")
}
Expand Down Expand Up @@ -64,7 +65,7 @@ class DoobieMultipleResultFunctionWithStatusTest extends AnyFunSuite with Doobie
}

assert(actualData.length == 1)
assert(actualData.head == expectedResultElem)
assert(actualData.head.get == expectedResultElem)
}

test("Retrieving single actor from database, lastname match") {
Expand All @@ -77,12 +78,11 @@ class DoobieMultipleResultFunctionWithStatusTest extends AnyFunSuite with Doobie
}

assert(actualData.length == 1)
assert(actualData.head == expectedResultElem)
assert(actualData.head.get == expectedResultElem)
}

test("Retrieving non-existing actor from database, no match") {
val results = getActorsByLastname(GetActorsByLastnameQueryParameters("TotallyNonExisting!")).unsafeRunSync()
// TODO SQL `NULL` read at column 3 (JDBC type Integer) but mapping is to a non-Option type; !
results.map {
case Left(err) =>
assert(err.status.statusText == "No actor found")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
package za.co.absa.fadb.doobie

/**
* Represents a function status with data.
* Represents a function status with data (basically a row returned from a DB).
*
* Note: data here represent one row that has status-related fields omitted. In some scenarios, it actually might
* be missing - i.e. query returns only status information with no data - pretty common scenario when a DB
* function returns error, e.g.: (41, 'NoDataFound', NULL). In this case, R must be an Option - to be specified
* by a user.
*/
case class StatusWithData[R](status: Int, statusText: String, data: R)

0 comments on commit bed8a55

Please sign in to comment.