From b542fcf90140c56a1c941cab891049839fb1fc20 Mon Sep 17 00:00:00 2001 From: Layla Manley Date: Sun, 30 Oct 2022 01:16:31 -0400 Subject: [PATCH] Add test coverage to core --- core/event_test.go | 35 ++++++++++++++++++++++++++++++++++ core/pointers_test.go | 19 ++++++++++++++++++ core/{organizer.go => user.go} | 0 core/user_test.go | 23 ++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 core/pointers_test.go rename core/{organizer.go => user.go} (100%) create mode 100644 core/user_test.go diff --git a/core/event_test.go b/core/event_test.go index 17afe4c..111671d 100644 --- a/core/event_test.go +++ b/core/event_test.go @@ -10,6 +10,7 @@ import ( func TestGetChannelName(t *testing.T) { assert := assert.New(t) + // Test Valid Address event := Event{ Name: "Hello World", Location: "1234 Place Rd, Ann Arbor, MI 00000", @@ -17,6 +18,8 @@ func TestGetChannelName(t *testing.T) { } assert.Equal("jan-5-ann-arbor-hello-world", event.Channel().Name) + // Test Unparsable Location + // lmanley: Note it'd be nice to expand support for this event = Event{ Name: "Hello World", Location: "Michigan Theater, Ann Arbor", @@ -24,4 +27,36 @@ func TestGetChannelName(t *testing.T) { } assert.Equal("jan-5-hello-world", event.Channel().Name) + // Test Short Location + event = Event{ + Name: "Hello World", + Location: "Monroe, MI", + DateTime: time.Date(2022, time.January, 5, 0, 0, 0, 0, time.UTC), + } + assert.Equal("jan-5-monroe-hello-world", event.Channel().Name) + + // Test Short Location + event = Event{ + Name: "Hello World", + Location: "Monroe St, Monroe , MI", + DateTime: time.Date(2022, time.January, 5, 0, 0, 0, 0, time.UTC), + } + assert.Equal("jan-5-monroe-hello-world", event.Channel().Name) + + // Test Remote Event + event = Event{ + Name: "Hello World", + Location: REMOTE_LOCATION, + DateTime: time.Date(2022, time.January, 5, 0, 0, 0, 0, time.UTC), + } + assert.Equal("jan-5-online-hello-world", event.Channel().Name) +} + +func TestMonthPrefix(t *testing.T) { + assert := assert.New(t) + + event := Event{ + DateTime: time.Date(2022, time.January, 1, 0, 0, 0, 0, time.UTC), + } + assert.Equal("jan", event.GetMonthPrefix()) } diff --git a/core/pointers_test.go b/core/pointers_test.go new file mode 100644 index 0000000..3e7ca9c --- /dev/null +++ b/core/pointers_test.go @@ -0,0 +1,19 @@ +package core + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestBool(t *testing.T) { + assert := assert.New(t) + + // Test const + assert.True(*Bool(true)) + + // Test var + sample := true + assert.True(*Bool(sample)) + +} diff --git a/core/organizer.go b/core/user.go similarity index 100% rename from core/organizer.go rename to core/user.go diff --git a/core/user_test.go b/core/user_test.go new file mode 100644 index 0000000..6171281 --- /dev/null +++ b/core/user_test.go @@ -0,0 +1,23 @@ +package core + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestUserMention(t *testing.T) { + assert := assert.New(t) + + // Create user object + user := &User{ + ID: "sample_id", + } + + assert.Equal("<@sample_id>", user.Mention()) + + // Test null user + var nullUser *User = nil + assert.NotEmpty(nullUser.Mention()) + +}