diff options
author | Jonathan <jonfritz@gmail.com> | 2018-03-07 10:54:51 -0500 |
---|---|---|
committer | George Goldberg <george@gberg.me> | 2018-03-07 15:54:51 +0000 |
commit | d448a6bef30339a63b7c118b8b2deb44cdb79d8e (patch) | |
tree | 4158c94595bf37e1e1aaf41b8441b73bd480b1c0 /app/channel_test.go | |
parent | 09713ff4eadd3d706df45cb69f096b66c5b283fd (diff) | |
download | chat-d448a6bef30339a63b7c118b8b2deb44cdb79d8e.tar.gz chat-d448a6bef30339a63b7c118b8b2deb44cdb79d8e.tar.bz2 chat-d448a6bef30339a63b7c118b8b2deb44cdb79d8e.zip |
XYZ-87: GlobalRelay DM Exports do not Include Channel Name (#8275)
* Adding ChannelMemberHistory table records when DM channels are created. This ensures that both participants in a DM are shown in compliance export, even if only one of them typed anything
* Direct/Group Message channels now get pretty display names for the purpose of compliance exports
* Fixed string formatting in t.Fatal calls
* Changed uses of ChannelMemberHistory over to ChannelMemberHistoryResult in tests. This should have been done as a part of the work in XYZ-110, but seems to have been missed in this branch for some reason
Diffstat (limited to 'app/channel_test.go')
-rw-r--r-- | app/channel_test.go | 69 |
1 files changed, 62 insertions, 7 deletions
diff --git a/app/channel_test.go b/app/channel_test.go index e4a0e4320..69efaeca7 100644 --- a/app/channel_test.go +++ b/app/channel_test.go @@ -110,7 +110,7 @@ func TestMoveChannel(t *testing.T) { } } -func TestJoinDefaultChannelsTownSquare(t *testing.T) { +func TestJoinDefaultChannelsCreatesChannelMemberHistoryRecordTownSquare(t *testing.T) { th := Setup().InitBasic() defer th.TearDown() @@ -136,7 +136,7 @@ func TestJoinDefaultChannelsTownSquare(t *testing.T) { assert.True(t, found) } -func TestJoinDefaultChannelsOffTopic(t *testing.T) { +func TestJoinDefaultChannelsCreatesChannelMemberHistoryRecordOffTopic(t *testing.T) { th := Setup().InitBasic() defer th.TearDown() @@ -162,7 +162,7 @@ func TestJoinDefaultChannelsOffTopic(t *testing.T) { assert.True(t, found) } -func TestCreateChannelPublic(t *testing.T) { +func TestCreateChannelPublicCreatesChannelMemberHistoryRecord(t *testing.T) { th := Setup().InitBasic() defer th.TearDown() @@ -176,7 +176,7 @@ func TestCreateChannelPublic(t *testing.T) { assert.Equal(t, publicChannel.Id, histories[0].ChannelId) } -func TestCreateChannelPrivate(t *testing.T) { +func TestCreateChannelPrivateCreatesChannelMemberHistoryRecord(t *testing.T) { th := Setup().InitBasic() defer th.TearDown() @@ -205,7 +205,7 @@ func TestUpdateChannelPrivacy(t *testing.T) { } } -func TestCreateGroupChannel(t *testing.T) { +func TestCreateGroupChannelCreatesChannelMemberHistoryRecord(t *testing.T) { th := Setup().InitBasic() defer th.TearDown() @@ -233,7 +233,62 @@ func TestCreateGroupChannel(t *testing.T) { } } -func TestAddUserToChannel(t *testing.T) { +func TestCreateDirectChannelCreatesChannelMemberHistoryRecord(t *testing.T) { + th := Setup().InitBasic() + defer th.TearDown() + + user1 := th.CreateUser() + user2 := th.CreateUser() + + if channel, err := th.App.CreateDirectChannel(user1.Id, user2.Id); err != nil { + t.Fatal("Failed to create direct channel. Error: " + err.Message) + } else { + // there should be a ChannelMemberHistory record for both users + histories := store.Must(th.App.Srv.Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)).([]*model.ChannelMemberHistoryResult) + assert.Len(t, histories, 2) + + historyId0 := histories[0].UserId + historyId1 := histories[1].UserId + switch historyId0 { + case user1.Id: + assert.Equal(t, user2.Id, historyId1) + case user2.Id: + assert.Equal(t, user1.Id, historyId1) + default: + t.Fatal("Unexpected user id " + historyId0 + " in ChannelMemberHistory table") + } + } +} + +func TestGetDirectChannelCreatesChannelMemberHistoryRecord(t *testing.T) { + th := Setup().InitBasic() + defer th.TearDown() + + user1 := th.CreateUser() + user2 := th.CreateUser() + + // this function call implicitly creates a direct channel between the two users if one doesn't already exist + if channel, err := th.App.GetDirectChannel(user1.Id, user2.Id); err != nil { + t.Fatal("Failed to create direct channel. Error: " + err.Message) + } else { + // there should be a ChannelMemberHistory record for both users + histories := store.Must(th.App.Srv.Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)).([]*model.ChannelMemberHistoryResult) + assert.Len(t, histories, 2) + + historyId0 := histories[0].UserId + historyId1 := histories[1].UserId + switch historyId0 { + case user1.Id: + assert.Equal(t, user2.Id, historyId1) + case user2.Id: + assert.Equal(t, user1.Id, historyId1) + default: + t.Fatal("Unexpected user id " + historyId0 + " in ChannelMemberHistory table") + } + } +} + +func TestAddUserToChannelCreatesChannelMemberHistoryRecord(t *testing.T) { th := Setup().InitBasic() defer th.TearDown() @@ -263,7 +318,7 @@ func TestAddUserToChannel(t *testing.T) { assert.Equal(t, groupUserIds, channelMemberHistoryUserIds) } -func TestRemoveUserFromChannel(t *testing.T) { +func TestRemoveUserFromChannelUpdatesChannelMemberHistoryRecord(t *testing.T) { th := Setup().InitBasic() defer th.TearDown() |