-
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.
Signed-off-by: Christiaan de Die le Clercq <[email protected]>
- Loading branch information
1 parent
10867d7
commit c791422
Showing
2 changed files
with
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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) | ||
} | ||
println(got.Text) | ||
}) | ||
} | ||
} |