Skip to content

Commit

Permalink
test: Add unit test for transfer directions
Browse files Browse the repository at this point in the history
  • Loading branch information
sirambd committed Oct 15, 2024
1 parent 5b76207 commit 7ce311a
Showing 1 changed file with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,21 @@ class TransferControllerTest {

@Test
fun canGetTransfers() = runTest {
DummyTransfer.transfers.take(2).forEach { transfer ->
transferController.upsert(transfer, TransferDirection.SENT)
}
addTwoRandomTransfersInDatabase()
val transfers = transferController.getTransfers()
assertEquals(2, transfers?.count(), "The transfer list must contain 2 items")
}

@Test
fun canGetSentTransfers() = runTest {
canGetTransfersByDirection(TransferDirection.SENT)
}

@Test
fun canGetReceivedTransfers() = runTest {
canGetTransfersByDirection(TransferDirection.RECEIVED)
}

@Test
fun canUpdateAnExistingTransfer() = runTest {
// Insert a transfer
Expand Down Expand Up @@ -94,4 +102,19 @@ class TransferControllerTest {
assertEquals(sent, realmTransfer.transferDirection())
assertEquals(transfer.container?.uuid, realmTransfer.container?.uuid, "The container is missing")
}

private suspend fun addTwoRandomTransfersInDatabase() {
DummyTransfer.transfers.take(2).forEachIndexed { index, transfer ->
val transferDirection = if (index == 0) TransferDirection.SENT else TransferDirection.RECEIVED
transferController.upsert(transfer, transferDirection)
}
}

private suspend fun canGetTransfersByDirection(transferDirection: TransferDirection) {
addTwoRandomTransfersInDatabase()
val transfers = transferController.getTransfers(transferDirection)
assertNotNull(transfers)
assertEquals(1, transfers.count(), "The transfer list must contain 1 item")
assertEquals(transferDirection, transfers.first().transferDirection())
}
}

0 comments on commit 7ce311a

Please sign in to comment.