-
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.
1 parent
0dedea4
commit 8cf23e8
Showing
4 changed files
with
122 additions
and
4 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
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
121 changes: 121 additions & 0 deletions
121
internal/connectors/matrix/actions/reaction/reschedule_repeating_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,121 @@ | ||
package reaction_test | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/CubicrootXYZ/gologger" | ||
"github.com/CubicrootXYZ/matrix-reminder-and-calendar-bot/internal/connectors/matrix/actions/reaction" | ||
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 TestRescheduleRepeatAction(t *testing.T) { | ||
action := &reaction.RescheduleRepeatingAction{} | ||
|
||
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 TestRescheduleRepeatingAction_Selector(t *testing.T) { | ||
action := &reaction.RescheduleRepeatingAction{} | ||
|
||
examples := []string{} | ||
|
||
_, _, examplesFromDocu := action.GetDocu() | ||
examples = append(examples, examplesFromDocu...) | ||
|
||
reactions := action.Selector() | ||
for _, example := range examples { | ||
matches := false | ||
for _, reaction := range reactions { | ||
if example == reaction { | ||
matches = true | ||
break | ||
} | ||
} | ||
assert.Truef(t, matches, "%s is not part of reactions", example) | ||
} | ||
} | ||
|
||
func TestRescheduleRepeatingAction_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 := &reaction.RescheduleRepeatingAction{} | ||
action.Configure( | ||
gologger.New(gologger.LogLevelDebug, 0), | ||
client, | ||
msngr, | ||
matrixDB, | ||
db, | ||
nil, | ||
) | ||
|
||
t.Run("success case", func(_ *testing.T) { | ||
msg := tests.TestMessage( | ||
tests.WithTestEvent(), | ||
) | ||
|
||
// Expectations | ||
db.EXPECT().NewEvent(gomock.Any()).Return(nil, nil) | ||
|
||
msngr.EXPECT().DeleteMessageAsync(gomock.Any()).Return(nil) | ||
|
||
// Execute | ||
action.HandleEvent(tests.TestReactionEvent( | ||
tests.ReactionWithKey("✅"), | ||
), msg) | ||
}) | ||
|
||
t.Run("new event fails", func(_ *testing.T) { | ||
msg := tests.TestMessage( | ||
tests.WithTestEvent(), | ||
) | ||
|
||
// Expectations | ||
db.EXPECT().NewEvent(gomock.Any()).Return(nil, errors.New("test")) | ||
|
||
msngr.EXPECT().SendMessageAsync(messenger.PlainTextMessage( | ||
"Whoopsie, can not update the event as requested.", | ||
"!room123", | ||
)).Return(nil) | ||
|
||
// Execute | ||
action.HandleEvent(tests.TestReactionEvent( | ||
tests.ReactionWithKey("✅"), | ||
), msg) | ||
}) | ||
|
||
t.Run("delete message fails", func(_ *testing.T) { | ||
msg := tests.TestMessage( | ||
tests.WithTestEvent(), | ||
) | ||
|
||
// Expectations | ||
db.EXPECT().NewEvent(gomock.Any()).Return(nil, nil) | ||
|
||
msngr.EXPECT().DeleteMessageAsync(gomock.Any()).Return(errors.New("test")) | ||
|
||
// Execute | ||
action.HandleEvent(tests.TestReactionEvent( | ||
tests.ReactionWithKey("✅"), | ||
), msg) | ||
}) | ||
} |
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