-
Notifications
You must be signed in to change notification settings - Fork 0
/
interactor_test.go
42 lines (33 loc) · 962 Bytes
/
interactor_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
32
33
34
35
36
37
38
39
40
41
42
package interactor_test
import (
"context"
"errors"
"testing"
"github.com/screwyprof/interactor/v2"
. "github.com/screwyprof/interactor/v2/testdsl"
)
func TestInteractorAcceptance(t *testing.T) {
t.Parallel()
t.Run("ensure use case returns an error", func(t *testing.T) {
t.Parallel()
want := errors.New("some error")
useCaseRunner := &ConcreteUseCase{err: want}
adaptedUseCaseRunner := interactor.MustAdapt(useCaseRunner)
Test(t)(
Given(adaptedUseCaseRunner.Run),
When(context.Background(), TestRequest{}, &TestResponse{}),
ThenFailWith(want),
)
})
t.Run("ensure use case returns valid result", func(t *testing.T) {
t.Parallel()
want := &TestResponse{result: 123}
useCaseRunner := &ConcreteUseCase{}
adaptedUseCaseRunner := interactor.Must(interactor.Func(useCaseRunner.Run))
Test(t)(
Given(adaptedUseCaseRunner.Run),
When(context.Background(), TestRequest{123}, &TestResponse{}),
Then(want),
)
})
}