-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bcf37c1
commit 83d44c2
Showing
2 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
internal/connectors/matrix/actions/message/list_commands_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package message_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/CubicrootXYZ/gologger" | ||
"github.com/CubicrootXYZ/matrix-reminder-and-calendar-bot/internal/connectors/matrix/actions/message" | ||
matrixdb "github.com/CubicrootXYZ/matrix-reminder-and-calendar-bot/internal/connectors/matrix/database" | ||
"github.com/CubicrootXYZ/matrix-reminder-and-calendar-bot/internal/connectors/matrix/mautrixcl" | ||
"github.com/CubicrootXYZ/matrix-reminder-and-calendar-bot/internal/connectors/matrix/messenger" | ||
"github.com/CubicrootXYZ/matrix-reminder-and-calendar-bot/internal/connectors/matrix/tests" | ||
"github.com/CubicrootXYZ/matrix-reminder-and-calendar-bot/internal/database" | ||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestListCommandsAction(t *testing.T) { | ||
action := &message.ListCommandsAction{} | ||
|
||
assert.NotEmpty(t, action.Name()) | ||
|
||
title, desc, examples := action.GetDocu() | ||
assert.NotEmpty(t, title) | ||
assert.NotEmpty(t, desc) | ||
assert.NotEmpty(t, examples) | ||
|
||
assert.NotNil(t, action.Selector()) | ||
} | ||
|
||
func TestListCommandsAction_Selector(t *testing.T) { | ||
action := &message.ListCommandsAction{} | ||
r := action.Selector() | ||
|
||
_, _, examples := action.GetDocu() | ||
for _, example := range examples { | ||
assert.True(t, r.MatchString(example)) | ||
} | ||
} | ||
|
||
func TestListCommandsAction_HandleEvent(t *testing.T) { | ||
// Setup | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
db := database.NewMockService(ctrl) | ||
matrixDB := matrixdb.NewMockService(ctrl) | ||
client := mautrixcl.NewMockClient(ctrl) | ||
msngr := messenger.NewMockMessenger(ctrl) | ||
|
||
action := &message.ListCommandsAction{} | ||
action.Configure( | ||
gologger.New(gologger.LogLevelDebug, 0), | ||
client, | ||
msngr, | ||
matrixDB, | ||
db, | ||
nil, | ||
) | ||
|
||
// Expectations | ||
matrixDB.EXPECT().NewMessage(gomock.Any()).Times(3).Return(nil, nil) | ||
|
||
msngr.EXPECT().SendMessage(gomock.Any()).Times(3).Return(&messenger.MessageResponse{ | ||
ExternalIdentifier: "ext1", | ||
}, nil) | ||
|
||
// Execute | ||
action.HandleEvent(tests.TestEvent( | ||
tests.MessageWithBody( | ||
"list my commands", | ||
"list my commands", | ||
), | ||
)) | ||
time.Sleep(time.Millisecond * 50) // wait for goroutine to finish | ||
} |