focalboard/server/services/store/storetests/board_insights.go
Shivashis Padhi f00b5c9e61
[MM-43781] Feature: boards insights (#3005)
* Add boilerplate functions and handlers for boards insights

* Fix function signatures to add 'duration' parameter, fix where clauses in db queries

* Fix where clause to include boards of which userId in parameter is a member

* Modify queries to work with sqlite, postgres, mysql

* Integration tests, and results of make generate

* Lint Fixes

* Add icons to board insights

* Lint fixes

* Format insights queries without squirrel to fix parameterization issues

* Add tests for sqlstore utility functions

* Improve team insights tests by creating 2 boards

* Refactor endpoints/app to adhere to developments in 7.0 release

* Refactor queries to use squirrel

* Lint fixes

* Fix client, integration tests

* Remove old integration tests

* Add storetests, refactor functions to handle authorized board_ids

* Make queries compatible with mysql, sqlite

* Add app tests

* Fix lint errors

* Revert makefile changes, fix docstring in api

* Lint fixes and doc correction suggested by @wiggin77

* Fix mock store call count error

* adding client code

* Make the following changes

 - use serviceAPI to get user.Timezone
 - rename licenseAndGuestUserCheck to insightPermissionGate, and handle returned error better
 - validate page, perPage parameters aren't < 0

* Lint fix

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MacBook-Pro.local>
2022-08-08 11:42:02 +05:30

99 lines
3.7 KiB
Go

package storetests
import (
"testing"
"github.com/mattermost/focalboard/server/model"
"github.com/mattermost/focalboard/server/services/store"
"github.com/stretchr/testify/require"
)
const (
testInsightsUserID1 = "user-id-1"
)
func StoreTestBoardsInsightsStore(t *testing.T, setup func(t *testing.T) (store.Store, func())) {
t.Run("GetBoardsInsights", func(t *testing.T) {
store, tearDown := setup(t)
defer tearDown()
getBoardsInsightsTest(t, store)
})
}
func getBoardsInsightsTest(t *testing.T, store store.Store) {
// creating sample data
teamID := testTeamID
userID := testUserID
newBab := &model.BoardsAndBlocks{
Boards: []*model.Board{
{ID: "board-id-1", TeamID: teamID, Type: model.BoardTypeOpen, Icon: "💬"},
{ID: "board-id-2", TeamID: teamID, Type: model.BoardTypePrivate},
{ID: "board-id-3", TeamID: teamID, Type: model.BoardTypeOpen},
},
Blocks: []model.Block{
{ID: "block-id-1", BoardID: "board-id-1", Type: model.TypeCard},
{ID: "block-id-2", BoardID: "board-id-2", Type: model.TypeCard},
{ID: "block-id-3", BoardID: "board-id-1", Type: model.TypeCard},
{ID: "block-id-4", BoardID: "board-id-2", Type: model.TypeCard},
{ID: "block-id-5", BoardID: "board-id-1", Type: model.TypeCard},
{ID: "block-id-6", BoardID: "board-id-2", Type: model.TypeCard},
{ID: "block-id-7", BoardID: "board-id-1", Type: model.TypeCard},
{ID: "block-id-8", BoardID: "board-id-2", Type: model.TypeCard},
{ID: "block-id-9", BoardID: "board-id-1", Type: model.TypeCard},
{ID: "block-id-10", BoardID: "board-id-3", Type: model.TypeCard},
{ID: "block-id-11", BoardID: "board-id-3", Type: model.TypeCard},
{ID: "block-id-12", BoardID: "board-id-3", Type: model.TypeCard},
},
}
bab, err := store.CreateBoardsAndBlocks(newBab, userID)
require.Nil(t, err)
require.NotNil(t, bab)
newBab = &model.BoardsAndBlocks{
Blocks: []model.Block{
{ID: "block-id-13", BoardID: "board-id-1", Type: model.TypeCard},
{ID: "block-id-14", BoardID: "board-id-1", Type: model.TypeCard},
},
}
bab, err = store.CreateBoardsAndBlocks(newBab, testInsightsUserID1)
require.Nil(t, err)
require.NotNil(t, bab)
bm := &model.BoardMember{
UserID: userID,
BoardID: "board-id-2",
SchemeAdmin: true,
}
_, _ = store.SaveMember(bm)
boardsUser1, _ := store.GetBoardsForUserAndTeam(testUserID, testTeamID)
boardsUser2, _ := store.GetBoardsForUserAndTeam(testInsightsUserID1, testTeamID)
// t.Run("team insights", func(t *testing.T) {
// boardIDs := []string{boardsUser1[0].ID, boardsUser1[1].ID, boardsUser1[2].ID}
// topTeamBoards, err := store.GetTeamBoardsInsights(testTeamID, testUserID,
// 0, 0, 10, boardIDs)
// require.NoError(t, err)
// require.Len(t, topTeamBoards.Items, 3)
// // validate board insight content
// require.Equal(t, topTeamBoards.Items[0].ActivityCount, strconv.Itoa(8))
// require.Equal(t, topTeamBoards.Items[0].Icon, "💬")
// require.Equal(t, topTeamBoards.Items[1].ActivityCount, strconv.Itoa(5))
// require.Equal(t, topTeamBoards.Items[2].ActivityCount, strconv.Itoa(4))
// })
t.Run("user insights", func(t *testing.T) {
boardIDs := []string{boardsUser1[0].ID, boardsUser1[1].ID, boardsUser1[2].ID}
topUser1Boards, err := store.GetUserBoardsInsights(testTeamID, testUserID, 0, 0, 10, boardIDs)
require.NoError(t, err)
require.Len(t, topUser1Boards.Items, 3)
require.Equal(t, topUser1Boards.Items[0].Icon, "💬")
require.Equal(t, topUser1Boards.Items[0].BoardID, "board-id-1")
boardIDs = []string{boardsUser2[0].ID, boardsUser2[1].ID}
topUser2Boards, err := store.GetUserBoardsInsights(testTeamID, testInsightsUserID1, 0, 0, 10, boardIDs)
require.NoError(t, err)
require.Len(t, topUser2Boards.Items, 1)
require.Equal(t, topUser2Boards.Items[0].BoardID, "board-id-1")
})
}