Handle special characters in event names (#1)

Co-authored-by: Layla <layla@layla.gg>
Reviewed-on: https://gitea.sumulayla.synology.me/layla/birdbot/pulls/1
This commit was merged in pull request #1.
This commit is contained in:
2023-06-10 04:24:57 -04:00
parent b98fc73ea1
commit 91a886a81e
2 changed files with 36 additions and 0 deletions

32
core/channel_test.go Normal file
View File

@@ -0,0 +1,32 @@
package core
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestGenerateEventChannelName(t *testing.T) {
assert := assert.New(t)
// Test Valid Address
channelName := GenerateEventChannelName("Hello World", "1234 Place Rd, Ann Arbor, MI 00000", time.Date(2022, time.January, 5, 0, 0, 0, 0, time.UTC))
assert.Equal("jan-5-ann-arbor-hello-world-2022", channelName)
// Test Unparsable
// lmanley: Note it'd be nice to expand support for this
channelName = GenerateEventChannelName("Hello World", "Michigan Theater, Ann Arbor", time.Date(2022, time.January, 5, 0, 0, 0, 0, time.UTC))
assert.Equal("jan-5-hello-world-2022", channelName)
// Test Short Location
channelName = GenerateEventChannelName("Hello World", "Monroe, MI", time.Date(2022, time.January, 5, 0, 0, 0, 0, time.UTC))
assert.Equal("jan-5-monroe-hello-world-2022", channelName)
// Test Remote Event
channelName = GenerateEventChannelName("Hello World", RemoteLocation, time.Date(2022, time.January, 5, 0, 0, 0, 0, time.UTC))
assert.Equal("jan-5-online-hello-world-2022", channelName)
channelName = GenerateEventChannelName("Hangout :)", "Quickly Livonia", time.Date(2022, time.January, 5, 0, 0, 0, 0, time.UTC))
assert.Equal("jan-5-quickly-livonia-hangout-2022", channelName)
}