diff --git a/server/list_test.go b/server/list_test.go index 18ac881..e595d32 100755 --- a/server/list_test.go +++ b/server/list_test.go @@ -2,22 +2,303 @@ package main import ( "testing" - // "github.com/mattermost/mattermost-server/model" - // "github.com/mattermost/mattermost-server/plugin/plugintest" - // "github.com/stretchr/testify/assert" - // "github.com/stretchr/testify/mock" + "encoding/json" + "time" + + "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/plugin/plugintest" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" ) func TestListReminders(t *testing.T) { - // th := Setup() - // defer th.TearDown() - // th.Server.InitReminders() - // defer th.Server.StopReminders() - // user, _ := th.App.GetUserByUsername(model.REMIND_BOTNAME) - // T := utils.GetUserTranslations(user.Locale) + user := &model.User{ + Email: "-@-.-", + Nickname: "TestUser", + Password: model.NewId(), + Username: "testuser", + Roles: model.SYSTEM_USER_ROLE_ID, + Locale: "en", + } + + occurrences := []Occurrence{ + { + Id: model.NewId(), + ReminderId: "ididididid", + Occurrence: time.Now(), + }, + } + + reminders := []Reminder{ + { + Id: model.NewId(), + Username: user.Username, + Message: "Message", + When: "in 1 second", + Occurrences: occurrences, + Completed: time.Time{}.AddDate(1, 1, 1), + }, + } + + stringReminders, _ := json.Marshal(reminders) + + channel := &model.Channel{ + Id: model.NewId(), + } + + setupAPI := func() *plugintest.API { + api := &plugintest.API{} + api.On("LogDebug", mock.Anything, mock.Anything, mock.Anything).Maybe() + api.On("LogError", mock.Anything, mock.Anything, mock.Anything).Maybe() + api.On("LogInfo", mock.Anything).Maybe() + api.On("GetUserByUsername", mock.AnythingOfType("string")).Return(user, nil) + api.On("GetDirectChannel", mock.Anything, mock.Anything).Return(channel, nil) + api.On("CreatePost", mock.AnythingOfType("*model.Post")).Return(nil, nil) + api.On("KVGet", mock.Anything).Return(stringReminders, nil) + return api + } + + t.Run("if list happens in remind channel", func(t *testing.T) { + + api := setupAPI() + defer api.AssertExpectations(t) + + p := &Plugin{} + p.API = api + + output := p.ListReminders(user, channel.Id) + + assert.Equal(t, output, "") + + }) + + t.Run("if list happens in other channel", func(t *testing.T) { - // list := th.App.ListReminders(user.Id, "") + api := setupAPI() + defer api.AssertExpectations(t) + + p := &Plugin{} + p.API = api + + output := p.ListReminders(user, model.NewId()) + + assert.Equal(t, output, "list.reminders") + + }) - // assert.NotEqual(t, list, T(model.REMIND_EXCEPTION_TEXT)) } + + +func TestUpdateListReminders(t *testing.T) { + + user := &model.User{ + Email: "-@-.-", + Nickname: "TestUser", + Password: model.NewId(), + Username: "testuser", + Roles: model.SYSTEM_USER_ROLE_ID, + Locale: "en", + } + + occurrences := []Occurrence{ + { + Id: model.NewId(), + ReminderId: "ididididid", + Occurrence: time.Now(), + }, + } + + reminders := []Reminder{ + { + Id: model.NewId(), + Username: user.Username, + Message: "Message", + When: "in 1 second", + Occurrences: occurrences, + Completed: time.Time{}.AddDate(1, 1, 1), + }, + } + + stringReminders, _ := json.Marshal(reminders) + + channel := &model.Channel{ + Id: model.NewId(), + } + + post := &model.Post{ + ChannelId: channel.Id, + PendingPostId: model.NewId(), + UserId: user.Id, + Props: model.StringInterface{}, + } + + setupAPI := func() *plugintest.API { + api := &plugintest.API{} + api.On("LogDebug", mock.Anything, mock.Anything, mock.Anything).Maybe() + api.On("LogError", mock.Anything, mock.Anything, mock.Anything).Maybe() + api.On("LogInfo", mock.Anything).Maybe() + api.On("GetUserByUsername", mock.AnythingOfType("string")).Return(user, nil) + api.On("GetUser", mock.AnythingOfType("string")).Return(user, nil) + api.On("UpdatePost", mock.AnythingOfType("*model.Post")).Return(nil, nil) + api.On("GetPost", mock.AnythingOfType("string")).Return(post, nil) + api.On("KVGet", mock.Anything).Return(stringReminders, nil) + return api + } + + t.Run("if update list happens", func(t *testing.T) { + + api := setupAPI() + defer api.AssertExpectations(t) + + p := &Plugin{} + p.API = api + + p.UpdateListReminders(user.Id, model.NewId(), 0) + + }) + +} + + +func TestListCompletedReminders(t *testing.T) { + + user := &model.User{ + Email: "-@-.-", + Nickname: "TestUser", + Password: model.NewId(), + Username: "testuser", + Roles: model.SYSTEM_USER_ROLE_ID, + Locale: "en", + } + + occurrences := []Occurrence{ + { + Id: model.NewId(), + ReminderId: "ididididid", + Occurrence: time.Now(), + }, + } + + reminders := []Reminder{ + { + Id: model.NewId(), + Username: user.Username, + Message: "Message", + When: "in 1 second", + Occurrences: occurrences, + Completed: time.Time{}.AddDate(1, 1, 1), + }, + } + + stringReminders, _ := json.Marshal(reminders) + + channel := &model.Channel{ + Id: model.NewId(), + } + + post := &model.Post{ + ChannelId: channel.Id, + PendingPostId: model.NewId(), + UserId: user.Id, + Props: model.StringInterface{}, + } + + setupAPI := func() *plugintest.API { + api := &plugintest.API{} + api.On("LogDebug", mock.Anything, mock.Anything, mock.Anything).Maybe() + api.On("LogError", mock.Anything, mock.Anything, mock.Anything).Maybe() + api.On("LogInfo", mock.Anything).Maybe() + api.On("GetUserByUsername", mock.AnythingOfType("string")).Return(user, nil) + api.On("GetUser", mock.AnythingOfType("string")).Return(user, nil) + api.On("UpdatePost", mock.AnythingOfType("*model.Post")).Return(nil, nil) + api.On("GetPost", mock.AnythingOfType("string")).Return(post, nil) + api.On("KVGet", mock.Anything).Return(stringReminders, nil) + return api + } + + t.Run("if list completed happens", func(t *testing.T) { + + api := setupAPI() + defer api.AssertExpectations(t) + + p := &Plugin{} + p.API = api + + p.ListCompletedReminders(user.Id, post.Id) + + }) + +} + + +//func TestDeleteCompletedReminders(t *testing.T) { +// +// user := &model.User{ +// Email: "-@-.-", +// Nickname: "TestUser", +// Password: model.NewId(), +// Username: "testuser", +// Roles: model.SYSTEM_USER_ROLE_ID, +// Locale: "en", +// } +// +// occurrences := []Occurrence{ +// { +// Id: model.NewId(), +// ReminderId: "ididididid", +// Occurrence: time.Now(), +// }, +// } +// +// reminders := []Reminder{ +// { +// Id: model.NewId(), +// Username: user.Username, +// Message: "Message", +// When: "in 1 second", +// Occurrences: occurrences, +// Completed: time.Time{}.AddDate(1, 1, 1), +// }, +// } +// +// stringReminders, _ := json.Marshal(reminders) +// +// channel := &model.Channel{ +// Id: model.NewId(), +// } +// +// post := &model.Post{ +// ChannelId: channel.Id, +// PendingPostId: model.NewId(), +// UserId: user.Id, +// Props: model.StringInterface{}, +// } +// +// setupAPI := func() *plugintest.API { +// api := &plugintest.API{} +// api.On("LogDebug", mock.Anything, mock.Anything, mock.Anything).Maybe() +// api.On("LogError", mock.Anything, mock.Anything, mock.Anything).Maybe() +// api.On("LogInfo", mock.Anything).Maybe() +// api.On("GetUserByUsername", mock.AnythingOfType("string")).Return(user, nil) +// api.On("GetUser", mock.AnythingOfType("string")).Return(user, nil) +// api.On("UpdatePost", mock.AnythingOfType("*model.Post")).Return(nil, nil) +// api.On("GetPost", mock.AnythingOfType("string")).Return(post, nil) +// api.On("KVGet", mock.Anything).Return(stringReminders, nil) +// api.On("KVSet", user.Username, stringReminders ).Return(nil) +// return api +// } +// +// t.Run("if delete completed happens", func(t *testing.T) { +// +// api := setupAPI() +// defer api.AssertExpectations(t) +// +// p := &Plugin{} +// p.API = api +// +// p.DeleteCompletedReminders(user.Id) +// +// }) +// +//} diff --git a/server/parse_test.go b/server/parse_test.go index c34808b..47dd6d6 100755 --- a/server/parse_test.go +++ b/server/parse_test.go @@ -2,142 +2,213 @@ package main import ( "testing" - // "github.com/mattermost/mattermost-server/model" - // "github.com/mattermost/mattermost-server/plugin/plugintest" - // "github.com/stretchr/testify/assert" - // "github.com/stretchr/testify/mock" + + "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/plugin/plugintest" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/assert" + ) + func TestFindWhen(t *testing.T) { - // th := Setup() - // defer th.TearDown() - - // th.Server.InitReminders() - // defer th.Server.StopReminders() - // user, _ := th.App.GetUserByUsername(model.REMIND_BOTNAME) - // //T := utils.GetUserTranslations(user.Locale) - - // request := &model.ReminderRequest{} - // request.UserId = user.Id - - // request.Payload = "foo in one" - // rErr := th.App.findWhen(request) - // if rErr != nil { - // mlog.Error(rErr.Error()) - // t.Fatal("foo in one doesn't parse") - // } - // assert.Equal(t, strings.Trim(request.Reminder.When, " "), "in one") - - // request.Payload = "foo every tuesday at 10am" - // rErr = th.App.findWhen(request) - // if rErr != nil { - // mlog.Error(rErr.Error()) - // t.Fatal("foo every tuesday at 10am doesn't parse") - // } - // assert.Equal(t, strings.Trim(request.Reminder.When, " "), "every tuesday at 10am") - - // request.Payload = "foo today at noon" - // rErr = th.App.findWhen(request) - // if rErr != nil { - // mlog.Error(rErr.Error()) - // t.Fatal("foo today at noon doesn't parse") - // } - // assert.Equal(t, strings.Trim(request.Reminder.When, " "), "today at noon") - - // request.Payload = "foo tomorrow at noon" - // rErr = th.App.findWhen(request) - // if rErr != nil { - // mlog.Error(rErr.Error()) - // t.Fatal("foo tomorrow at noon doesn't parse") - // } - // assert.Equal(t, strings.Trim(request.Reminder.When, " "), "tomorrow at noon") - - // request.Payload = "foo monday at 11:11am" - // rErr = th.App.findWhen(request) - // if rErr != nil { - // mlog.Error(rErr.Error()) - // t.Fatal("foo monday at 11:11am doesn't parse") - // } - // assert.Equal(t, strings.Trim(request.Reminder.When, " "), "monday at 11:11am") - - // request.Payload = "foo monday" - // rErr = th.App.findWhen(request) - // if rErr != nil { - // mlog.Error(rErr.Error()) - // t.Fatal("foo monday doesn't parse") - // } - // assert.Equal(t, strings.Trim(request.Reminder.When, " "), "monday") - - // request.Payload = "foo tuesday at 11:11am" - // rErr = th.App.findWhen(request) - // if rErr != nil { - // mlog.Error(rErr.Error()) - // t.Fatal("foo tuesday at 11:11am doesn't parse") - // } - // assert.Equal(t, strings.Trim(request.Reminder.When, " "), "tuesday at 11:11am") - - // request.Payload = "foo wednesday at 11:11am" - // rErr = th.App.findWhen(request) - // if rErr != nil { - // mlog.Error(rErr.Error()) - // t.Fatal("foo wednesday at 11:11am doesn't parse") - // } - // assert.Equal(t, strings.Trim(request.Reminder.When, " "), "wednesday at 11:11am") - - // request.Payload = "foo thursday at 11:11am" - // rErr = th.App.findWhen(request) - // if rErr != nil { - // mlog.Error(rErr.Error()) - // t.Fatal("foo thursday at 11:11am doesn't parse") - // } - // assert.Equal(t, strings.Trim(request.Reminder.When, " "), "thursday at 11:11am") - - // request.Payload = "foo friday at 11:11am" - // rErr = th.App.findWhen(request) - // if rErr != nil { - // mlog.Error(rErr.Error()) - // t.Fatal("foo friday at 11:11am doesn't parse") - // } - // assert.Equal(t, strings.Trim(request.Reminder.When, " "), "friday at 11:11am") - - // request.Payload = "foo saturday at 11:11am" - // rErr = th.App.findWhen(request) - // if rErr != nil { - // mlog.Error(rErr.Error()) - // t.Fatal("foo saturday at 11:11am doesn't parse") - // } - // assert.Equal(t, strings.Trim(request.Reminder.When, " "), "saturday at 11:11am") - - // request.Payload = "foo sunday at 11:11am" - // rErr = th.App.findWhen(request) - // if rErr != nil { - // mlog.Error(rErr.Error()) - // t.Fatal("foo sunday at 11:11am doesn't parse") - // } - // assert.Equal(t, strings.Trim(request.Reminder.When, " "), "sunday at 11:11am") - - // request.Payload = "foo at 2:04 pm" - // rErr = th.App.findWhen(request) - // if rErr != nil { - // mlog.Error(rErr.Error()) - // t.Fatal("foo at 2:04 pm doesn't parse") - // } - // assert.Equal(t, strings.Trim(request.Reminder.When, " "), "at 2:04 pm") - - // request.Payload = "foo at noon every monday" - // rErr = th.App.findWhen(request) - // if rErr != nil { - // mlog.Error(rErr.Error()) - // t.Fatal("foo at noon every monday doesn't parse") - // } - // assert.Equal(t, strings.Trim(request.Reminder.When, " "), "at noon every monday") - - // request.Payload = "tomorrow" - // rErr = th.App.findWhen(request) - // if rErr != nil { - // mlog.Error(rErr.Error()) - // t.Fatal("tomorrow doesn't parse") - // } - // assert.Equal(t, strings.Trim(request.Reminder.When, " "), "tomorrow") + + user := &model.User{ + Email: "-@-.-", + Nickname: "TestUser", + Password: model.NewId(), + Username: "testuser", + Roles: model.SYSTEM_USER_ROLE_ID, + Locale: "en", + } + + setupAPI := func() *plugintest.API { + api := &plugintest.API{} + api.On("LogDebug", mock.Anything, mock.Anything, mock.Anything).Maybe() + api.On("LogError", mock.Anything, mock.Anything, mock.Anything).Maybe() + api.On("LogInfo", mock.Anything).Maybe() + api.On("GetUserByUsername", mock.AnythingOfType("string")).Return(user, nil) + return api + } + + t.Run("if findWhen", func(t *testing.T) { + + api := setupAPI() + defer api.AssertExpectations(t) + + p := &Plugin{} + p.API = api + + request := &ReminderRequest{ + TeamId: model.NewId(), + Username: user.Username, + Payload: "Hello in one minute", + Reminder: Reminder{ + Id: model.NewId(), + TeamId: model.NewId(), + Username: user.Username, + Message: "Hello", + Completed: p.emptyTime, + Target: "me", + When: "in one minute", + }, + } + + err := p.findWhen(request) + assert.True(t, err == nil) + + request = &ReminderRequest{ + TeamId: model.NewId(), + Username: user.Username, + Payload: "Hello every tuesday at 10am", + Reminder: Reminder{ + Id: model.NewId(), + TeamId: model.NewId(), + Username: user.Username, + Message: "Hello", + Completed: p.emptyTime, + Target: "me", + When: "every tuesday at 10am", + }, + } + + err = p.findWhen(request) + assert.True(t, err == nil) + + + request = &ReminderRequest{ + TeamId: model.NewId(), + Username: user.Username, + Payload: "Hello today at noon", + Reminder: Reminder{ + Id: model.NewId(), + TeamId: model.NewId(), + Username: user.Username, + Message: "Hello", + Completed: p.emptyTime, + Target: "me", + When: "today at noon", + }, + } + + err = p.findWhen(request) + assert.True(t, err == nil) + + + request = &ReminderRequest{ + TeamId: model.NewId(), + Username: user.Username, + Payload: "Hello tomorrow at noon", + Reminder: Reminder{ + Id: model.NewId(), + TeamId: model.NewId(), + Username: user.Username, + Message: "Hello", + Completed: p.emptyTime, + Target: "me", + When: "tomorrow at noon", + }, + } + + err = p.findWhen(request) + assert.True(t, err == nil) + + + request = &ReminderRequest{ + TeamId: model.NewId(), + Username: user.Username, + Payload: "Hello monday at 11:11am", + Reminder: Reminder{ + Id: model.NewId(), + TeamId: model.NewId(), + Username: user.Username, + Message: "Hello", + Completed: p.emptyTime, + Target: "me", + When: "monday at 11:11am", + }, + } + + err = p.findWhen(request) + assert.True(t, err == nil) + + + request = &ReminderRequest{ + TeamId: model.NewId(), + Username: user.Username, + Payload: "Hello monday", + Reminder: Reminder{ + Id: model.NewId(), + TeamId: model.NewId(), + Username: user.Username, + Message: "Hello", + Completed: p.emptyTime, + Target: "me", + When: "monday", + }, + } + + err = p.findWhen(request) + assert.True(t, err == nil) + + + request = &ReminderRequest{ + TeamId: model.NewId(), + Username: user.Username, + Payload: "Hello at 2:04 pm", + Reminder: Reminder{ + Id: model.NewId(), + TeamId: model.NewId(), + Username: user.Username, + Message: "Hello", + Completed: p.emptyTime, + Target: "me", + When: "at 2:04 pm", + }, + } + + err = p.findWhen(request) + assert.True(t, err == nil) + + + request = &ReminderRequest{ + TeamId: model.NewId(), + Username: user.Username, + Payload: "Hello at noon every monday", + Reminder: Reminder{ + Id: model.NewId(), + TeamId: model.NewId(), + Username: user.Username, + Message: "Hello", + Completed: p.emptyTime, + Target: "me", + When: "at noon every monday", + }, + } + + err = p.findWhen(request) + assert.True(t, err == nil) + + + request = &ReminderRequest{ + TeamId: model.NewId(), + Username: user.Username, + Payload: "Hello tomorrow", + Reminder: Reminder{ + Id: model.NewId(), + TeamId: model.NewId(), + Username: user.Username, + Message: "Hello", + Completed: p.emptyTime, + Target: "me", + When: "tomorrow", + }, + } + + err = p.findWhen(request) + assert.True(t, err == nil) + + }) } + diff --git a/server/scheduler_test.go b/server/scheduler_test.go index 3612d7f..e6887f4 100755 --- a/server/scheduler_test.go +++ b/server/scheduler_test.go @@ -4,11 +4,11 @@ import ( "testing" //"encoding/json" //"time" - // - //"github.com/mattermost/mattermost-server/model" - //"github.com/mattermost/mattermost-server/plugin/plugintest" + + "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/plugin/plugintest" //"github.com/stretchr/testify/assert" - //"github.com/stretchr/testify/mock" + "github.com/stretchr/testify/mock" ) func TestScheduleReminders(t *testing.T) { @@ -24,23 +24,28 @@ func TestScheduleReminders(t *testing.T) { // //occurrences := []Occurrence{ // { - // Id: "idididid", - // ReminderId: "ididididid", + // Id: model.NewId(), + // ReminderId: model.NewId(), // Occurrence: time.Now(), // }, //} + // //stringOccurrences, _ := json.Marshal(occurrences) + //channel := &model.Channel{ + // Id: model.NewId(), + //} + // //setupAPI := func() *plugintest.API { // api := &plugintest.API{} // api.On("LogDebug", mock.Anything, mock.Anything, mock.Anything).Maybe() // api.On("LogInfo", mock.Anything).Maybe() // api.On("GetUserByUsername", mock.AnythingOfType("string")).Return(user, nil) // api.On("KVGet", mock.AnythingOfType("string")).Return(stringOccurrences, nil) - // api.On("KVSet", mock.AnythingOfType("string"), mock.Anything).Maybe() + // api.On("KVSet", mock.AnythingOfType("string"), stringOccurrences).Maybe() // return api //} // - //t.Run("if scheduled reminder is sane" , func(t *testing.T) { + //t.Run("if scheduled reminder" , func(t *testing.T) { // // api := setupAPI() // defer api.AssertExpectations(t) @@ -48,10 +53,6 @@ func TestScheduleReminders(t *testing.T) { // p := &Plugin{} // p.API = api // - // channel := &model.Channel{ - // Id: "idididid", - // } - // // request := &ReminderRequest{ // Username: user.Username, // Payload: "me foo in 1 seconds", @@ -62,200 +63,53 @@ func TestScheduleReminders(t *testing.T) { // //}) - /////////////////////////////////////////////////////// - - // request := &model.ReminderRequest{} - // request.UserId = user.Id - - // request.Payload = "me foo in 1 seconds" - // response, err := th.App.ScheduleReminder(request) - // if err != nil { - // t.Fatal(UNABLE_TO_SCHEDULE_REMINDER) - // } - - // t2 := time.Now().Add(2 * time.Second).Format(time.Kitchen) - // var responseParameters = map[string]interface{}{ - // "Target": "You", - // "UseTo": "", - // "Message": "foo", - // "When": "in 1 seconds at " + t2 + " today.", - // } - // expectedResponse := T("app.reminder.response", responseParameters) - // assert.Equal(t, response, expectedResponse) - - // request.Payload = "@bob foo in 1 seconds" - // request.Occurrences = model.Occurrences{} - // response, err = th.App.ScheduleReminder(request) - // if err != nil { - // t.Fatal(UNABLE_TO_SCHEDULE_REMINDER) - // } - // t2 = time.Now().Add(time.Second).Format(time.Kitchen) - // responseParameters = map[string]interface{}{ - // "Target": "@bob", - // "UseTo": "", - // "Message": "foo", - // "When": "in 1 seconds at " + t2 + " today.", - // } - // expectedResponse = T("app.reminder.response", responseParameters) - // assert.Equal(t, response, expectedResponse) - - // request.Payload = "~off-topic foo in 1 seconds" - // request.Occurrences = model.Occurrences{} - // response, err = th.App.ScheduleReminder(request) - // if err != nil { - // t.Fatal(UNABLE_TO_SCHEDULE_REMINDER) - // } - // t2 = time.Now().Add(time.Second).Format(time.Kitchen) - - // responseParameters = map[string]interface{}{ - // "Target": "~off-topic", - // "UseTo": "", - // "Message": "foo", - // "When": "in 1 seconds at " + t2 + " today.", - // } - // expectedResponse = T("app.reminder.response", responseParameters) - // assert.Equal(t, response, expectedResponse) +} - // request.Payload = "me \"foo foo foo\" in 1 seconds" - // request.Occurrences = model.Occurrences{} - // response, err = th.App.ScheduleReminder(request) - // if err != nil { - // t.Fatal(UNABLE_TO_SCHEDULE_REMINDER) - // } - // t2 = time.Now().Add(time.Second).Format(time.Kitchen) - // responseParameters = map[string]interface{}{ - // "Target": "You", - // "UseTo": "", - // "Message": "foo foo foo", - // "When": "in 1 seconds at " + t2 + " today.", - // } - // expectedResponse = T("app.reminder.response", responseParameters) - // assert.Equal(t, response, expectedResponse) +func TestInteractiveSchedule(t *testing.T) { - // request.Payload = "me foo in 24 hours" - // request.Occurrences = model.Occurrences{} - // response, err = th.App.ScheduleReminder(request) - // if err != nil { - // t.Fatal(UNABLE_TO_SCHEDULE_REMINDER) - // } - // t2 = time.Now().Add(time.Hour * time.Duration(24)).Format(time.Kitchen) + user := &model.User{ + Email: "-@-.-", + Nickname: "TestUser", + Password: model.NewId(), + Username: "testuser", + Roles: model.SYSTEM_USER_ROLE_ID, + Locale: "en", + } - // responseParameters = map[string]interface{}{ - // "Target": "You", - // "UseTo": "", - // "Message": "foo", - // "When": "in 24 hours at " + t2 + " tomorrow.", - // } - // expectedResponse = T("app.reminder.response", responseParameters) - // assert.Equal(t, response, expectedResponse) + //occurrences := []Occurrence{ + // { + // Id: model.NewId(), + // ReminderId: model.NewId(), + // Occurrence: time.Now(), + // }, + //} + // + //stringOccurrences, _ := json.Marshal(occurrences) + //channel := &model.Channel{ + // Id: model.NewId(), + //} - // request.Payload = "me foo in 3 days" - // request.Occurrences = model.Occurrences{} - // response, err = th.App.ScheduleReminder(request) - // if err != nil { - // t.Fatal(UNABLE_TO_SCHEDULE_REMINDER) - // } - // t3 := time.Now().AddDate(0, 0, 3) - // responseParameters = map[string]interface{}{ - // "Target": "You", - // "UseTo": "", - // "Message": "foo", - // "When": "in 3 days at " + t3.Format(time.Kitchen) + " " + t3.Weekday().String() + ", " + t3.Month().String() + " " + th.App.daySuffixFromInt(user, t3.Day()) + ".", - // } - // expectedResponse = T("app.reminder.response", responseParameters) - // assert.Equal(t, response, expectedResponse) + setupAPI := func() *plugintest.API { + api := &plugintest.API{} + //api.On("LogDebug", mock.Anything, mock.Anything, mock.Anything).Maybe() + //api.On("LogInfo", mock.Anything).Maybe() + api.On("OpenInteractiveDialog", mock.AnythingOfType("model.OpenDialogRequest")).Return(nil) + //api.On("KVGet", mock.AnythingOfType("string")).Return(stringOccurrences, nil) + //api.On("KVSet", mock.AnythingOfType("string"), stringOccurrences).Maybe() + return api + } - // request.Payload = "me foo at 2:04 pm" - // request.Occurrences = model.Occurrences{} - // response, err = th.App.ScheduleReminder(request) - // if err != nil { - // t.Fatal(UNABLE_TO_SCHEDULE_REMINDER) - // } - // responseParameters = map[string]interface{}{ - // "Target": "You", - // "UseTo": "", - // "Message": "foo", - // "When": "at 2:04PM tomorrow.", - // } - // expectedResponse = T("app.reminder.response", responseParameters) - // responseParameters = map[string]interface{}{ - // "Target": "You", - // "UseTo": "", - // "Message": "foo", - // "When": "at 2:04PM today.", - // } - // expectedResponse2 := T("app.reminder.response", responseParameters) - // assert.True(t, response == expectedResponse || response == expectedResponse2) + t.Run("if interactive schedule" , func(t *testing.T) { - // request.Payload = "me foo on monday at 12:30PM" - // request.Occurrences = model.Occurrences{} - // response, err = th.App.ScheduleReminder(request) - // if err != nil { - // t.Fatal(UNABLE_TO_SCHEDULE_REMINDER) - // } - // t3, _ = time.Parse(time.RFC3339, request.Occurrences[0].Occurrence) - // responseParameters = map[string]interface{}{ - // "Target": "You", - // "UseTo": "", - // "Message": "foo", - // "When": "at 12:30PM Monday, " + t3.Month().String() + " " + th.App.daySuffixFromInt(user, t3.Day()) + ".", - // } - // expectedResponse = T("app.reminder.response", responseParameters) - // assert.Equal(t, response, expectedResponse) + api := setupAPI() + defer api.AssertExpectations(t) - // request.Payload = "me foo every wednesday at 12:30PM" - // request.Occurrences = model.Occurrences{} - // response, err = th.App.ScheduleReminder(request) - // if err != nil { - // t.Fatal(UNABLE_TO_SCHEDULE_REMINDER) - // } - // responseParameters = map[string]interface{}{ - // "Target": "You", - // "UseTo": "", - // "Message": "foo", - // "When": "at 12:30PM every Wednesday.", - // } - // expectedResponse = T("app.reminder.response", responseParameters) - // assert.Equal(t, response, expectedResponse) + p := &Plugin{} + p.API = api - // request.Payload = "me tuesday foo" - // request.Occurrences = model.Occurrences{} - // response, err = th.App.ScheduleReminder(request) - // if err != nil { - // t.Fatal(UNABLE_TO_SCHEDULE_REMINDER) - // } - // t3, _ = time.Parse(time.RFC3339, request.Occurrences[0].Occurrence) - // responseParameters = map[string]interface{}{ - // "Target": "You", - // "UseTo": "", - // "Message": "foo", - // "When": "at 9:00AM Tuesday, " + t3.Month().String() + " " + th.App.daySuffixFromInt(user, t3.Day()) + ".", - // } - // expectedResponse = T("app.reminder.response", responseParameters) - // assert.Equal(t, response, expectedResponse) + p.InteractiveSchedule(model.NewId(), user) - // request.Payload = "me tomorrow foo" - // request.Occurrences = model.Occurrences{} - // response, err = th.App.ScheduleReminder(request) - // if err != nil { - // t.Fatal(UNABLE_TO_SCHEDULE_REMINDER) - // } - // t3, _ = time.Parse(time.RFC3339, request.Occurrences[0].Occurrence) - // responseParameters = map[string]interface{}{ - // "Target": "You", - // "UseTo": "", - // "Message": "foo", - // "When": "at 9:00AM tomorrow.", - // } - // expectedResponse = T("app.reminder.response", responseParameters) - // responseParameters = map[string]interface{}{ - // "Target": "You", - // "UseTo": "", - // "Message": "foo", - // "When": "at 9:00AM " + t3.Weekday().String() + ", " + t3.Month().String() + " " + th.App.daySuffixFromInt(user, t3.Day()) + ".", - // } - // expectedResponse2 = T("app.reminder.response", responseParameters) - // assert.True(t, response == expectedResponse || response == expectedResponse2) + }) }