From f7476b2fb6a01d50868a128c1d1f77c14691482d Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Thu, 26 Jan 2017 02:14:12 +0000 Subject: PLT-4378 Slack import when channel name is deleted (#4649) This fixes the issue where the channel fails to Import from Slack if there is already a channel with the same name on Mattermost that has been deleted. --- store/sql_channel_store_test.go | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'store/sql_channel_store_test.go') diff --git a/store/sql_channel_store_test.go b/store/sql_channel_store_test.go index 38446bf94..5202a7c29 100644 --- a/store/sql_channel_store_test.go +++ b/store/sql_channel_store_test.go @@ -352,7 +352,8 @@ func TestChannelStoreGetByName(t *testing.T) { o1.Type = model.CHANNEL_OPEN Must(store.Channel().Save(&o1)) - if r1 := <-store.Channel().GetByName(o1.TeamId, o1.Name); r1.Err != nil { + r1 := <-store.Channel().GetByName(o1.TeamId, o1.Name) + if r1.Err != nil { t.Fatal(r1.Err) } else { if r1.Data.(*model.Channel).ToJson() != o1.ToJson() { @@ -363,6 +364,36 @@ func TestChannelStoreGetByName(t *testing.T) { if err := (<-store.Channel().GetByName(o1.TeamId, "")).Err; err == nil { t.Fatal("Missing id should have failed") } + + Must(store.Channel().Delete(r1.Data.(*model.Channel).Id, model.GetMillis())) + + if err := (<-store.Channel().GetByName(o1.TeamId, "")).Err; err == nil { + t.Fatal("Deleted channel should not be returned by GetByName()") + } +} + +func TestChannelStoreGetDeletedByName(t *testing.T) { + Setup() + + o1 := model.Channel{} + o1.TeamId = model.NewId() + o1.DisplayName = "Name" + o1.Name = "a" + model.NewId() + "b" + o1.Type = model.CHANNEL_OPEN + o1.DeleteAt = model.GetMillis() + Must(store.Channel().Save(&o1)) + + if r1 := <-store.Channel().GetDeletedByName(o1.TeamId, o1.Name); r1.Err != nil { + t.Fatal(r1.Err) + } else { + if r1.Data.(*model.Channel).ToJson() != o1.ToJson() { + t.Fatal("invalid returned channel") + } + } + + if err := (<-store.Channel().GetDeletedByName(o1.TeamId, "")).Err; err == nil { + t.Fatal("Missing id should have failed") + } } func TestChannelMemberStore(t *testing.T) { -- cgit v1.2.3-1-g7c22