From 1dcc6cdcf0f9439ab0c2671e45a8be2b6b0cc188 Mon Sep 17 00:00:00 2001 From: Scott Lee Davis Date: Thu, 9 May 2019 08:52:07 -0700 Subject: [PATCH] testing list --- server/list.go | 20 ++++++------- server/list_test.go | 51 +++++++++++++++----------------- server/parse_test.go | 12 +------- server/reminder_test.go | 64 +++++++++++++++++++--------------------- server/scheduler_test.go | 3 +- 5 files changed, 65 insertions(+), 85 deletions(-) diff --git a/server/list.go b/server/list.go index 9a75828..08eb2de 100755 --- a/server/list.go +++ b/server/list.go @@ -155,27 +155,25 @@ func (p *Plugin) categorizeOccurrences(reminders []Reminder) ( reminder.Completed == p.emptyTime && ((occurrence.Repeat == "" && t.After(time.Now().UTC())) || (s != p.emptyTime && s.After(time.Now().UTC()))) { - upcomingOccurrences = append(upcomingOccurrences, occurrence) - } - - if !strings.HasPrefix(reminder.Target, "~") && + } else if !strings.HasPrefix(reminder.Target, "~") && occurrence.Repeat != "" && t.After(time.Now().UTC()) { recurringOccurrences = append(recurringOccurrences, occurrence) - } - - if !strings.HasPrefix(reminder.Target, "~") && + } else if !strings.HasPrefix(reminder.Target, "~") && reminder.Completed == p.emptyTime && t.Before(time.Now().UTC()) && s == p.emptyTime { - pastOccurrences = append(pastOccurrences, occurrence) - } - - if strings.HasPrefix(reminder.Target, "~") && + } else if strings.HasPrefix(reminder.Target, "~") && reminder.Completed == p.emptyTime && t.After(time.Now().UTC()) { channelOccurrences = append(channelOccurrences, occurrence) + } else if reminder.Completed != p.emptyTime { + p.API.LogInfo("completed reminder: " + fmt.Sprintf("%v", reminder)) + p.API.LogInfo("completed occurrence: " + fmt.Sprintf("%v", occurrence)) + } else { + p.API.LogInfo("unknown reminder: " + fmt.Sprintf("%v", reminder)) + p.API.LogInfo("unknown occurrence: " + fmt.Sprintf("%v", occurrence)) } } diff --git a/server/list_test.go b/server/list_test.go index e595d32..84578bc 100755 --- a/server/list_test.go +++ b/server/list_test.go @@ -1,8 +1,8 @@ package main import ( - "testing" "encoding/json" + "testing" "time" "github.com/mattermost/mattermost-server/model" @@ -24,20 +24,20 @@ func TestListReminders(t *testing.T) { occurrences := []Occurrence{ { - Id: model.NewId(), + Id: model.NewId(), ReminderId: "ididididid", - Occurrence: time.Now(), + Occurrence: time.Now(), }, } reminders := []Reminder{ { - Id: model.NewId(), - Username: user.Username, - Message: "Message", - When: "in 1 second", + Id: model.NewId(), + Username: user.Username, + Message: "Message", + When: "in 1 second", Occurrences: occurrences, - Completed: time.Time{}.AddDate(1, 1, 1), + Completed: time.Time{}.AddDate(1, 1, 1), }, } @@ -89,7 +89,6 @@ func TestListReminders(t *testing.T) { } - func TestUpdateListReminders(t *testing.T) { user := &model.User{ @@ -103,20 +102,20 @@ func TestUpdateListReminders(t *testing.T) { occurrences := []Occurrence{ { - Id: model.NewId(), + Id: model.NewId(), ReminderId: "ididididid", - Occurrence: time.Now(), + Occurrence: time.Now(), }, } reminders := []Reminder{ { - Id: model.NewId(), - Username: user.Username, - Message: "Message", - When: "in 1 second", + Id: model.NewId(), + Username: user.Username, + Message: "Message", + When: "in 1 second", Occurrences: occurrences, - Completed: time.Time{}.AddDate(1, 1, 1), + Completed: time.Time{}.AddDate(1, 1, 1), }, } @@ -130,7 +129,7 @@ func TestUpdateListReminders(t *testing.T) { ChannelId: channel.Id, PendingPostId: model.NewId(), UserId: user.Id, - Props: model.StringInterface{}, + Props: model.StringInterface{}, } setupAPI := func() *plugintest.API { @@ -160,7 +159,6 @@ func TestUpdateListReminders(t *testing.T) { } - func TestListCompletedReminders(t *testing.T) { user := &model.User{ @@ -174,20 +172,20 @@ func TestListCompletedReminders(t *testing.T) { occurrences := []Occurrence{ { - Id: model.NewId(), + Id: model.NewId(), ReminderId: "ididididid", - Occurrence: time.Now(), + Occurrence: time.Now(), }, } reminders := []Reminder{ { - Id: model.NewId(), - Username: user.Username, - Message: "Message", - When: "in 1 second", + Id: model.NewId(), + Username: user.Username, + Message: "Message", + When: "in 1 second", Occurrences: occurrences, - Completed: time.Time{}.AddDate(1, 1, 1), + Completed: time.Time{}.AddDate(1, 1, 1), }, } @@ -201,7 +199,7 @@ func TestListCompletedReminders(t *testing.T) { ChannelId: channel.Id, PendingPostId: model.NewId(), UserId: user.Id, - Props: model.StringInterface{}, + Props: model.StringInterface{}, } setupAPI := func() *plugintest.API { @@ -231,7 +229,6 @@ func TestListCompletedReminders(t *testing.T) { } - //func TestDeleteCompletedReminders(t *testing.T) { // // user := &model.User{ diff --git a/server/parse_test.go b/server/parse_test.go index 164c5b2..bc92895 100755 --- a/server/parse_test.go +++ b/server/parse_test.go @@ -5,9 +5,8 @@ import ( "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/plugin/plugintest" - "github.com/stretchr/testify/mock" "github.com/stretchr/testify/assert" - + "github.com/stretchr/testify/mock" ) func TestParseRequest(t *testing.T) { @@ -30,7 +29,6 @@ func TestParseRequest(t *testing.T) { return api } - t.Run("if no quotes", func(t *testing.T) { api := setupAPI() defer api.AssertExpectations(t) @@ -146,7 +144,6 @@ func TestFindWhen(t *testing.T) { err = p.findWhen(request) assert.True(t, err == nil) - request = &ReminderRequest{ TeamId: model.NewId(), Username: user.Username, @@ -165,7 +162,6 @@ func TestFindWhen(t *testing.T) { err = p.findWhen(request) assert.True(t, err == nil) - request = &ReminderRequest{ TeamId: model.NewId(), Username: user.Username, @@ -184,7 +180,6 @@ func TestFindWhen(t *testing.T) { err = p.findWhen(request) assert.True(t, err == nil) - request = &ReminderRequest{ TeamId: model.NewId(), Username: user.Username, @@ -203,7 +198,6 @@ func TestFindWhen(t *testing.T) { err = p.findWhen(request) assert.True(t, err == nil) - request = &ReminderRequest{ TeamId: model.NewId(), Username: user.Username, @@ -222,7 +216,6 @@ func TestFindWhen(t *testing.T) { err = p.findWhen(request) assert.True(t, err == nil) - request = &ReminderRequest{ TeamId: model.NewId(), Username: user.Username, @@ -241,7 +234,6 @@ func TestFindWhen(t *testing.T) { err = p.findWhen(request) assert.True(t, err == nil) - request = &ReminderRequest{ TeamId: model.NewId(), Username: user.Username, @@ -260,7 +252,6 @@ func TestFindWhen(t *testing.T) { err = p.findWhen(request) assert.True(t, err == nil) - request = &ReminderRequest{ TeamId: model.NewId(), Username: user.Username, @@ -282,4 +273,3 @@ func TestFindWhen(t *testing.T) { }) } - diff --git a/server/reminder_test.go b/server/reminder_test.go index 9c56900..a6da46e 100755 --- a/server/reminder_test.go +++ b/server/reminder_test.go @@ -2,15 +2,14 @@ package main import ( "encoding/json" + "fmt" "testing" "time" - "fmt" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/plugin/plugintest" - "github.com/stretchr/testify/mock" "github.com/stretchr/testify/assert" - + "github.com/stretchr/testify/mock" ) func TestTriggerReminders(t *testing.T) { @@ -23,24 +22,24 @@ func TestTriggerReminders(t *testing.T) { Roles: model.SYSTEM_USER_ROLE_ID, Locale: "en", } - testTime := time.Now().UTC().Round(time.Second) + testTime := time.Now().UTC().Round(time.Second) occurrences := []Occurrence{ { - Id: model.NewId(), + Id: model.NewId(), ReminderId: model.NewId(), - Occurrence: testTime, + Occurrence: testTime, }, } reminders := []Reminder{ { - Id: model.NewId(), - TeamId: model.NewId(), - Username: user.Username, - Message: "Hello", - Target: "me", - When: "in one minute", + Id: model.NewId(), + TeamId: model.NewId(), + Username: user.Username, + Message: "Hello", + Target: "me", + When: "in one minute", Occurrences: occurrences, }, } @@ -80,7 +79,6 @@ func TestTriggerReminders(t *testing.T) { p := &Plugin{} p.API = api - p.TriggerReminders() }) @@ -97,24 +95,24 @@ func TestGetReminder(t *testing.T) { Roles: model.SYSTEM_USER_ROLE_ID, Locale: "en", } - testTime := time.Now().UTC().Round(time.Second) + testTime := time.Now().UTC().Round(time.Second) occurrences := []Occurrence{ { - Id: model.NewId(), + Id: model.NewId(), ReminderId: model.NewId(), - Occurrence: testTime, + Occurrence: testTime, }, } reminders := []Reminder{ { - Id: model.NewId(), - TeamId: model.NewId(), - Username: user.Username, - Message: "Hello", - Target: "me", - When: "in one minute", + Id: model.NewId(), + TeamId: model.NewId(), + Username: user.Username, + Message: "Hello", + Target: "me", + When: "in one minute", Occurrences: occurrences, }, } @@ -155,24 +153,24 @@ func TestGetReminders(t *testing.T) { Roles: model.SYSTEM_USER_ROLE_ID, Locale: "en", } - testTime := time.Now().UTC().Round(time.Second) + testTime := time.Now().UTC().Round(time.Second) occurrences := []Occurrence{ { - Id: model.NewId(), + Id: model.NewId(), ReminderId: model.NewId(), - Occurrence: testTime, + Occurrence: testTime, }, } reminders := []Reminder{ { - Id: model.NewId(), - TeamId: model.NewId(), - Username: user.Username, - Message: "Hello", - Target: "me", - When: "in one minute", + Id: model.NewId(), + TeamId: model.NewId(), + Username: user.Username, + Message: "Hello", + Target: "me", + When: "in one minute", Occurrences: occurrences, }, } @@ -200,7 +198,6 @@ func TestGetReminders(t *testing.T) { }) - } func TestUpdateReminder(t *testing.T) { @@ -337,9 +334,8 @@ func TestUpsertReminder(t *testing.T) { func TestDeleteReminder(t *testing.T) { - } func TestDeleteReminders(t *testing.T) { -} \ No newline at end of file +} diff --git a/server/scheduler_test.go b/server/scheduler_test.go index e6887f4..9e32345 100755 --- a/server/scheduler_test.go +++ b/server/scheduler_test.go @@ -65,7 +65,6 @@ func TestScheduleReminders(t *testing.T) { } - func TestInteractiveSchedule(t *testing.T) { user := &model.User{ @@ -100,7 +99,7 @@ func TestInteractiveSchedule(t *testing.T) { return api } - t.Run("if interactive schedule" , func(t *testing.T) { + t.Run("if interactive schedule", func(t *testing.T) { api := setupAPI() defer api.AssertExpectations(t)