-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option for Telegram to use a thread id when posting notification (#…
…265) * Add option for Telegram to use a thread Signed-off-by: Christiaan de Die le Clercq <[email protected]> * Create tests for Telegram service Signed-off-by: Christiaan de Die le Clercq <[email protected]> --------- Signed-off-by: Christiaan de Die le Clercq <[email protected]> Co-authored-by: pasha-codefresh <[email protected]>
- Loading branch information
1 parent
ace379e
commit 743f877
Showing
5 changed files
with
97 additions
and
18 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
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
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,53 @@ | ||
package services | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" | ||
) | ||
|
||
func TestBuildTelegramMessageOptions(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
notification Notification | ||
dest Destination | ||
want *tgbotapi.MessageConfig | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "Message to chat", | ||
notification: Notification{Message: "Test message"}, | ||
dest: Destination{Recipient: "-123456"}, | ||
want: &tgbotapi.MessageConfig{Text: "Test message", BaseChat: tgbotapi.BaseChat{ChatConfig: tgbotapi.ChatConfig{ChatID: -123456}, MessageThreadID: 0}, ParseMode: "Markdown"}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Message to chat with thread", | ||
notification: Notification{Message: "Test message"}, | ||
dest: Destination{Recipient: "-123456|1"}, | ||
want: &tgbotapi.MessageConfig{Text: "Test message", BaseChat: tgbotapi.BaseChat{ChatConfig: tgbotapi.ChatConfig{ChatID: -123456}, MessageThreadID: 1}, ParseMode: "Markdown"}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Message to channel", | ||
notification: Notification{Message: "Test message"}, | ||
dest: Destination{Recipient: "123456"}, | ||
want: &tgbotapi.MessageConfig{Text: "Test message", BaseChat: tgbotapi.BaseChat{ChatConfig: tgbotapi.ChatConfig{ChannelUsername: "@123456"}}, ParseMode: "Markdown"}, | ||
wantErr: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := buildTelegramMessageOptions(tt.notification, tt.dest) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("buildTelegramMessageOptions() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("buildTelegramMessageOptions() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |