From 90f279c7d561360664639071b422618c332d0272 Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Mon, 5 Nov 2018 17:39:46 +0800 Subject: [PATCH] [MM-12805] Remove ephemeral post after leaving a channel (#9772) * remove ephemeral post after leaving a channel * remove unnecessary debugging line --- app/command_leave.go | 2 +- app/command_leave_test.go | 86 +++++++++++++++++++++++++++++++++++++++ i18n/en.json | 4 -- 3 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 app/command_leave_test.go diff --git a/app/command_leave.go b/app/command_leave.go index f127947d5b..5fd84f0118 100644 --- a/app/command_leave.go +++ b/app/command_leave.go @@ -51,5 +51,5 @@ func (me *LeaveProvider) DoCommand(a *App, args *model.CommandArgs, message stri return &model.CommandResponse{Text: args.T("api.command_leave.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} } - return &model.CommandResponse{GotoLocation: args.SiteURL + "/" + team.Name + "/channels/" + model.DEFAULT_CHANNEL, Text: args.T("api.command_leave.success"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} + return &model.CommandResponse{GotoLocation: args.SiteURL + "/" + team.Name + "/channels/" + model.DEFAULT_CHANNEL} } diff --git a/app/command_leave_test.go b/app/command_leave_test.go new file mode 100644 index 0000000000..a1c185be04 --- /dev/null +++ b/app/command_leave_test.go @@ -0,0 +1,86 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package app + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" + + "github.com/mattermost/mattermost-server/model" +) + +func TestLeaveProviderDoCommand(t *testing.T) { + th := Setup().InitBasic() + defer th.TearDown() + + lp := LeaveProvider{} + + publicChannel, _ := th.App.CreateChannel(&model.Channel{ + DisplayName: "AA", + Name: "aa" + model.NewId() + "a", + Type: model.CHANNEL_OPEN, + TeamId: th.BasicTeam.Id, + CreatorId: th.BasicUser.Id, + }, false) + + privateChannel, _ := th.App.CreateChannel(&model.Channel{ + DisplayName: "BB", + Name: "aa" + model.NewId() + "a", + Type: model.CHANNEL_OPEN, + TeamId: th.BasicTeam.Id, + CreatorId: th.BasicUser.Id, + }, false) + + th.App.AddUserToTeam(th.BasicTeam.Id, th.BasicUser.Id, th.BasicUser.Id) + th.App.AddUserToChannel(th.BasicUser, publicChannel) + th.App.AddUserToChannel(th.BasicUser, privateChannel) + + args := &model.CommandArgs{ + T: func(s string, args ...interface{}) string { return s }, + } + + // Should error when no Channel ID in args + actual := lp.DoCommand(th.App, args, "") + assert.Equal(t, "api.command_leave.fail.app_error", actual.Text) + assert.Equal(t, model.COMMAND_RESPONSE_TYPE_EPHEMERAL, actual.ResponseType) + + // Should error when no Team ID in args + args.ChannelId = publicChannel.Id + actual = lp.DoCommand(th.App, args, "") + assert.Equal(t, "api.command_leave.fail.app_error", actual.Text) + assert.Equal(t, model.COMMAND_RESPONSE_TYPE_EPHEMERAL, actual.ResponseType) + + // Leave a public channel + siteURL := "http://localhost:8065" + args.TeamId = th.BasicTeam.Id + args.SiteURL = siteURL + actual = lp.DoCommand(th.App, args, "") + assert.Equal(t, "", actual.Text) + assert.Equal(t, siteURL+"/"+th.BasicTeam.Name+"/channels/"+model.DEFAULT_CHANNEL, actual.GotoLocation) + assert.Equal(t, "", actual.ResponseType) + + time.Sleep(100 * time.Millisecond) + + member, err := th.App.GetChannelMember(publicChannel.Id, th.BasicUser.Id) + if member == nil { + t.Errorf("Expected member object, got nil") + } + + if err != nil { + t.Errorf("Expected nil object, got %s", err) + } + + // Leave a private channel + args.ChannelId = privateChannel.Id + actual = lp.DoCommand(th.App, args, "") + assert.Equal(t, "", actual.Text) + + // Should not leave a default channel + defaultChannel, _ := th.App.GetChannelByName(model.DEFAULT_CHANNEL, th.BasicTeam.Id, false) + args.ChannelId = defaultChannel.Id + actual = lp.DoCommand(th.App, args, "") + assert.Equal(t, "api.channel.leave.default.app_error", actual.Text) +} diff --git a/i18n/en.json b/i18n/en.json index 70b36a1738..b98d13b471 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -694,10 +694,6 @@ "id": "api.command_leave.name", "translation": "leave" }, - { - "id": "api.command_leave.success", - "translation": "Left the channel." - }, { "id": "api.command_logout.desc", "translation": "Logout of Mattermost"