focalboard/server/services/store/storetests/data_retention.go
Harshil Sharma 9918a0b3f8
DND support for category and boards in LHS (#3964)
* WIP

* WIP

* Removed unused webapp util

* Added server tests

* Lint fix

* Updating existing tests

* Updating existing tests

* Updating existing tests

* Fixing existing tests

* Fixing existing tests

* Fixing existing tests

* WIP

* Added category sort order migration

* Added logic to set new category on top

* Implemented api, WS listein logic remining

* finished webapp implementation

* Added category type and tests

* updated tests

* Fixed integration test

* type fix

* WIP

* implemented boards DND to other category and in same category

* removed seconds from boards name

* wip

* debugging cy test

* Enabled hiding views list while DNDing

* Removed some debug logs

* Fixed a bug preventing users from collapsing boards category

* WIP

* Debugging cypress test

* CI

* debugging cy test

* Testing a fix

* reverting test fix

* Handled personal server

* WIP

* WIP

* Adding support for building with esbuild

* Using different index.html templates for esbuild

* WIP

* WIP

* Fixed delete category and rename category

* WIP

* WIP

* Finally, its done.

* Adde suppor tot update board-category mapping in bulk

* Fixed a bug where create category option didn't show up on default category

* Fixed bug where new board was added as last board in Boards category instead of first board

* Minor cleanup

* WIP

* Added support to drab boards onto collapsed categories

* Fixed route order from specific to generic

* Fix linter

* Updated existin server tests

* fixed integration tests

* Fixed webapp test err

* Removed accidental dependencies

* Adding  new server tests

* Finished server tests

* added api to client.go

* Added API integration test

* Fixed existing webapp tests

* WIP

* WIP

* WIP

* WIP

* WIP

* Fixed missing paranthesis

* Some cleanup

* fixed server lint

* noopped down migration

* Fixed issue with DND not working great with newly added category

* Fixed a test

* Fixed a test

* Fixed a test

* Fixed console error while DNDing

* pakg lock restore

* Fixed missing react beautiful dnd in package.lock.json

* updated snapshots

* Fixed webapp test

* Review fixes

* Added API permission check

Co-authored-by: Jesús Espino <jespinog@gmail.com>
2022-11-24 15:31:32 +05:30

139 lines
3.5 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package storetests
import (
"testing"
"time"
"github.com/mattermost/focalboard/server/model"
"github.com/mattermost/focalboard/server/services/store"
"github.com/mattermost/focalboard/server/utils"
"github.com/stretchr/testify/require"
)
const (
boardID = "board-id-test"
categoryID = "category-id-test"
)
func StoreTestDataRetention(t *testing.T, setup func(t *testing.T) (store.Store, func())) {
t.Run("RunDataRetention", func(t *testing.T) {
store, tearDown := setup(t)
defer tearDown()
category := model.Category{
ID: categoryID,
Name: "TestCategory",
UserID: testUserID,
TeamID: testTeamID,
}
err := store.CreateCategory(category)
require.NoError(t, err)
testRunDataRetention(t, store, 0)
testRunDataRetention(t, store, 2)
testRunDataRetention(t, store, 10)
})
}
func LoadData(t *testing.T, store store.Store) {
validBoard := model.Board{
ID: boardID,
IsTemplate: false,
ModifiedBy: testUserID,
TeamID: testTeamID,
}
board, err := store.InsertBoard(&validBoard, testUserID)
require.NoError(t, err)
validBlock := &model.Block{
ID: "id-test",
BoardID: board.ID,
ModifiedBy: testUserID,
}
validBlock2 := &model.Block{
ID: "id-test2",
BoardID: board.ID,
ModifiedBy: testUserID,
}
validBlock3 := &model.Block{
ID: "id-test3",
BoardID: board.ID,
ModifiedBy: testUserID,
}
validBlock4 := &model.Block{
ID: "id-test4",
BoardID: board.ID,
ModifiedBy: testUserID,
}
newBlocks := []*model.Block{validBlock, validBlock2, validBlock3, validBlock4}
err = store.InsertBlocks(newBlocks, testUserID)
require.NoError(t, err)
member := &model.BoardMember{
UserID: testUserID,
BoardID: boardID,
SchemeAdmin: true,
}
_, err = store.SaveMember(member)
require.NoError(t, err)
sharing := model.Sharing{
ID: boardID,
Enabled: true,
Token: "testToken",
}
err = store.UpsertSharing(sharing)
require.NoError(t, err)
err = store.AddUpdateCategoryBoard(testUserID, map[string]string{boardID: categoryID})
require.NoError(t, err)
}
func testRunDataRetention(t *testing.T, store store.Store, batchSize int) {
LoadData(t, store)
blocks, err := store.GetBlocksForBoard(boardID)
require.NoError(t, err)
require.Len(t, blocks, 4)
initialCount := len(blocks)
t.Run("test no deletions", func(t *testing.T) {
deletions, err := store.RunDataRetention(utils.GetMillisForTime(time.Now().Add(-time.Hour*1)), int64(batchSize))
require.NoError(t, err)
require.Equal(t, int64(0), deletions)
})
t.Run("test all deletions", func(t *testing.T) {
deletions, err := store.RunDataRetention(utils.GetMillisForTime(time.Now().Add(time.Hour*1)), int64(batchSize))
require.NoError(t, err)
require.True(t, deletions > int64(initialCount))
// expect all blocks to be deleted.
blocks, errBlocks := store.GetBlocksForBoard(boardID)
require.NoError(t, errBlocks)
require.Equal(t, 0, len(blocks))
// GetMemberForBoard throws error on now rows found
member, err := store.GetMemberForBoard(boardID, testUserID)
require.Error(t, err)
require.True(t, model.IsErrNotFound(err), err)
require.Nil(t, member)
// GetSharing throws error on now rows found
sharing, err := store.GetSharing(boardID)
require.Error(t, err)
require.True(t, model.IsErrNotFound(err), err)
require.Nil(t, sharing)
category, err := store.GetUserCategoryBoards(boardID, testTeamID)
require.NoError(t, err)
require.Empty(t, category)
})
}