diff --git a/android-app/app/src/test/java/com/korexlabs/dhinspeccion/domain/MobileWorkflowRulesTest.kt b/android-app/app/src/test/java/com/korexlabs/dhinspeccion/domain/MobileWorkflowRulesTest.kt new file mode 100644 index 0000000..8ef652a --- /dev/null +++ b/android-app/app/src/test/java/com/korexlabs/dhinspeccion/domain/MobileWorkflowRulesTest.kt @@ -0,0 +1,89 @@ +package com.korexlabs.dhinspeccion.domain + +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +class MobileWorkflowRulesTest { + @Test + fun plannedInspectionCanStartButRunningOrClosedCannot() { + assertTrue(MobileWorkflowRules.canStartInspection("PLANNED")) + assertFalse(MobileWorkflowRules.canStartInspection("IN_PROGRESS")) + assertFalse(MobileWorkflowRules.canStartInspection("CLOSED")) + } + + @Test + fun onlyOneDraftActIsAllowedPerInspection() { + assertFalse(MobileWorkflowRules.hasDraftAct(listOf("SEALED", "LOCKED"))) + assertTrue(MobileWorkflowRules.hasDraftAct(listOf("SEALED", "DRAFT", "LOCKED"))) + } + + @Test + fun creatingAnActRequiresRunningInspectionInventoryValidUrgencyAndNoDraft() { + assertTrue( + MobileWorkflowRules.canCreateAct( + visitStatus = "IN_PROGRESS", + actStatuses = listOf("SEALED", "LOCKED"), + hasSelectedInventory = true, + urgency = "NON_URGENT", + ), + ) + assertTrue( + MobileWorkflowRules.canCreateAct( + visitStatus = "IN_PROGRESS", + actStatuses = emptyList(), + hasSelectedInventory = true, + urgency = "URGENT", + ), + ) + assertFalse(MobileWorkflowRules.canCreateAct("PLANNED", emptyList(), true, "URGENT")) + assertFalse(MobileWorkflowRules.canCreateAct("IN_PROGRESS", listOf("DRAFT"), true, "URGENT")) + assertFalse(MobileWorkflowRules.canCreateAct("IN_PROGRESS", emptyList(), false, "URGENT")) + assertFalse(MobileWorkflowRules.canCreateAct("IN_PROGRESS", emptyList(), true, "UNKNOWN")) + } + + @Test + fun fieldInventoryCanOnlyBeCreatedWhileInspectionIsRunning() { + assertTrue(MobileWorkflowRules.canCreateFieldInventory("IN_PROGRESS")) + assertFalse(MobileWorkflowRules.canCreateFieldInventory("PLANNED")) + assertFalse(MobileWorkflowRules.canCreateFieldInventory("CLOSED")) + } + + @Test + fun findingsRequireRunningInspectionDraftActAndReadyInventory() { + assertTrue(MobileWorkflowRules.canRegisterFinding("IN_PROGRESS", "DRAFT", true)) + assertFalse(MobileWorkflowRules.canRegisterFinding("PLANNED", "DRAFT", true)) + assertFalse(MobileWorkflowRules.canRegisterFinding("IN_PROGRESS", "LOCKED", true)) + assertFalse(MobileWorkflowRules.canRegisterFinding("IN_PROGRESS", "DRAFT", false)) + assertFalse(MobileWorkflowRules.canRegisterFinding("IN_PROGRESS", null, true)) + } + + @Test + fun actCanOnlyLockFromDraftAfterResponsibleWasResolved() { + assertTrue(MobileWorkflowRules.canLockAct("DRAFT", true)) + assertFalse(MobileWorkflowRules.canLockAct("DRAFT", false)) + assertFalse(MobileWorkflowRules.canLockAct("LOCKED", true)) + assertFalse(MobileWorkflowRules.canLockAct("SEALED", true)) + } + + @Test + fun actCanOnlySealAfterInspectorAndCompanyOutcomeAreResolved() { + assertTrue(MobileWorkflowRules.canSealAct("LOCKED", true, "SIGNED")) + assertTrue(MobileWorkflowRules.canSealAct("LOCKED", true, "REFUSED")) + assertFalse(MobileWorkflowRules.canSealAct("DRAFT", true, "SIGNED")) + assertFalse(MobileWorkflowRules.canSealAct("LOCKED", false, "SIGNED")) + assertFalse(MobileWorkflowRules.canSealAct("LOCKED", true, null)) + assertFalse(MobileWorkflowRules.canSealAct("LOCKED", true, "ABSENT")) + } + + @Test + fun inspectionClosesOnlyWhenEveryNonCancelledActIsSealed() { + assertTrue(MobileWorkflowRules.canCloseInspection("IN_PROGRESS", listOf("SEALED"))) + assertTrue(MobileWorkflowRules.canCloseInspection("IN_PROGRESS", listOf("SEALED", "CANCELLED", "SEALED"))) + assertFalse(MobileWorkflowRules.canCloseInspection("IN_PROGRESS", emptyList())) + assertFalse(MobileWorkflowRules.canCloseInspection("IN_PROGRESS", listOf("CANCELLED"))) + assertFalse(MobileWorkflowRules.canCloseInspection("IN_PROGRESS", listOf("SEALED", "LOCKED"))) + assertFalse(MobileWorkflowRules.canCloseInspection("IN_PROGRESS", listOf("SEALED", "DRAFT"))) + assertFalse(MobileWorkflowRules.canCloseInspection("CLOSED", listOf("SEALED"))) + } +}