Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Commit

Permalink
testing list
Browse files Browse the repository at this point in the history
  • Loading branch information
scottleedavis committed May 9, 2019
1 parent acfa49b commit 1dcc6cd
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 85 deletions.
20 changes: 9 additions & 11 deletions server/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

}
Expand Down
51 changes: 24 additions & 27 deletions server/list_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"testing"
"encoding/json"
"testing"
"time"

"github.com/mattermost/mattermost-server/model"
Expand All @@ -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),
},
}

Expand Down Expand Up @@ -89,7 +89,6 @@ func TestListReminders(t *testing.T) {

}


func TestUpdateListReminders(t *testing.T) {

user := &model.User{
Expand All @@ -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),
},
}

Expand All @@ -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 {
Expand Down Expand Up @@ -160,7 +159,6 @@ func TestUpdateListReminders(t *testing.T) {

}


func TestListCompletedReminders(t *testing.T) {

user := &model.User{
Expand All @@ -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),
},
}

Expand All @@ -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 {
Expand Down Expand Up @@ -231,7 +229,6 @@ func TestListCompletedReminders(t *testing.T) {

}


//func TestDeleteCompletedReminders(t *testing.T) {
//
// user := &model.User{
Expand Down
12 changes: 1 addition & 11 deletions server/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -282,4 +273,3 @@ func TestFindWhen(t *testing.T) {
})

}

Loading

0 comments on commit 1dcc6cd

Please sign in to comment.