feat(android): import private Shopee probe tasks
This commit is contained in:
+63
@@ -0,0 +1,63 @@
|
||||
package com.roubao.autopilot.workflow
|
||||
|
||||
import com.roubao.task.ProbeReferenceImage
|
||||
import com.roubao.task.ProbeTask
|
||||
import com.roubao.task.TaskSource
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class ProbeWorkflowCoordinatorTest {
|
||||
@Test
|
||||
fun `workflow consumes task source without knowing fixture implementation`() = runTest {
|
||||
val expectedTask = probeTask()
|
||||
val source = TaskSource { expectedTask }
|
||||
val runner = WorkflowRunner { AutomationResult.Success }
|
||||
val coordinator = ProbeWorkflowCoordinator(
|
||||
taskSource = source,
|
||||
workflowRunner = runner,
|
||||
stepsForTask = { task ->
|
||||
assertEquals(expectedTask.title, task.title)
|
||||
assertEquals(expectedTask.sku, task.sku)
|
||||
assertEquals(expectedTask.quantity, task.quantity)
|
||||
listOf(WorkflowStep("prepare_search", timeoutMillis = 1_000))
|
||||
}
|
||||
)
|
||||
|
||||
val result = coordinator.runNext() as ProbeWorkflowResult.Executed
|
||||
|
||||
assertEquals(expectedTask.probeId, result.probeId)
|
||||
assertEquals(WorkflowState.SUCCEEDED, result.report.state)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `empty task source does not start workflow`() = runTest {
|
||||
var automationCalls = 0
|
||||
val coordinator = ProbeWorkflowCoordinator(
|
||||
taskSource = TaskSource { null },
|
||||
workflowRunner = WorkflowRunner {
|
||||
automationCalls += 1
|
||||
AutomationResult.Success
|
||||
},
|
||||
stepsForTask = { listOf(WorkflowStep("unused", timeoutMillis = 1_000)) }
|
||||
)
|
||||
|
||||
assertEquals(ProbeWorkflowResult.NoTask, coordinator.runNext())
|
||||
assertEquals(0, automationCalls)
|
||||
}
|
||||
|
||||
private fun probeTask() = ProbeTask(
|
||||
probeId = "probe_0123456789abcdef",
|
||||
sourceOrderNo = "ORDER_000001",
|
||||
sourceStoreName = "Test Store",
|
||||
title = "Test Product",
|
||||
sku = "SKU-001",
|
||||
quantity = 1,
|
||||
referenceImage = ProbeReferenceImage(
|
||||
relativePath = "assets/0123456789abcdef.jpg",
|
||||
mediaType = "image/jpeg",
|
||||
sizeBytes = 123,
|
||||
sha256 = "a".repeat(64)
|
||||
)
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user