From 15a0697f61861daaaaa00ed4fd5f960781b40f00 Mon Sep 17 00:00:00 2001 From: agonzalez-r Date: Thu, 19 Dec 2024 13:14:18 -0600 Subject: [PATCH] test: add tests for `acceptAlert()` and `unacceptAlert()` --- .../model/alert/AlertViewModelTest.kt | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/app/src/test/java/com/android/periodpals/model/alert/AlertViewModelTest.kt b/app/src/test/java/com/android/periodpals/model/alert/AlertViewModelTest.kt index cca0bb4c2..f3c75b6d5 100644 --- a/app/src/test/java/com/android/periodpals/model/alert/AlertViewModelTest.kt +++ b/app/src/test/java/com/android/periodpals/model/alert/AlertViewModelTest.kt @@ -540,6 +540,41 @@ class AlertViewModelTest { assertEquals(alert, viewModel.selectedAlert.value) } + @Test + fun acceptAlertSuccess() = runBlocking { + doAnswer { it.getArgument<(List) -> Unit>(0)(alerts) } + .`when`(alertModelSupabase) + .getAllAlerts(any<(List) -> Unit>(), any<(Exception) -> Unit>()) + val n = Random.nextInt(EXAMPLES) + val alert = alerts[n] + + viewModel.fetchAlerts() + assert(viewModel.palAlerts.value.contains(alert)) + assert(viewModel.acceptedAlerts.value.isEmpty()) + viewModel.acceptAlert(alert) + assertEquals(listOf(alert), viewModel.acceptedAlerts.value) + assert(!viewModel.palAlerts.value.contains(alert)) + } + + @Test + fun unAcceptAlertSuccess() = runBlocking { + doAnswer { it.getArgument<(List) -> Unit>(0)(alerts) } + .`when`(alertModelSupabase) + .getAllAlerts(any<(List) -> Unit>(), any<(Exception) -> Unit>()) + val n = Random.nextInt(EXAMPLES) + val alert = alerts[n] + + viewModel.fetchAlerts() + assert(viewModel.acceptedAlerts.value.isEmpty()) + viewModel.acceptAlert(alert) + assertEquals(listOf(alert), viewModel.acceptedAlerts.value) + assert(!viewModel.palAlerts.value.contains(alert)) + + viewModel.unAcceptAlert(alert) + assert(viewModel.acceptedAlerts.value.isEmpty()) + assert(viewModel.palAlerts.value.contains(alert)) + } + @Test fun formStateContainsCorrectFields() { val formState = viewModel.formState