summaryrefslogtreecommitdiffstats
path: root/bridge/discord/handlers_test.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2020-03-21 21:27:17 +0100
committerGitHub <noreply@github.com>2020-03-21 21:27:17 +0100
commit281016a5014146387e38d268aa271d539fd562e8 (patch)
treeead89e88d5d22f24eab80bd6192570cb66b2b824 /bridge/discord/handlers_test.go
parentd4acdf2f896f46e78916ba34b3cb942e6b677d7b (diff)
downloadmatterbridge-msglm-281016a5014146387e38d268aa271d539fd562e8.tar.gz
matterbridge-msglm-281016a5014146387e38d268aa271d539fd562e8.tar.bz2
matterbridge-msglm-281016a5014146387e38d268aa271d539fd562e8.zip
Fix duplicate separator on empty description/url (discord). Fixes #1008 (#1035)
Make this work for all possible cases. Add tests
Diffstat (limited to 'bridge/discord/handlers_test.go')
-rw-r--r--bridge/discord/handlers_test.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/bridge/discord/handlers_test.go b/bridge/discord/handlers_test.go
new file mode 100644
index 00000000..af821ad0
--- /dev/null
+++ b/bridge/discord/handlers_test.go
@@ -0,0 +1,58 @@
+package bdiscord
+
+import (
+ "testing"
+
+ "github.com/matterbridge/discordgo"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestHandleEmbed(t *testing.T) {
+ testcases := map[string]struct {
+ embed *discordgo.MessageEmbed
+ result string
+ }{
+ "allempty": {
+ embed: &discordgo.MessageEmbed{},
+ result: "",
+ },
+ "one": {
+ embed: &discordgo.MessageEmbed{
+ Title: "blah",
+ },
+ result: "embed: blah\n",
+ },
+ "two": {
+ embed: &discordgo.MessageEmbed{
+ Title: "blah",
+ Description: "blah2",
+ },
+ result: "embed: blah - blah2\n",
+ },
+ "three": {
+ embed: &discordgo.MessageEmbed{
+ Title: "blah",
+ Description: "blah2",
+ URL: "blah3",
+ },
+ result: "embed: blah - blah2 - blah3\n",
+ },
+ "twob": {
+ embed: &discordgo.MessageEmbed{
+ Description: "blah2",
+ URL: "blah3",
+ },
+ result: "embed: blah2 - blah3\n",
+ },
+ "oneb": {
+ embed: &discordgo.MessageEmbed{
+ URL: "blah3",
+ },
+ result: "embed: blah3\n",
+ },
+ }
+
+ for name, tc := range testcases {
+ assert.Equalf(t, tc.result, handleEmbed(tc.embed), "Testcases %s", name)
+ }
+}