-
Notifications
You must be signed in to change notification settings - Fork 202
/
workflow_test.go
31 lines (27 loc) · 963 Bytes
/
workflow_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package saga
import (
"errors"
"testing"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.temporal.io/sdk/testsuite"
)
func Test_Workflow(t *testing.T) {
testSuite := &testsuite.WorkflowTestSuite{}
env := testSuite.NewTestWorkflowEnvironment()
// Mock activity implementation
testDetails := TransferDetails{
Amount: 1.00,
FromAccount: "001-001",
ToAccount: "002-002",
ReferenceID: "1234",
}
env.OnActivity(Withdraw, mock.Anything, testDetails).Return(nil)
env.OnActivity(WithdrawCompensation, mock.Anything, testDetails).Return(nil)
env.OnActivity(Deposit, mock.Anything, testDetails).Return(nil)
env.OnActivity(DepositCompensation, mock.Anything, testDetails).Return(nil)
env.OnActivity(StepWithError, mock.Anything, testDetails).Return(errors.New("some error"))
env.ExecuteWorkflow(TransferMoney, testDetails)
require.True(t, env.IsWorkflowCompleted())
require.Error(t, env.GetWorkflowError())
}