diff options
Diffstat (limited to 'store/storetest')
-rw-r--r-- | store/storetest/channel_store.go | 49 | ||||
-rw-r--r-- | store/storetest/compliance_store.go | 300 | ||||
-rw-r--r-- | store/storetest/mocks/ChannelStore.go | 21 | ||||
-rw-r--r-- | store/storetest/mocks/FileInfoStore.go | 5 | ||||
-rw-r--r-- | store/storetest/mocks/PostStore.go | 5 | ||||
-rw-r--r-- | store/storetest/mocks/TeamStore.go | 16 | ||||
-rw-r--r-- | store/storetest/mocks/UserStore.go | 21 | ||||
-rw-r--r-- | store/storetest/mocks/WebhookStore.go | 5 | ||||
-rw-r--r-- | store/storetest/team_store.go | 26 | ||||
-rw-r--r-- | store/storetest/user_store.go | 77 |
10 files changed, 439 insertions, 86 deletions
diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go index 121b40a01..d3b69edea 100644 --- a/store/storetest/channel_store.go +++ b/store/storetest/channel_store.go @@ -43,7 +43,6 @@ func TestChannelStore(t *testing.T, ss store.Store) { t.Run("GetMember", func(t *testing.T) { testGetMember(t, ss) }) t.Run("GetMemberForPost", func(t *testing.T) { testChannelStoreGetMemberForPost(t, ss) }) t.Run("GetMemberCount", func(t *testing.T) { testGetMemberCount(t, ss) }) - t.Run("UpdateExtrasByUser", func(t *testing.T) { testUpdateExtrasByUser(t, ss) }) t.Run("SearchMore", func(t *testing.T) { testChannelStoreSearchMore(t, ss) }) t.Run("SearchInTeam", func(t *testing.T) { testChannelStoreSearchInTeam(t, ss) }) t.Run("GetMembersByIds", func(t *testing.T) { testChannelStoreGetMembersByIds(t, ss) }) @@ -1641,54 +1640,6 @@ func testGetMemberCount(t *testing.T, ss store.Store) { } } -func testUpdateExtrasByUser(t *testing.T, ss store.Store) { - teamId := model.NewId() - - c1 := model.Channel{ - TeamId: teamId, - DisplayName: "Channel1", - Name: "zz" + model.NewId() + "b", - Type: model.CHANNEL_OPEN, - } - store.Must(ss.Channel().Save(&c1, -1)) - - c2 := model.Channel{ - TeamId: teamId, - DisplayName: "Channel2", - Name: "zz" + model.NewId() + "b", - Type: model.CHANNEL_OPEN, - } - store.Must(ss.Channel().Save(&c2, -1)) - - u1 := &model.User{ - Email: model.NewId(), - DeleteAt: 0, - } - store.Must(ss.User().Save(u1)) - store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: u1.Id}, -1)) - - m1 := model.ChannelMember{ - ChannelId: c1.Id, - UserId: u1.Id, - NotifyProps: model.GetDefaultChannelNotifyProps(), - } - store.Must(ss.Channel().SaveMember(&m1)) - - u1.DeleteAt = model.GetMillis() - store.Must(ss.User().Update(u1, true)) - - if result := <-ss.Channel().ExtraUpdateByUser(u1.Id, u1.DeleteAt); result.Err != nil { - t.Fatalf("failed to update extras by user: %v", result.Err) - } - - u1.DeleteAt = 0 - store.Must(ss.User().Update(u1, true)) - - if result := <-ss.Channel().ExtraUpdateByUser(u1.Id, u1.DeleteAt); result.Err != nil { - t.Fatalf("failed to update extras by user: %v", result.Err) - } -} - func testChannelStoreSearchMore(t *testing.T, ss store.Store) { o1 := model.Channel{} o1.TeamId = model.NewId() diff --git a/store/storetest/compliance_store.go b/store/storetest/compliance_store.go index eb29bedc7..50a62531f 100644 --- a/store/storetest/compliance_store.go +++ b/store/storetest/compliance_store.go @@ -16,7 +16,10 @@ func TestComplianceStore(t *testing.T, ss store.Store) { t.Run("", func(t *testing.T) { testComplianceStore(t, ss) }) t.Run("ComplianceExport", func(t *testing.T) { testComplianceExport(t, ss) }) t.Run("ComplianceExportDirectMessages", func(t *testing.T) { testComplianceExportDirectMessages(t, ss) }) - t.Run("MessageExport", func(t *testing.T) { testComplianceMessageExport(t, ss) }) + t.Run("MessageExportPublicChannel", func(t *testing.T) { testMessageExportPublicChannel(t, ss) }) + t.Run("MessageExportPrivateChannel", func(t *testing.T) { testMessageExportPrivateChannel(t, ss) }) + t.Run("MessageExportDirectMessageChannel", func(t *testing.T) { testMessageExportDirectMessageChannel(t, ss) }) + t.Run("MessageExportGroupMessageChannel", func(t *testing.T) { testMessageExportGroupMessageChannel(t, ss) }) } func testComplianceStore(t *testing.T, ss store.Store) { @@ -319,7 +322,7 @@ func testComplianceExportDirectMessages(t *testing.T, ss store.Store) { } } -func testComplianceMessageExport(t *testing.T, ss store.Store) { +func testMessageExportPublicChannel(t *testing.T, ss store.Store) { // get the starting number of message export entries startTime := model.GetMillis() var numMessageExports = 0 @@ -360,15 +363,14 @@ func testComplianceMessageExport(t *testing.T, ss store.Store) { UserId: user2.Id, }, -1)) - // need a public channel as well as a DM channel between the two users + // need a public channel channel := &model.Channel{ TeamId: team.Id, Name: model.NewId(), - DisplayName: "Channel2", + DisplayName: "Public Channel", Type: model.CHANNEL_OPEN, } channel = store.Must(ss.Channel().Save(channel, -1)).(*model.Channel) - directMessageChannel := store.Must(ss.Channel().CreateDirectChannel(user1.Id, user2.Id)).(*model.Channel) // user1 posts twice in the public channel post1 := &model.Post{ @@ -387,22 +389,114 @@ func testComplianceMessageExport(t *testing.T, ss store.Store) { } post2 = store.Must(ss.Post().Save(post2)).(*model.Post) - // user1 also sends a DM to user2 - post3 := &model.Post{ - ChannelId: directMessageChannel.Id, + // fetch the message exports for both posts that user1 sent + messageExportMap := map[string]model.MessageExport{} + if r1 := <-ss.Compliance().MessageExport(startTime-10, 10); r1.Err != nil { + t.Fatal(r1.Err) + } else { + messages := r1.Data.([]*model.MessageExport) + assert.Equal(t, numMessageExports+2, len(messages)) + + for _, v := range messages { + messageExportMap[*v.PostId] = *v + } + } + + // post1 was made by user1 in channel1 and team1 + assert.Equal(t, post1.Id, *messageExportMap[post1.Id].PostId) + assert.Equal(t, post1.CreateAt, *messageExportMap[post1.Id].PostCreateAt) + assert.Equal(t, post1.Message, *messageExportMap[post1.Id].PostMessage) + assert.Equal(t, channel.Id, *messageExportMap[post1.Id].ChannelId) + assert.Equal(t, channel.DisplayName, *messageExportMap[post1.Id].ChannelDisplayName) + assert.Equal(t, user1.Id, *messageExportMap[post1.Id].UserId) + assert.Equal(t, user1.Email, *messageExportMap[post1.Id].UserEmail) + assert.Equal(t, user1.Username, *messageExportMap[post1.Id].Username) + + // post2 was made by user1 in channel1 and team1 + assert.Equal(t, post2.Id, *messageExportMap[post2.Id].PostId) + assert.Equal(t, post2.CreateAt, *messageExportMap[post2.Id].PostCreateAt) + assert.Equal(t, post2.Message, *messageExportMap[post2.Id].PostMessage) + assert.Equal(t, channel.Id, *messageExportMap[post2.Id].ChannelId) + assert.Equal(t, channel.DisplayName, *messageExportMap[post2.Id].ChannelDisplayName) + assert.Equal(t, user1.Id, *messageExportMap[post2.Id].UserId) + assert.Equal(t, user1.Email, *messageExportMap[post2.Id].UserEmail) + assert.Equal(t, user1.Username, *messageExportMap[post2.Id].Username) +} + +func testMessageExportPrivateChannel(t *testing.T, ss store.Store) { + // get the starting number of message export entries + startTime := model.GetMillis() + var numMessageExports = 0 + if r1 := <-ss.Compliance().MessageExport(startTime-10, 10); r1.Err != nil { + t.Fatal(r1.Err) + } else { + messages := r1.Data.([]*model.MessageExport) + numMessageExports = len(messages) + } + + // need a team + team := &model.Team{ + DisplayName: "DisplayName", + Name: "zz" + model.NewId() + "b", + Email: model.NewId() + "@nowhere.com", + Type: model.TEAM_OPEN, + } + team = store.Must(ss.Team().Save(team)).(*model.Team) + + // and two users that are a part of that team + user1 := &model.User{ + Email: model.NewId(), + Username: model.NewId(), + } + user1 = store.Must(ss.User().Save(user1)).(*model.User) + store.Must(ss.Team().SaveMember(&model.TeamMember{ + TeamId: team.Id, + UserId: user1.Id, + }, -1)) + + user2 := &model.User{ + Email: model.NewId(), + Username: model.NewId(), + } + user2 = store.Must(ss.User().Save(user2)).(*model.User) + store.Must(ss.Team().SaveMember(&model.TeamMember{ + TeamId: team.Id, + UserId: user2.Id, + }, -1)) + + // need a private channel + channel := &model.Channel{ + TeamId: team.Id, + Name: model.NewId(), + DisplayName: "Private Channel", + Type: model.CHANNEL_PRIVATE, + } + channel = store.Must(ss.Channel().Save(channel, -1)).(*model.Channel) + + // user1 posts twice in the private channel + post1 := &model.Post{ + ChannelId: channel.Id, UserId: user1.Id, - CreateAt: startTime + 20, - Message: "zz" + model.NewId() + "c", + CreateAt: startTime, + Message: "zz" + model.NewId() + "a", + } + post1 = store.Must(ss.Post().Save(post1)).(*model.Post) + + post2 := &model.Post{ + ChannelId: channel.Id, + UserId: user1.Id, + CreateAt: startTime + 10, + Message: "zz" + model.NewId() + "b", } - post3 = store.Must(ss.Post().Save(post3)).(*model.Post) + post2 = store.Must(ss.Post().Save(post2)).(*model.Post) - // fetch the message exports for all three posts that user1 sent + // fetch the message exports for both posts that user1 sent messageExportMap := map[string]model.MessageExport{} if r1 := <-ss.Compliance().MessageExport(startTime-10, 10); r1.Err != nil { t.Fatal(r1.Err) } else { messages := r1.Data.([]*model.MessageExport) - assert.Equal(t, numMessageExports+3, len(messages)) + assert.Equal(t, numMessageExports+2, len(messages)) for _, v := range messages { messageExportMap[*v.PostId] = *v @@ -415,6 +509,7 @@ func testComplianceMessageExport(t *testing.T, ss store.Store) { assert.Equal(t, post1.Message, *messageExportMap[post1.Id].PostMessage) assert.Equal(t, channel.Id, *messageExportMap[post1.Id].ChannelId) assert.Equal(t, channel.DisplayName, *messageExportMap[post1.Id].ChannelDisplayName) + assert.Equal(t, channel.Type, *messageExportMap[post1.Id].ChannelType) assert.Equal(t, user1.Id, *messageExportMap[post1.Id].UserId) assert.Equal(t, user1.Email, *messageExportMap[post1.Id].UserEmail) assert.Equal(t, user1.Username, *messageExportMap[post1.Id].Username) @@ -425,16 +520,179 @@ func testComplianceMessageExport(t *testing.T, ss store.Store) { assert.Equal(t, post2.Message, *messageExportMap[post2.Id].PostMessage) assert.Equal(t, channel.Id, *messageExportMap[post2.Id].ChannelId) assert.Equal(t, channel.DisplayName, *messageExportMap[post2.Id].ChannelDisplayName) + assert.Equal(t, channel.Type, *messageExportMap[post2.Id].ChannelType) assert.Equal(t, user1.Id, *messageExportMap[post2.Id].UserId) assert.Equal(t, user1.Email, *messageExportMap[post2.Id].UserEmail) assert.Equal(t, user1.Username, *messageExportMap[post2.Id].Username) +} + +func testMessageExportDirectMessageChannel(t *testing.T, ss store.Store) { + // get the starting number of message export entries + startTime := model.GetMillis() + var numMessageExports = 0 + if r1 := <-ss.Compliance().MessageExport(startTime-10, 10); r1.Err != nil { + t.Fatal(r1.Err) + } else { + messages := r1.Data.([]*model.MessageExport) + numMessageExports = len(messages) + } + + // need a team + team := &model.Team{ + DisplayName: "DisplayName", + Name: "zz" + model.NewId() + "b", + Email: model.NewId() + "@nowhere.com", + Type: model.TEAM_OPEN, + } + team = store.Must(ss.Team().Save(team)).(*model.Team) + + // and two users that are a part of that team + user1 := &model.User{ + Email: model.NewId(), + Username: model.NewId(), + } + user1 = store.Must(ss.User().Save(user1)).(*model.User) + store.Must(ss.Team().SaveMember(&model.TeamMember{ + TeamId: team.Id, + UserId: user1.Id, + }, -1)) + + user2 := &model.User{ + Email: model.NewId(), + Username: model.NewId(), + } + user2 = store.Must(ss.User().Save(user2)).(*model.User) + store.Must(ss.Team().SaveMember(&model.TeamMember{ + TeamId: team.Id, + UserId: user2.Id, + }, -1)) + + // as well as a DM channel between those users + directMessageChannel := store.Must(ss.Channel().CreateDirectChannel(user1.Id, user2.Id)).(*model.Channel) + + // user1 also sends a DM to user2 + post := &model.Post{ + ChannelId: directMessageChannel.Id, + UserId: user1.Id, + CreateAt: startTime + 20, + Message: "zz" + model.NewId() + "c", + } + post = store.Must(ss.Post().Save(post)).(*model.Post) + + // fetch the message export for the post that user1 sent + messageExportMap := map[string]model.MessageExport{} + if r1 := <-ss.Compliance().MessageExport(startTime-10, 10); r1.Err != nil { + t.Fatal(r1.Err) + } else { + messages := r1.Data.([]*model.MessageExport) + assert.Equal(t, numMessageExports+1, len(messages)) + + for _, v := range messages { + messageExportMap[*v.PostId] = *v + } + } + + // post is a DM between user1 and user2 + // there is no channel display name for direct messages, so we sub in the string "Direct Message" instead + assert.Equal(t, post.Id, *messageExportMap[post.Id].PostId) + assert.Equal(t, post.CreateAt, *messageExportMap[post.Id].PostCreateAt) + assert.Equal(t, post.Message, *messageExportMap[post.Id].PostMessage) + assert.Equal(t, directMessageChannel.Id, *messageExportMap[post.Id].ChannelId) + assert.Equal(t, "Direct Message", *messageExportMap[post.Id].ChannelDisplayName) + assert.Equal(t, user1.Id, *messageExportMap[post.Id].UserId) + assert.Equal(t, user1.Email, *messageExportMap[post.Id].UserEmail) + assert.Equal(t, user1.Username, *messageExportMap[post.Id].Username) +} + +func testMessageExportGroupMessageChannel(t *testing.T, ss store.Store) { + // get the starting number of message export entries + startTime := model.GetMillis() + var numMessageExports = 0 + if r1 := <-ss.Compliance().MessageExport(startTime-10, 10); r1.Err != nil { + t.Fatal(r1.Err) + } else { + messages := r1.Data.([]*model.MessageExport) + numMessageExports = len(messages) + } + + // need a team + team := &model.Team{ + DisplayName: "DisplayName", + Name: "zz" + model.NewId() + "b", + Email: model.NewId() + "@nowhere.com", + Type: model.TEAM_OPEN, + } + team = store.Must(ss.Team().Save(team)).(*model.Team) + + // and three users that are a part of that team + user1 := &model.User{ + Email: model.NewId(), + Username: model.NewId(), + } + user1 = store.Must(ss.User().Save(user1)).(*model.User) + store.Must(ss.Team().SaveMember(&model.TeamMember{ + TeamId: team.Id, + UserId: user1.Id, + }, -1)) + + user2 := &model.User{ + Email: model.NewId(), + Username: model.NewId(), + } + user2 = store.Must(ss.User().Save(user2)).(*model.User) + store.Must(ss.Team().SaveMember(&model.TeamMember{ + TeamId: team.Id, + UserId: user2.Id, + }, -1)) + + user3 := &model.User{ + Email: model.NewId(), + Username: model.NewId(), + } + user3 = store.Must(ss.User().Save(user3)).(*model.User) + store.Must(ss.Team().SaveMember(&model.TeamMember{ + TeamId: team.Id, + UserId: user3.Id, + }, -1)) + + // can't create a group channel directly, because importing app creates an import cycle, so we have to fake it + groupMessageChannel := &model.Channel{ + TeamId: team.Id, + Name: model.NewId(), + Type: model.CHANNEL_GROUP, + } + groupMessageChannel = store.Must(ss.Channel().Save(groupMessageChannel, -1)).(*model.Channel) + + // user1 posts in the GM + post := &model.Post{ + ChannelId: groupMessageChannel.Id, + UserId: user1.Id, + CreateAt: startTime + 20, + Message: "zz" + model.NewId() + "c", + } + post = store.Must(ss.Post().Save(post)).(*model.Post) + + // fetch the message export for the post that user1 sent + messageExportMap := map[string]model.MessageExport{} + if r1 := <-ss.Compliance().MessageExport(startTime-10, 10); r1.Err != nil { + t.Fatal(r1.Err) + } else { + messages := r1.Data.([]*model.MessageExport) + assert.Equal(t, numMessageExports+1, len(messages)) + + for _, v := range messages { + messageExportMap[*v.PostId] = *v + } + } - // post3 is a DM between user1 and user2 - assert.Equal(t, post3.Id, *messageExportMap[post3.Id].PostId) - assert.Equal(t, post3.CreateAt, *messageExportMap[post3.Id].PostCreateAt) - assert.Equal(t, post3.Message, *messageExportMap[post3.Id].PostMessage) - assert.Equal(t, directMessageChannel.Id, *messageExportMap[post3.Id].ChannelId) - assert.Equal(t, user1.Id, *messageExportMap[post3.Id].UserId) - assert.Equal(t, user1.Email, *messageExportMap[post3.Id].UserEmail) - assert.Equal(t, user1.Username, *messageExportMap[post3.Id].Username) + // post is a DM between user1 and user2 + // there is no channel display name for direct messages, so we sub in the string "Direct Message" instead + assert.Equal(t, post.Id, *messageExportMap[post.Id].PostId) + assert.Equal(t, post.CreateAt, *messageExportMap[post.Id].PostCreateAt) + assert.Equal(t, post.Message, *messageExportMap[post.Id].PostMessage) + assert.Equal(t, groupMessageChannel.Id, *messageExportMap[post.Id].ChannelId) + assert.Equal(t, "Group Message", *messageExportMap[post.Id].ChannelDisplayName) + assert.Equal(t, user1.Id, *messageExportMap[post.Id].UserId) + assert.Equal(t, user1.Email, *messageExportMap[post.Id].UserEmail) + assert.Equal(t, user1.Username, *messageExportMap[post.Id].Username) } diff --git a/store/storetest/mocks/ChannelStore.go b/store/storetest/mocks/ChannelStore.go index 5379c2fb4..6eab47073 100644 --- a/store/storetest/mocks/ChannelStore.go +++ b/store/storetest/mocks/ChannelStore.go @@ -61,6 +61,11 @@ func (_m *ChannelStore) AutocompleteInTeam(teamId string, term string) store.Sto return r0 } +// ClearCaches provides a mock function with given fields: +func (_m *ChannelStore) ClearCaches() { + _m.Called() +} + // CreateDirectChannel provides a mock function with given fields: userId, otherUserId func (_m *ChannelStore) CreateDirectChannel(userId string, otherUserId string) store.StoreChannel { ret := _m.Called(userId, otherUserId) @@ -93,22 +98,6 @@ func (_m *ChannelStore) Delete(channelId string, time int64) store.StoreChannel return r0 } -// ExtraUpdateByUser provides a mock function with given fields: userId, time -func (_m *ChannelStore) ExtraUpdateByUser(userId string, time int64) store.StoreChannel { - ret := _m.Called(userId, time) - - var r0 store.StoreChannel - if rf, ok := ret.Get(0).(func(string, int64) store.StoreChannel); ok { - r0 = rf(userId, time) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(store.StoreChannel) - } - } - - return r0 -} - // Get provides a mock function with given fields: id, allowFromCache func (_m *ChannelStore) Get(id string, allowFromCache bool) store.StoreChannel { ret := _m.Called(id, allowFromCache) diff --git a/store/storetest/mocks/FileInfoStore.go b/store/storetest/mocks/FileInfoStore.go index 9b479ff3a..4dddf0bd7 100644 --- a/store/storetest/mocks/FileInfoStore.go +++ b/store/storetest/mocks/FileInfoStore.go @@ -29,6 +29,11 @@ func (_m *FileInfoStore) AttachToPost(fileId string, postId string) store.StoreC return r0 } +// ClearCaches provides a mock function with given fields: +func (_m *FileInfoStore) ClearCaches() { + _m.Called() +} + // DeleteForPost provides a mock function with given fields: postId func (_m *FileInfoStore) DeleteForPost(postId string) store.StoreChannel { ret := _m.Called(postId) diff --git a/store/storetest/mocks/PostStore.go b/store/storetest/mocks/PostStore.go index 05e3bde34..c405d5030 100644 --- a/store/storetest/mocks/PostStore.go +++ b/store/storetest/mocks/PostStore.go @@ -61,6 +61,11 @@ func (_m *PostStore) AnalyticsUserCountsWithPostsByDay(teamId string) store.Stor return r0 } +// ClearCaches provides a mock function with given fields: +func (_m *PostStore) ClearCaches() { + _m.Called() +} + // Delete provides a mock function with given fields: postId, time func (_m *PostStore) Delete(postId string, time int64) store.StoreChannel { ret := _m.Called(postId, time) diff --git a/store/storetest/mocks/TeamStore.go b/store/storetest/mocks/TeamStore.go index bdad7f81b..d38fb5f27 100644 --- a/store/storetest/mocks/TeamStore.go +++ b/store/storetest/mocks/TeamStore.go @@ -461,6 +461,22 @@ func (_m *TeamStore) UpdateDisplayName(name string, teamId string) store.StoreCh return r0 } +// UpdateLastTeamIconUpdate provides a mock function with given fields: teamId, curTime +func (_m *TeamStore) UpdateLastTeamIconUpdate(teamId string, curTime int64) store.StoreChannel { + ret := _m.Called(teamId, curTime) + + var r0 store.StoreChannel + if rf, ok := ret.Get(0).(func(string, int64) store.StoreChannel); ok { + r0 = rf(teamId, curTime) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(store.StoreChannel) + } + } + + return r0 +} + // UpdateMember provides a mock function with given fields: member func (_m *TeamStore) UpdateMember(member *model.TeamMember) store.StoreChannel { ret := _m.Called(member) diff --git a/store/storetest/mocks/UserStore.go b/store/storetest/mocks/UserStore.go index 7d1fd8c38..369a29e7a 100644 --- a/store/storetest/mocks/UserStore.go +++ b/store/storetest/mocks/UserStore.go @@ -77,6 +77,11 @@ func (_m *UserStore) AnalyticsUniqueUserCount(teamId string) store.StoreChannel return r0 } +// ClearCaches provides a mock function with given fields: +func (_m *UserStore) ClearCaches() { + _m.Called() +} + // Get provides a mock function with given fields: id func (_m *UserStore) Get(id string) store.StoreChannel { ret := _m.Called(id) @@ -349,6 +354,22 @@ func (_m *UserStore) GetProfilesInChannel(channelId string, offset int, limit in return r0 } +// GetProfilesInChannelByStatus provides a mock function with given fields: channelId, offset, limit +func (_m *UserStore) GetProfilesInChannelByStatus(channelId string, offset int, limit int) store.StoreChannel { + ret := _m.Called(channelId, offset, limit) + + var r0 store.StoreChannel + if rf, ok := ret.Get(0).(func(string, int, int) store.StoreChannel); ok { + r0 = rf(channelId, offset, limit) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(store.StoreChannel) + } + } + + return r0 +} + // GetProfilesNotInChannel provides a mock function with given fields: teamId, channelId, offset, limit func (_m *UserStore) GetProfilesNotInChannel(teamId string, channelId string, offset int, limit int) store.StoreChannel { ret := _m.Called(teamId, channelId, offset, limit) diff --git a/store/storetest/mocks/WebhookStore.go b/store/storetest/mocks/WebhookStore.go index aa66e0600..bf5b636eb 100644 --- a/store/storetest/mocks/WebhookStore.go +++ b/store/storetest/mocks/WebhookStore.go @@ -45,6 +45,11 @@ func (_m *WebhookStore) AnalyticsOutgoingCount(teamId string) store.StoreChannel return r0 } +// ClearCaches provides a mock function with given fields: +func (_m *WebhookStore) ClearCaches() { + _m.Called() +} + // DeleteIncoming provides a mock function with given fields: webhookId, time func (_m *WebhookStore) DeleteIncoming(webhookId string, time int64) store.StoreChannel { ret := _m.Called(webhookId, time) diff --git a/store/storetest/team_store.go b/store/storetest/team_store.go index a32de9dba..cab06f87f 100644 --- a/store/storetest/team_store.go +++ b/store/storetest/team_store.go @@ -33,6 +33,7 @@ func TestTeamStore(t *testing.T, ss store.Store) { t.Run("MemberCount", func(t *testing.T) { testTeamStoreMemberCount(t, ss) }) t.Run("GetChannelUnreadsForAllTeams", func(t *testing.T) { testGetChannelUnreadsForAllTeams(t, ss) }) t.Run("GetChannelUnreadsForTeam", func(t *testing.T) { testGetChannelUnreadsForTeam(t, ss) }) + t.Run("UpdateLastTeamIconUpdate", func(t *testing.T) { testUpdateLastTeamIconUpdate(t, ss) }) } func testTeamStoreSave(t *testing.T, ss store.Store) { @@ -1003,3 +1004,28 @@ func testGetChannelUnreadsForTeam(t *testing.T, ss store.Store) { } } } + +func testUpdateLastTeamIconUpdate(t *testing.T, ss store.Store) { + + // team icon initially updated a second ago + lastTeamIconUpdateInitial := model.GetMillis() - 1000 + + o1 := &model.Team{} + o1.DisplayName = "Display Name" + o1.Name = "z-z-z" + model.NewId() + "b" + o1.Email = model.NewId() + "@nowhere.com" + o1.Type = model.TEAM_OPEN + o1.LastTeamIconUpdate = lastTeamIconUpdateInitial + o1 = (<-ss.Team().Save(o1)).Data.(*model.Team) + + curTime := model.GetMillis() + + if err := (<-ss.Team().UpdateLastTeamIconUpdate(o1.Id, curTime)).Err; err != nil { + t.Fatal(err) + } + + ro1 := (<-ss.Team().Get(o1.Id)).Data.(*model.Team) + if ro1.LastTeamIconUpdate <= lastTeamIconUpdateInitial { + t.Fatal("LastTeamIconUpdate not updated") + } +} diff --git a/store/storetest/user_store.go b/store/storetest/user_store.go index 47f04d1bb..2fd7d4190 100644 --- a/store/storetest/user_store.go +++ b/store/storetest/user_store.go @@ -25,6 +25,7 @@ func TestUserStore(t *testing.T, ss store.Store) { t.Run("GetAllProfiles", func(t *testing.T) { testUserStoreGetAllProfiles(t, ss) }) t.Run("GetProfiles", func(t *testing.T) { testUserStoreGetProfiles(t, ss) }) t.Run("GetProfilesInChannel", func(t *testing.T) { testUserStoreGetProfilesInChannel(t, ss) }) + t.Run("GetProfilesInChannelByStatus", func(t *testing.T) { testUserStoreGetProfilesInChannelByStatus(t, ss) }) t.Run("GetProfilesWithoutTeam", func(t *testing.T) { testUserStoreGetProfilesWithoutTeam(t, ss) }) t.Run("GetAllProfilesInChannel", func(t *testing.T) { testUserStoreGetAllProfilesInChannel(t, ss) }) t.Run("GetProfilesNotInChannel", func(t *testing.T) { testUserStoreGetProfilesNotInChannel(t, ss) }) @@ -464,6 +465,82 @@ func testUserStoreGetProfilesInChannel(t *testing.T, ss store.Store) { } } +func testUserStoreGetProfilesInChannelByStatus(t *testing.T, ss store.Store) { + teamId := model.NewId() + + u1 := &model.User{} + u1.Email = model.NewId() + store.Must(ss.User().Save(u1)) + store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: u1.Id}, -1)) + + u2 := &model.User{} + u2.Email = model.NewId() + store.Must(ss.User().Save(u2)) + store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: u2.Id}, -1)) + + c1 := model.Channel{} + c1.TeamId = teamId + c1.DisplayName = "Profiles in channel" + c1.Name = "profiles-" + model.NewId() + c1.Type = model.CHANNEL_OPEN + + c2 := model.Channel{} + c2.TeamId = teamId + c2.DisplayName = "Profiles in private" + c2.Name = "profiles-" + model.NewId() + c2.Type = model.CHANNEL_PRIVATE + + store.Must(ss.Channel().Save(&c1, -1)) + store.Must(ss.Channel().Save(&c2, -1)) + + m1 := model.ChannelMember{} + m1.ChannelId = c1.Id + m1.UserId = u1.Id + m1.NotifyProps = model.GetDefaultChannelNotifyProps() + + m2 := model.ChannelMember{} + m2.ChannelId = c1.Id + m2.UserId = u2.Id + m2.NotifyProps = model.GetDefaultChannelNotifyProps() + + m3 := model.ChannelMember{} + m3.ChannelId = c2.Id + m3.UserId = u1.Id + m3.NotifyProps = model.GetDefaultChannelNotifyProps() + + store.Must(ss.Channel().SaveMember(&m1)) + store.Must(ss.Channel().SaveMember(&m2)) + store.Must(ss.Channel().SaveMember(&m3)) + + if r1 := <-ss.User().GetProfilesInChannelByStatus(c1.Id, 0, 100); r1.Err != nil { + t.Fatal(r1.Err) + } else { + users := r1.Data.([]*model.User) + if len(users) != 2 { + t.Fatal("invalid returned users") + } + + found := false + for _, u := range users { + if u.Id == u1.Id { + found = true + } + } + + if !found { + t.Fatal("missing user") + } + } + + if r2 := <-ss.User().GetProfilesInChannelByStatus(c2.Id, 0, 1); r2.Err != nil { + t.Fatal(r2.Err) + } else { + if len(r2.Data.([]*model.User)) != 1 { + t.Fatal("should have returned only 1 user") + } + } +} + func testUserStoreGetProfilesWithoutTeam(t *testing.T, ss store.Store) { teamId := model.NewId() |