-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfilters_test.go
68 lines (58 loc) · 1.5 KB
/
filters_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package fsm
import (
"context"
"errors"
"testing"
"github.com/stretchr/testify/assert"
tele "gopkg.in/telebot.v3"
)
func TestDefaultFilterProcessor(t *testing.T) {
t.Run("error from State", func(t *testing.T) {
var caughtError error
testError := errors.New("test error")
fsm := new(MockContext)
fsm.EXPECT().
State(context.Background()).
Return(DefaultState, testError).
Once()
bot, err := tele.NewBot(tele.Settings{
Offline: true,
OnError: func(err error, context tele.Context) {
assert.ErrorIs(t, err, testError)
caughtError = err
},
})
assert.NoError(t, err, "creating new bot")
ctx := bot.NewContext(U)
status := DefaultFilterProcessor(ctx, fsm, StateFilter(func(state State) bool {
assert.Failf(
t,
"Unexpected call of state metcher",
"State matcher must be not called",
)
return false
}))
assert.False(t, status, "DefaultFilterProcess")
assert.ErrorIs(t, caughtError, testError, "Error from OnError handler")
})
t.Run("success process", func(t *testing.T) {
ctx := B.NewContext(U)
fsm := new(MockContext)
testState := State("test_state")
fsm.EXPECT().
State(context.Background()).
Return(testState, nil).
Once()
isMatcherCalled := false
status := DefaultFilterProcessor(
ctx,
fsm,
StateFilter(func(state State) bool {
isMatcherCalled = true
return AnyState.MatchState(state)
}),
)
assert.True(t, status, "DefaultFilterProcessor")
assert.True(t, isMatcherCalled, "call state matcher")
})
}