diff --git a/STDatabase/src/commonTest/kotlin/com/infomaniak/multiplatform_swisstransfer/database/TransferControllerTest.kt b/STDatabase/src/commonTest/kotlin/com/infomaniak/multiplatform_swisstransfer/database/TransferControllerTest.kt index 31778f83..413b3bce 100644 --- a/STDatabase/src/commonTest/kotlin/com/infomaniak/multiplatform_swisstransfer/database/TransferControllerTest.kt +++ b/STDatabase/src/commonTest/kotlin/com/infomaniak/multiplatform_swisstransfer/database/TransferControllerTest.kt @@ -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 @@ -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()) + } }