* Add route endpoints, model, store functions, and tests for top threads
* Run make store-layers
* Make the following changes
- Fix top user threads query
- Fix passing parameters in api4/insights.go to handler in app
- Add top user threads test
* Add post-message, user_id, participants information to insights results
* model.TopThread.UserID -> model.TopThread.UserId, for compatibility with MySQL
* Rename name -> channel_name
* Add user information to response
* Link post in response, filter out deleted root posts from top threads
* Handle thread delete cases, add app tests for threads insights
* lint: fix typo
* lint: rename asserts
* lint: require.nil -> require.NoError
* Add integration tests for thread insights
* Add embeds and images to top posts
* Add license checks for top threads endpoints
* Query users in batch to populate post-creator
* Make the following changes
- Add license to test server in api4/
- Add tests for threads insights
- top team threads shouldn't include threads from other teams, DMs
- Test duration constraint
- Pagination testing for top threads in model/insights_test.go
* Add i18n-extract
* i18n fixes
* Add username, nickname to user_information
* Hide message, user_id, post_id, reply_count in depth=1 of top threads response
* Fix tests using response.reply_count to use response.post.reply_count
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
123 строки
3.3 KiB
Go
123 строки
3.3 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package model
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetTopReactionListWithPagination(t *testing.T) {
|
|
reactions := []*TopReaction{
|
|
{EmojiName: "smile", Count: 200},
|
|
{EmojiName: "+1", Count: 190},
|
|
{EmojiName: "100", Count: 100},
|
|
{EmojiName: "-1", Count: 75},
|
|
{EmojiName: "checkmark", Count: 50},
|
|
{EmojiName: "mattermost", Count: 49}}
|
|
|
|
hasNextTC := []struct {
|
|
Description string
|
|
Limit int
|
|
Offset int
|
|
Expected *TopReactionList
|
|
}{
|
|
{
|
|
Description: "has one page",
|
|
Limit: len(reactions),
|
|
Offset: 0,
|
|
Expected: &TopReactionList{InsightsListData: InsightsListData{HasNext: false}, Items: reactions},
|
|
},
|
|
{
|
|
Description: "has more than one page",
|
|
Limit: len(reactions) - 1,
|
|
Offset: 0,
|
|
Expected: &TopReactionList{InsightsListData: InsightsListData{HasNext: true}, Items: reactions},
|
|
},
|
|
}
|
|
|
|
for _, test := range hasNextTC {
|
|
t.Run(test.Description, func(t *testing.T) {
|
|
actual := GetTopReactionListWithPagination(reactions, test.Limit)
|
|
assert.Equal(t, test.Expected.HasNext, actual.HasNext)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetTopChannelListWithPagination(t *testing.T) {
|
|
channels := []*TopChannel{
|
|
{ID: NewId(), MessageCount: 200},
|
|
{ID: NewId(), MessageCount: 150},
|
|
{ID: NewId(), MessageCount: 120},
|
|
{ID: NewId(), MessageCount: 105},
|
|
{ID: NewId(), MessageCount: 5},
|
|
{ID: NewId(), MessageCount: 2}}
|
|
|
|
hasNextTC := []struct {
|
|
Description string
|
|
Limit int
|
|
Offset int
|
|
Expected *TopChannelList
|
|
}{
|
|
{
|
|
Description: "has one page",
|
|
Limit: len(channels),
|
|
Offset: 0,
|
|
Expected: &TopChannelList{InsightsListData: InsightsListData{HasNext: false}, Items: channels},
|
|
},
|
|
{
|
|
Description: "has more than one page",
|
|
Limit: len(channels) - 1,
|
|
Offset: 0,
|
|
Expected: &TopChannelList{InsightsListData: InsightsListData{HasNext: true}, Items: channels},
|
|
},
|
|
}
|
|
|
|
for _, test := range hasNextTC {
|
|
t.Run(test.Description, func(t *testing.T) {
|
|
actual := GetTopChannelListWithPagination(channels, test.Limit)
|
|
assert.Equal(t, test.Expected.HasNext, actual.HasNext)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetTopThreadListWithPagination(t *testing.T) {
|
|
threads := []*TopThread{
|
|
{PostId: NewId(), ReplyCount: 100},
|
|
{PostId: NewId(), ReplyCount: 80},
|
|
{PostId: NewId(), ReplyCount: 90},
|
|
{PostId: NewId(), ReplyCount: 76},
|
|
{PostId: NewId(), ReplyCount: 43},
|
|
{PostId: NewId(), ReplyCount: 2},
|
|
{PostId: NewId(), ReplyCount: 1},
|
|
}
|
|
hasNextTT := []struct {
|
|
Description string
|
|
Limit int
|
|
Offset int
|
|
Expected *TopThreadList
|
|
}{
|
|
{
|
|
Description: "has one page",
|
|
Limit: len(threads),
|
|
Offset: 0,
|
|
Expected: &TopThreadList{InsightsListData: InsightsListData{HasNext: false}, Items: threads},
|
|
},
|
|
{
|
|
Description: "has more than one page",
|
|
Limit: len(threads) - 1,
|
|
Offset: 0,
|
|
Expected: &TopThreadList{InsightsListData: InsightsListData{HasNext: true}, Items: threads},
|
|
},
|
|
}
|
|
|
|
for _, test := range hasNextTT {
|
|
t.Run(test.Description, func(t *testing.T) {
|
|
actual := GetTopThreadListWithPagination(threads, test.Limit)
|
|
assert.Equal(t, test.Expected.HasNext, actual.HasNext)
|
|
})
|
|
}
|
|
}
|