2021-01-29 17:50:20 +01:00
|
|
|
package storetests
|
2020-10-18 01:09:12 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2021-01-29 19:32:33 +01:00
|
|
|
"time"
|
2020-10-18 01:09:12 +02:00
|
|
|
|
2021-01-26 23:13:46 +01:00
|
|
|
"github.com/mattermost/focalboard/server/model"
|
2021-01-29 17:50:20 +01:00
|
|
|
"github.com/mattermost/focalboard/server/services/store"
|
2021-10-07 13:51:01 +02:00
|
|
|
"github.com/mattermost/focalboard/server/utils"
|
2022-03-22 15:24:34 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-10-18 01:09:12 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2021-07-09 03:09:02 +02:00
|
|
|
const (
|
2022-03-22 15:24:34 +01:00
|
|
|
testUserID = "user-id"
|
|
|
|
testTeamID = "team-id"
|
|
|
|
testBoardID = "board-id"
|
2021-07-09 03:09:02 +02:00
|
|
|
)
|
|
|
|
|
2021-01-29 17:50:20 +01:00
|
|
|
func StoreTestBlocksStore(t *testing.T, setup func(t *testing.T) (store.Store, func())) {
|
|
|
|
t.Run("InsertBlock", func(t *testing.T) {
|
|
|
|
store, tearDown := setup(t)
|
2021-01-29 19:32:33 +01:00
|
|
|
defer tearDown()
|
2022-03-22 15:24:34 +01:00
|
|
|
testInsertBlock(t, store)
|
2021-01-29 19:32:33 +01:00
|
|
|
})
|
2021-12-10 15:17:00 +01:00
|
|
|
t.Run("InsertBlocks", func(t *testing.T) {
|
|
|
|
store, tearDown := setup(t)
|
|
|
|
defer tearDown()
|
2022-03-22 15:24:34 +01:00
|
|
|
testInsertBlocks(t, store)
|
2021-12-10 15:17:00 +01:00
|
|
|
})
|
2021-08-06 14:10:24 +02:00
|
|
|
t.Run("PatchBlock", func(t *testing.T) {
|
|
|
|
store, tearDown := setup(t)
|
|
|
|
defer tearDown()
|
2022-03-22 15:24:34 +01:00
|
|
|
testPatchBlock(t, store)
|
2021-08-06 14:10:24 +02:00
|
|
|
})
|
2021-12-10 15:17:00 +01:00
|
|
|
t.Run("PatchBlocks", func(t *testing.T) {
|
|
|
|
store, tearDown := setup(t)
|
|
|
|
defer tearDown()
|
2022-03-22 15:24:34 +01:00
|
|
|
testPatchBlocks(t, store)
|
2021-12-10 15:17:00 +01:00
|
|
|
})
|
2021-01-29 19:32:33 +01:00
|
|
|
t.Run("DeleteBlock", func(t *testing.T) {
|
|
|
|
store, tearDown := setup(t)
|
|
|
|
defer tearDown()
|
2022-03-22 15:24:34 +01:00
|
|
|
testDeleteBlock(t, store)
|
2021-01-29 17:50:20 +01:00
|
|
|
})
|
2022-02-22 18:42:49 +01:00
|
|
|
t.Run("UndeleteBlock", func(t *testing.T) {
|
|
|
|
store, tearDown := setup(t)
|
|
|
|
defer tearDown()
|
2022-03-22 15:24:34 +01:00
|
|
|
testUndeleteBlock(t, store)
|
2022-02-22 18:42:49 +01:00
|
|
|
})
|
2021-01-29 17:50:20 +01:00
|
|
|
t.Run("GetSubTree2", func(t *testing.T) {
|
|
|
|
store, tearDown := setup(t)
|
2021-01-29 19:32:33 +01:00
|
|
|
defer tearDown()
|
2022-03-22 15:24:34 +01:00
|
|
|
testGetSubTree2(t, store)
|
2021-01-29 17:50:20 +01:00
|
|
|
})
|
2022-03-22 15:24:34 +01:00
|
|
|
t.Run("GetBlocks", func(t *testing.T) {
|
2021-01-29 19:32:33 +01:00
|
|
|
store, tearDown := setup(t)
|
|
|
|
defer tearDown()
|
2022-03-22 15:24:34 +01:00
|
|
|
testGetBlocks(t, store)
|
2021-04-30 16:31:04 +02:00
|
|
|
})
|
2022-03-22 15:24:34 +01:00
|
|
|
t.Run("GetBlock", func(t *testing.T) {
|
2021-04-30 16:31:04 +02:00
|
|
|
store, tearDown := setup(t)
|
|
|
|
defer tearDown()
|
2022-03-22 15:24:34 +01:00
|
|
|
testGetBlock(t, store)
|
2021-07-08 16:36:43 +02:00
|
|
|
})
|
2022-03-22 15:24:34 +01:00
|
|
|
t.Run("DuplicateBlock", func(t *testing.T) {
|
2021-07-09 06:36:50 +02:00
|
|
|
store, tearDown := setup(t)
|
|
|
|
defer tearDown()
|
2022-03-22 15:24:34 +01:00
|
|
|
testDuplicateBlock(t, store)
|
2021-07-09 06:36:50 +02:00
|
|
|
})
|
GetBoardMetadata API (#2569)
* wip
* Added data migration for populating categories
* wip
* Added data migration for populating categories
* Store WIP
* migration WIP
* category CRUD APIs complete
* category block API WIP
* block category update API done
* Fetcehed data into store
* Started displayting sidebar data
* sidebar WIP
* Dashboard - basic changes
* Sidebar dashboard btn and board switcher UI only
* Sidebar dashboard btn and board switcher UI only
* create category dialog WIP
* Create category webapp side done
* Integrated move card to other category
* board to block
* Disabled dashboard route for now as we'll implement it in phase 2
* WIP
* Added logic to open last board/view on per team level
* Add workspace to teams and boards migrations (#1986)
* Add workspace to teams and boards migrations
* Update json annotations on board models
* boards search dialog WIP
* Seach dialog WIP
* Implemented opening boiard from search results
* Boards switcher styliung
* Handled update category WS event
* Template support
* personal server support and styling fixes
* test fix WIP
* Fixed a bug causing boards to not be moved correctly beteen categories
* Fixed webapp tests
* fix
* Store changes (#2011)
* Permissions phase 1 - Websocket updates (#2014)
* Store changes
* Websockets changes
* Permissions phase 1 - Permissions service (#2015)
* Store changes
* Websockets changes
* Permissions service
* Api and app updates (#2016)
* Store changes
* Websockets changes
* Permissions service
* New API and App changes
* Delete and Patch boards and blocks endpoints
* Used correct variable
* Webapp changes WIP
* Open correct team URL
* Fixed get block API
* Used React context for workspace users
* WIP
* On load navigation sorted out
* WIP
* Nav fix
* categories WS broadcast
* Used real search API
* Fixed unfurl ppreview
* set active team in sidebar
* IMplemented navigation on changing team in sidebar
* Misc fixes
* close rows inside transaction (#2045)
* update syntax for mysql (#2044)
* Upadted mutator for new patchBlock API
* Updated patchBlock API to use new URL
* Listeining to correct event in plugin mode
* Implemented WS messages for category operations:
* Fix duplicated build tags on Makefile
* Sidebar enhancements
* Add missing prefix to SQLite migration and fix flaky tests
* Sidebar boards menu enhancement
* Fix board page interactions (#2144)
* Fix patch board card properties error
* Fix board interactions
* Fix insert blocks interactions
* Fix app tests (#2104)
* Add json1 tag to vscode launch (#2157)
* Fix add, delete and update boards and add board patch generation (#2146)
* Fix update boards and add board patch generation
* Make add board and add template work, as well as deleting a board
* Update the state on board deletion
* Delete unused variable
* Fix bad parenthesis
* Fix board creation inside plugin, options were coming null due websocket message serialization
* update property type mutators to use boards API (#2168)
* Add permissions modal (#2196)
* Initial integration
* Permissions modal, websocket updates and API tests implemented
* Avoid updating/removing user if there is only one admin left
* Fix duplicates on board search
* Adds integration test
* Addressing PR review comments
Co-authored-by: Jesús Espino <jespinog@gmail.com>
* Merge
* I'm able to compile now
* Some fixes around tests execution
* Fixing migrations
* Fixing migrations order
* WIP
* Fixing some other compilation problems on tests
* Some typescript tests fixed
* Fixing javascript tests
* Fixing compilation
* Fixing some problems to create boards
* Load the templates on initial load
* Improvements over initial team templates import
* Adding new fields in the database
* Working on adding duplicate board api
* Removing RootID concept entirely
* Improving a bit the subscriptions
* Fixing store tests for notificationHints
* Fixing more tests
* fixing tests
* Fixing tests
* Fixing tests
* Fixing some small bugs related to templates
* Fixing registration link generation/regeneration
* Fixing cypress tests
* Adding store tests for duplicateBoard and duplicateBlock
* Addressing some TODO comments
* Making the export api simpler
* Add redirect component for old workspace urls
* Removing Dashboard code
* Delete only the built-in templates on update
* fixing tests
* Adding users autocompletion
* Updating snapshots
* Fixing bad merge
* fix panic when creating new card in notifysubscriptions (#2352)
* fix lint errors (#2353)
* fix lint errors
* fix panic when creating new card in notifysubscriptions (#2352)
* fix lint errors
* fix unit test
* Revert "fix unit test"
This reverts commit 0ad78aed65745521c0bb45790c9ea91b6c316c44.
Co-authored-by: Doug Lauder <wiggin77@warpmail.net>
* fix sql syntax error for SearchUsersByTeam (#2357)
* Fix mentions delivery (#2358)
* fix sql syntax error for SearchUsersByTeam
* fix mentions delivery
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* update api for octoClient calls, pass correct variables to mutator (#2359)
* Fixing tests after merge
* Fix sidebar context menu UI issue (#2399)
* Fix notification diff for text blocks (#2386)
* fix notification diff for text blocks; fix various linter errors.
* fix URLs to cards
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* Permissions branch: Fix card links (#2391)
* fix notification diff for text blocks; fix various linter errors.
* fix URLs to cards
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* Fixing sqlite tests
* Fixing server tests
* Update migrations to create global templates. (#2397)
* fix duplicate templates
* revert migrate.go
* update UI for empty templates
* implement updating built-in templates as global (teamId = 0)
* handle error if board not found
* update unit test
* fix more tests
* Update blocks_test.go
Fix merge issue
* fix migration sql error (#2414)
* Fixing frontend tests
* Set target team ID when using a global template (#2419)
* Fix some server tests
* Fixing onboarding creation
* Permissions branch: Fix unit tests and CI errors (part 1) (#2425)
* Fixing some small memory leaks (#2400)
* Fixing some small memory leaks
* fixing tests
* passing the tags to all test targets
* Increasing the timeout of the tests
* Fix some type checkings
* Permissions branch: Fixes all the linter errors (#2429)
* fix linter errors
* Reestructuring the router and splitting in more subcomponents (#2403)
* Reestructuring the router and splitting in more subcomponents
* Removing console.log calls
* Removing unneeded selector
* Addressing PR comment
* Fix redirection to one team when you load directly the boards home path
* Using properly the lastTeamID to redirect the user if needed
* don't allow last admin change/deleted (#2416)
* don't allow last admin change/deleted
* update for i18-extract
* fixed en.json
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Harshil Sharma <harshilsharma63@gmail.com>
* Splitting BoardPage component into simpler/smaller components (#2435)
* Splitting BoardPage component into simpler/smaller components
* Removing unneeded import
* Replace go migrate with morph permissions (#2424)
* merge origin/replace-go-migrate-with-morph
* run go mod tidy on mattermost-plugin and increase test timeout
* fix merge issue temprorarily
* remove some debug changes
* fixing the linter
* Allow always team 0 (global) templates fetch (#2472)
* Fix problem with viewId 0 in the URL (#2473)
* Migrate from binddata to goembed (#2471)
* Adding join logic to the board switcher (#2434)
* Adding join logic to the board switcher
* Using already existing client function and removing the joinBoard one
* Adding support for autojoin based on url
* Fixing frontend tests
* fix webapp compile error, missing enableSharedBoards (#2501)
* Fixing duplication on postgres
* Adding back views to the sidebar (#2494)
* Fix #2507. Update Swagger comments (#2508)
* Fix the flash of the template selector on board/team switch (#2490)
* Fix the flash of the template selector on board/team switch
* More fixes specially around error handling
* Fixing the bot badge (#2487)
* simplifying a bit the team store sync between channels and focalboard (#2481)
* Fix menu tests (#2528)
* fix failing menu tests
* fix lint error
* Added keyboard shortcut for boards switcher (#2407)
* Added keyboard shortcut for boards switcher
* Fixed a type error
* Added some inline comments
* Fixed lint
* Fixed bug with scroll jumping when the card is opened: (#2477)
- avoid remounting of `ScrollingComponent` for each render of `Kanban` component
- property `autoFocus` set to false for `CalculationOptions` because it triggers `blur` even for the button in Jest tests and closes the menu
- snapshots for tests with `CalculationOptions` updated
* Adding the frontend support for permissions and applying it to a big part of the interface. (#2536)
* Initial work on permissions gates
* Applying permissions gates in more places
* Adding more checks to the interface
* Adding more permissions gates and keeping the store up to date
* fixing some tests
* Fixing some more tests
* Fixing another test
* Fixing all tests and adding some more
* Adding no-permission snapshot tests
* Addressing PR review comments
* Fixing invert behavior
* Permissions branch: No sqlstore calls after app shutdown (#2530)
* fix webapp compile error, missing enableSharedBoards
* refactor app init wip
* - ensure all block change notifications are finished before shutting down app
- fix unit tests for mysql (insert_at only has 1 second resolution!)
* adjust logging
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* Fixed migrations to allow upgrading from previous version (#2535)
* Added mechanism to check if schema migration is needed
* WIP
* WIP
* WIP
* WIP
* Fixed migration
* Fixed for SQLite
* minor cleaniup
* Deleted old schema migration table after running migrations
* Removed a debug log
* Fixed a bug where the code always tried to delete a table which may or may not exist
* Show properly the user avatar in the ShareBoard component (#2542)
* Fixing the last CI problems from the permissions-branch (#2541)
* Fix history ordering
* Giving some times to avoid possible race conditions
* Empty
* Reverting accidental change in the config.json
* Optimizing table view (#2540)
* Optimizing table view
* Reducing the amount of rendering for tables
* Some other performance improvements
* Improve the activeView updates
* Some extra simplifications
* Another small improvement
* Fixing tests
* Fixing linter errors
* Reducing a bit the amount of dependency with big objects in the store
* Small simplification
* Removing Commenter role from the user role selector (#2561)
* Shareboard cleanup (#2550)
* Initial work on permissions gates
* Applying permissions gates in more places
* Adding more checks to the interface
* Adding more permissions gates and keeping the store up to date
* fixing some tests
* Fixing some more tests
* Fixing another test
* Fixing all tests and adding some more
* Adding no-permission snapshot tests
* Addressing PR review comments
* cleanup some shareboard settings
* remove unused property, fix for user items being displayed for non admin
* revert change, allow users to show
Co-authored-by: Jesús Espino <jespinog@gmail.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* GetBoardMetadata API
* Integration tests. WIP
* getBoardHistory
* Working integration test
* Fix ordering, add store tests
* Fix: Update board_history update_at on patch
* sqltests
* Fix unmarshall delete boards_history
* testGetBlockMetadata with delete and undelete
* Handle board not found
* Fixing comments and cards with the new optimizations in the store (#2560)
* Fixing property creation (#2563)
* Cleanup
* Fix user selection in table view (#2565)
* Fixing focus new row in table view (#2567)
* Permissions branch: Fix sqlite table lock (CI) (#2568)
* fix sqlite table lock
* remove test db on teardown
* revert .gitignore
* fix goimport on migration code
* fix typo
* more linter fixes
* clean up tmp db for sqlstore tests
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* Fixing snapshots
* Remove debug log
* Return metadata for deleted boards
* Migrating center panel to functional component (#2562)
* Migrating center panel to functional component
* Fixing some tests
* Fixing another test
* Fixing linter errors
* Fixing types errors
* Fixing linter error
* Fixing cypress tests
* Fixing the last cypress test
* Simpliying a bit the code
* Making property insertion more robust
* Updating checkbox test
* License check
* Cleanup and update Swagger docs
* Merge from main
* Fix bad merge
* Fix Linux-app build break
* do mod tidy
* Fix server lint
* Require credentials (not only read token)
* Add missing defer CloseRows
* do mod tidy
Co-authored-by: Harshil Sharma <harshilsharma63@gmail.com>
Co-authored-by: Miguel de la Cruz <miguel@mcrx.me>
Co-authored-by: Scott Bishel <scott.bishel@mattermost.com>
Co-authored-by: Jesús Espino <jespinog@gmail.com>
Co-authored-by: Doug Lauder <wiggin77@warpmail.net>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Harshil Sharma <18575143+harshilsharma63@users.noreply.github.com>
Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Co-authored-by: kamre <eremchenko@gmail.com>
2022-03-29 23:47:49 +02:00
|
|
|
t.Run("GetBlockMetadata", func(t *testing.T) {
|
|
|
|
store, tearDown := setup(t)
|
|
|
|
defer tearDown()
|
|
|
|
testGetBlockMetadata(t, store)
|
|
|
|
})
|
2021-01-29 17:50:20 +01:00
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func testInsertBlock(t *testing.T, store store.Store) {
|
2021-07-09 03:09:02 +02:00
|
|
|
userID := testUserID
|
2022-03-22 15:24:34 +01:00
|
|
|
boardID := testBoardID
|
2021-01-12 20:16:25 +01:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, errBlocks := store.GetBlocksForBoard(boardID)
|
2021-07-09 12:59:44 +02:00
|
|
|
require.NoError(t, errBlocks)
|
2021-01-06 04:47:18 +01:00
|
|
|
initialCount := len(blocks)
|
2020-10-18 01:09:12 +02:00
|
|
|
|
2021-01-29 19:21:55 +01:00
|
|
|
t.Run("valid block", func(t *testing.T) {
|
|
|
|
block := model.Block{
|
|
|
|
ID: "id-test",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: boardID,
|
2021-01-29 19:21:55 +01:00
|
|
|
ModifiedBy: userID,
|
|
|
|
}
|
2020-10-18 01:09:12 +02:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.InsertBlock(&block, "user-id-1")
|
2021-01-29 19:21:55 +01:00
|
|
|
require.NoError(t, err)
|
2020-10-18 01:09:12 +02:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err := store.GetBlocksForBoard(boardID)
|
2021-01-29 19:21:55 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, initialCount+1)
|
|
|
|
})
|
2020-10-18 01:09:12 +02:00
|
|
|
|
2021-01-29 19:21:55 +01:00
|
|
|
t.Run("invalid rootid", func(t *testing.T) {
|
|
|
|
block := model.Block{
|
|
|
|
ID: "id-test",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: "",
|
2021-01-29 19:21:55 +01:00
|
|
|
ModifiedBy: userID,
|
|
|
|
}
|
2020-10-18 01:09:12 +02:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.InsertBlock(&block, "user-id-1")
|
2021-01-29 19:21:55 +01:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err := store.GetBlocksForBoard(boardID)
|
2021-01-29 19:21:55 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, initialCount+1)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("invalid fields data", func(t *testing.T) {
|
|
|
|
block := model.Block{
|
|
|
|
ID: "id-test",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: "id-test",
|
2021-01-29 19:21:55 +01:00
|
|
|
ModifiedBy: userID,
|
|
|
|
Fields: map[string]interface{}{"no-serialiable-value": t.Run},
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.InsertBlock(&block, "user-id-1")
|
2021-01-29 19:21:55 +01:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err := store.GetBlocksForBoard(boardID)
|
2021-01-29 19:21:55 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, initialCount+1)
|
|
|
|
})
|
2021-07-08 16:36:43 +02:00
|
|
|
|
|
|
|
t.Run("insert new block", func(t *testing.T) {
|
|
|
|
block := model.Block{
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: testBoardID,
|
2021-07-08 16:36:43 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.InsertBlock(&block, "user-id-2")
|
2021-07-08 16:36:43 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, "user-id-2", block.CreatedBy)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("update existing block", func(t *testing.T) {
|
|
|
|
block := model.Block{
|
2022-03-22 15:24:34 +01:00
|
|
|
ID: "id-2",
|
|
|
|
BoardID: "board-id-1",
|
|
|
|
Title: "Old Title",
|
2021-07-08 16:36:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// inserting
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.InsertBlock(&block, "user-id-2")
|
2021-07-08 16:36:43 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// created by populated from user id for new blocks
|
|
|
|
require.Equal(t, "user-id-2", block.CreatedBy)
|
|
|
|
|
|
|
|
// hack to avoid multiple, quick updates to a card
|
|
|
|
// violating block_history composite primary key constraint
|
2022-03-22 15:24:34 +01:00
|
|
|
time.Sleep(1 * time.Millisecond)
|
2021-07-08 16:36:43 +02:00
|
|
|
|
|
|
|
// updating
|
|
|
|
newBlock := model.Block{
|
|
|
|
ID: "id-2",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: "board-id-1",
|
2021-07-08 16:36:43 +02:00
|
|
|
CreatedBy: "user-id-3",
|
|
|
|
Title: "New Title",
|
|
|
|
}
|
2022-03-22 15:24:34 +01:00
|
|
|
err = store.InsertBlock(&newBlock, "user-id-4")
|
2021-07-08 16:36:43 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
// created by is not altered for existing blocks
|
|
|
|
require.Equal(t, "user-id-3", newBlock.CreatedBy)
|
|
|
|
require.Equal(t, "New Title", newBlock.Title)
|
|
|
|
})
|
|
|
|
|
|
|
|
createdAt, err := time.Parse(time.RFC822, "01 Jan 90 01:00 IST")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
updateAt, err := time.Parse(time.RFC822, "02 Jan 90 01:00 IST")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("data tamper attempt", func(t *testing.T) {
|
|
|
|
block := model.Block{
|
2021-07-09 03:09:02 +02:00
|
|
|
ID: "id-10",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: "board-id-1",
|
2021-07-09 03:09:02 +02:00
|
|
|
Title: "Old Title",
|
2021-10-07 13:51:01 +02:00
|
|
|
CreateAt: utils.GetMillisForTime(createdAt),
|
|
|
|
UpdateAt: utils.GetMillisForTime(updateAt),
|
2021-07-09 03:09:02 +02:00
|
|
|
CreatedBy: "user-id-5",
|
2021-07-08 16:36:43 +02:00
|
|
|
ModifiedBy: "user-id-6",
|
|
|
|
}
|
|
|
|
|
|
|
|
// inserting
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.InsertBlock(&block, "user-id-1")
|
2021-07-08 16:36:43 +02:00
|
|
|
require.NoError(t, err)
|
2022-04-13 21:17:30 +02:00
|
|
|
expectedTime := time.Now()
|
2021-07-08 16:36:43 +02:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
retrievedBlock, err := store.GetBlock("id-10")
|
2021-07-08 16:36:43 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, retrievedBlock)
|
2022-03-22 15:24:34 +01:00
|
|
|
assert.Equal(t, "board-id-1", retrievedBlock.BoardID)
|
2021-07-08 16:36:43 +02:00
|
|
|
assert.Equal(t, "user-id-1", retrievedBlock.CreatedBy)
|
|
|
|
assert.Equal(t, "user-id-1", retrievedBlock.ModifiedBy)
|
2022-04-13 21:17:30 +02:00
|
|
|
assert.WithinDurationf(t, expectedTime, utils.GetTimeForMillis(retrievedBlock.CreateAt), 1*time.Second, "create time should be current time")
|
|
|
|
assert.WithinDurationf(t, expectedTime, utils.GetTimeForMillis(retrievedBlock.UpdateAt), 1*time.Second, "update time should be current time")
|
2021-07-08 16:36:43 +02:00
|
|
|
})
|
2020-10-18 01:09:12 +02:00
|
|
|
}
|
2020-11-12 19:48:08 +01:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func testInsertBlocks(t *testing.T, store store.Store) {
|
2021-12-10 15:17:00 +01:00
|
|
|
userID := testUserID
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, errBlocks := store.GetBlocksForBoard("id-test")
|
2021-12-10 15:17:00 +01:00
|
|
|
require.NoError(t, errBlocks)
|
|
|
|
initialCount := len(blocks)
|
|
|
|
|
|
|
|
t.Run("invalid block", func(t *testing.T) {
|
|
|
|
validBlock := model.Block{
|
|
|
|
ID: "id-test",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: "id-test",
|
2021-12-10 15:17:00 +01:00
|
|
|
ModifiedBy: userID,
|
|
|
|
}
|
|
|
|
|
|
|
|
invalidBlock := model.Block{
|
|
|
|
ID: "id-test",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: "",
|
2021-12-10 15:17:00 +01:00
|
|
|
ModifiedBy: userID,
|
|
|
|
}
|
|
|
|
|
|
|
|
newBlocks := []model.Block{validBlock, invalidBlock}
|
|
|
|
|
2022-02-22 22:30:47 +01:00
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.InsertBlocks(newBlocks, "user-id-1")
|
2021-12-10 15:17:00 +01:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err := store.GetBlocksForBoard("id-test")
|
2021-12-10 15:17:00 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
// no blocks should have been inserted
|
|
|
|
require.Len(t, blocks, initialCount)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func testPatchBlock(t *testing.T, store store.Store) {
|
2021-08-06 14:10:24 +02:00
|
|
|
userID := testUserID
|
2022-03-22 15:24:34 +01:00
|
|
|
boardID := "board-id-1"
|
2021-08-06 14:10:24 +02:00
|
|
|
|
|
|
|
block := model.Block{
|
|
|
|
ID: "id-test",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: boardID,
|
2021-08-06 14:10:24 +02:00
|
|
|
Title: "oldTitle",
|
|
|
|
ModifiedBy: userID,
|
|
|
|
Fields: map[string]interface{}{"test": "test value", "test2": "test value 2"},
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.InsertBlock(&block, "user-id-1")
|
2021-08-06 14:10:24 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, errBlocks := store.GetBlocksForBoard(boardID)
|
2021-08-06 14:10:24 +02:00
|
|
|
require.NoError(t, errBlocks)
|
|
|
|
initialCount := len(blocks)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
t.Run("not existing block id", func(t *testing.T) {
|
|
|
|
err := store.PatchBlock("invalid-block-id", &model.BlockPatch{}, "user-id-1")
|
2021-08-06 14:10:24 +02:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err := store.GetBlocksForBoard(boardID)
|
2021-08-06 14:10:24 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, initialCount)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("invalid rootid", func(t *testing.T) {
|
2022-03-22 15:24:34 +01:00
|
|
|
wrongBoardID := ""
|
2021-08-06 14:10:24 +02:00
|
|
|
blockPatch := model.BlockPatch{
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: &wrongBoardID,
|
2021-08-06 14:10:24 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.PatchBlock("id-test", &blockPatch, "user-id-1")
|
2021-08-06 14:10:24 +02:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err := store.GetBlocksForBoard(boardID)
|
2021-08-06 14:10:24 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, initialCount)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("invalid fields data", func(t *testing.T) {
|
|
|
|
blockPatch := model.BlockPatch{
|
|
|
|
UpdatedFields: map[string]interface{}{"no-serialiable-value": t.Run},
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.PatchBlock("id-test", &blockPatch, "user-id-1")
|
2021-08-06 14:10:24 +02:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err := store.GetBlocksForBoard(boardID)
|
2021-08-06 14:10:24 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, initialCount)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("update block fields", func(t *testing.T) {
|
|
|
|
newTitle := "New title"
|
|
|
|
blockPatch := model.BlockPatch{
|
|
|
|
Title: &newTitle,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for not colliding the ID+insert_at key
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
|
|
|
|
|
|
|
// inserting
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.PatchBlock("id-test", &blockPatch, "user-id-2")
|
2021-08-06 14:10:24 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
retrievedBlock, err := store.GetBlock("id-test")
|
2021-08-06 14:10:24 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// created by populated from user id for new blocks
|
|
|
|
require.Equal(t, "user-id-2", retrievedBlock.ModifiedBy)
|
|
|
|
require.Equal(t, "New title", retrievedBlock.Title)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("update block custom fields", func(t *testing.T) {
|
|
|
|
blockPatch := model.BlockPatch{
|
|
|
|
UpdatedFields: map[string]interface{}{"test": "new test value", "test3": "new value"},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for not colliding the ID+insert_at key
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
|
|
|
|
|
|
|
// inserting
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.PatchBlock("id-test", &blockPatch, "user-id-2")
|
2021-08-06 14:10:24 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
retrievedBlock, err := store.GetBlock("id-test")
|
2021-08-06 14:10:24 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// created by populated from user id for new blocks
|
|
|
|
require.Equal(t, "user-id-2", retrievedBlock.ModifiedBy)
|
|
|
|
require.Equal(t, "new test value", retrievedBlock.Fields["test"])
|
|
|
|
require.Equal(t, "test value 2", retrievedBlock.Fields["test2"])
|
|
|
|
require.Equal(t, "new value", retrievedBlock.Fields["test3"])
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("remove block custom fields", func(t *testing.T) {
|
|
|
|
blockPatch := model.BlockPatch{
|
|
|
|
DeletedFields: []string{"test", "test3", "test100"},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for not colliding the ID+insert_at key
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
|
|
|
|
|
|
|
// inserting
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.PatchBlock("id-test", &blockPatch, "user-id-2")
|
2021-08-06 14:10:24 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
retrievedBlock, err := store.GetBlock("id-test")
|
2021-08-06 14:10:24 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// created by populated from user id for new blocks
|
|
|
|
require.Equal(t, "user-id-2", retrievedBlock.ModifiedBy)
|
|
|
|
require.Equal(t, nil, retrievedBlock.Fields["test"])
|
|
|
|
require.Equal(t, "test value 2", retrievedBlock.Fields["test2"])
|
|
|
|
require.Equal(t, nil, retrievedBlock.Fields["test3"])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func testPatchBlocks(t *testing.T, store store.Store) {
|
2021-12-10 15:17:00 +01:00
|
|
|
block := model.Block{
|
2022-03-22 15:24:34 +01:00
|
|
|
ID: "id-test",
|
|
|
|
BoardID: "id-test",
|
|
|
|
Title: "oldTitle",
|
2021-12-10 15:17:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
block2 := model.Block{
|
2022-03-22 15:24:34 +01:00
|
|
|
ID: "id-test2",
|
|
|
|
BoardID: "id-test2",
|
|
|
|
Title: "oldTitle2",
|
2021-12-10 15:17:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
insertBlocks := []model.Block{block, block2}
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.InsertBlocks(insertBlocks, "user-id-1")
|
2021-12-10 15:17:00 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("successful updated existing blocks", func(t *testing.T) {
|
|
|
|
title := "updatedTitle"
|
|
|
|
blockPatch := model.BlockPatch{
|
|
|
|
Title: &title,
|
|
|
|
}
|
|
|
|
|
|
|
|
blockPatch2 := model.BlockPatch{
|
|
|
|
Title: &title,
|
|
|
|
}
|
|
|
|
|
|
|
|
blockIds := []string{"id-test", "id-test2"}
|
|
|
|
blockPatches := []model.BlockPatch{blockPatch, blockPatch2}
|
|
|
|
|
2022-02-22 18:42:49 +01:00
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.PatchBlocks(&model.BlockPatchBatch{BlockIDs: blockIds, BlockPatches: blockPatches}, "user-id-1")
|
2021-12-10 15:17:00 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
retrievedBlock, err := store.GetBlock("id-test")
|
2021-12-10 15:17:00 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, title, retrievedBlock.Title)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
retrievedBlock2, err := store.GetBlock("id-test2")
|
2021-12-10 15:17:00 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, title, retrievedBlock2.Title)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("invalid block id, nothing updated existing blocks", func(t *testing.T) {
|
2022-03-22 15:24:34 +01:00
|
|
|
if store.DBType() == model.SqliteDBType {
|
2022-02-22 22:30:47 +01:00
|
|
|
t.Skip("No transactions support int sqlite")
|
|
|
|
}
|
|
|
|
|
2021-12-10 15:17:00 +01:00
|
|
|
title := "Another Title"
|
|
|
|
blockPatch := model.BlockPatch{
|
|
|
|
Title: &title,
|
|
|
|
}
|
|
|
|
|
|
|
|
blockPatch2 := model.BlockPatch{
|
|
|
|
Title: &title,
|
|
|
|
}
|
|
|
|
|
|
|
|
blockIds := []string{"id-test", "invalid id"}
|
|
|
|
blockPatches := []model.BlockPatch{blockPatch, blockPatch2}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
time.Sleep(1 * time.Millisecond)
|
|
|
|
err := store.PatchBlocks(&model.BlockPatchBatch{BlockIDs: blockIds, BlockPatches: blockPatches}, "user-id-1")
|
2021-12-10 15:17:00 +01:00
|
|
|
require.Error(t, err)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
retrievedBlock, err := store.GetBlock("id-test")
|
2021-12-10 15:17:00 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEqual(t, title, retrievedBlock.Title)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-07-09 03:09:02 +02:00
|
|
|
var (
|
|
|
|
subtreeSampleBlocks = []model.Block{
|
2021-01-29 17:50:20 +01:00
|
|
|
{
|
2021-01-12 20:16:25 +01:00
|
|
|
ID: "parent",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: testBoardID,
|
2021-07-09 03:09:02 +02:00
|
|
|
ModifiedBy: testUserID,
|
2020-11-12 19:48:08 +01:00
|
|
|
},
|
2021-01-29 17:50:20 +01:00
|
|
|
{
|
2021-01-12 20:16:25 +01:00
|
|
|
ID: "child1",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: testBoardID,
|
2021-01-12 20:16:25 +01:00
|
|
|
ParentID: "parent",
|
2021-07-09 03:09:02 +02:00
|
|
|
ModifiedBy: testUserID,
|
2020-11-12 19:48:08 +01:00
|
|
|
},
|
2021-01-29 17:50:20 +01:00
|
|
|
{
|
2021-01-12 20:16:25 +01:00
|
|
|
ID: "child2",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: testBoardID,
|
2021-01-12 20:16:25 +01:00
|
|
|
ParentID: "parent",
|
2021-07-09 03:09:02 +02:00
|
|
|
ModifiedBy: testUserID,
|
2020-11-12 19:48:08 +01:00
|
|
|
},
|
2021-01-29 17:50:20 +01:00
|
|
|
{
|
2021-01-12 20:16:25 +01:00
|
|
|
ID: "grandchild1",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: testBoardID,
|
2021-01-12 20:16:25 +01:00
|
|
|
ParentID: "child1",
|
2021-07-09 03:09:02 +02:00
|
|
|
ModifiedBy: testUserID,
|
2020-11-12 19:48:08 +01:00
|
|
|
},
|
2021-01-29 17:50:20 +01:00
|
|
|
{
|
2021-01-12 20:16:25 +01:00
|
|
|
ID: "grandchild2",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: testBoardID,
|
2021-01-12 20:16:25 +01:00
|
|
|
ParentID: "child2",
|
2021-07-09 03:09:02 +02:00
|
|
|
ModifiedBy: testUserID,
|
2020-11-12 19:48:08 +01:00
|
|
|
},
|
2021-01-29 17:50:20 +01:00
|
|
|
{
|
2021-01-12 20:16:25 +01:00
|
|
|
ID: "greatgrandchild1",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: testBoardID,
|
2021-01-12 20:16:25 +01:00
|
|
|
ParentID: "grandchild1",
|
2021-07-09 03:09:02 +02:00
|
|
|
ModifiedBy: testUserID,
|
2020-11-12 19:48:08 +01:00
|
|
|
},
|
|
|
|
}
|
2021-07-09 03:09:02 +02:00
|
|
|
)
|
2020-11-12 19:48:08 +01:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func testGetSubTree2(t *testing.T, store store.Store) {
|
|
|
|
boardID := testBoardID
|
|
|
|
blocks, err := store.GetBlocksForBoard(boardID)
|
2021-07-09 03:09:02 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
initialCount := len(blocks)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
InsertBlocks(t, store, subtreeSampleBlocks, "user-id-1")
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
|
|
|
defer DeleteBlocks(t, store, subtreeSampleBlocks, "test")
|
2020-11-12 19:48:08 +01:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err = store.GetBlocksForBoard(boardID)
|
2021-01-06 04:47:18 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, initialCount+6)
|
|
|
|
|
2021-01-29 19:21:55 +01:00
|
|
|
t.Run("from root id", func(t *testing.T) {
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err = store.GetSubTree2(boardID, "parent", model.QuerySubtreeOptions{})
|
2021-01-29 19:21:55 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 3)
|
|
|
|
require.True(t, ContainsBlockWithID(blocks, "parent"))
|
|
|
|
require.True(t, ContainsBlockWithID(blocks, "child1"))
|
|
|
|
require.True(t, ContainsBlockWithID(blocks, "child2"))
|
|
|
|
})
|
2020-11-12 19:48:08 +01:00
|
|
|
|
2021-01-29 19:21:55 +01:00
|
|
|
t.Run("from child id", func(t *testing.T) {
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err = store.GetSubTree2(boardID, "child1", model.QuerySubtreeOptions{})
|
2021-01-29 19:21:55 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 2)
|
|
|
|
require.True(t, ContainsBlockWithID(blocks, "child1"))
|
|
|
|
require.True(t, ContainsBlockWithID(blocks, "grandchild1"))
|
|
|
|
})
|
2020-11-12 19:48:08 +01:00
|
|
|
|
2021-01-29 19:21:55 +01:00
|
|
|
t.Run("from not existing id", func(t *testing.T) {
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err = store.GetSubTree2(boardID, "not-exists", model.QuerySubtreeOptions{})
|
2021-01-29 19:21:55 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 0)
|
|
|
|
})
|
2020-11-12 19:48:08 +01:00
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func testDeleteBlock(t *testing.T, store store.Store) {
|
2021-07-09 03:09:02 +02:00
|
|
|
userID := testUserID
|
2022-03-22 15:24:34 +01:00
|
|
|
boardID := testBoardID
|
2021-01-29 19:32:33 +01:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err := store.GetBlocksForBoard(boardID)
|
2021-01-29 19:32:33 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
initialCount := len(blocks)
|
|
|
|
|
|
|
|
blocksToInsert := []model.Block{
|
|
|
|
{
|
|
|
|
ID: "block1",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: boardID,
|
2021-01-29 19:32:33 +01:00
|
|
|
ModifiedBy: userID,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "block2",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: boardID,
|
2021-01-29 19:32:33 +01:00
|
|
|
ModifiedBy: userID,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "block3",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: boardID,
|
2021-01-29 19:32:33 +01:00
|
|
|
ModifiedBy: userID,
|
|
|
|
},
|
|
|
|
}
|
2022-03-22 15:24:34 +01:00
|
|
|
InsertBlocks(t, store, blocksToInsert, "user-id-1")
|
|
|
|
defer DeleteBlocks(t, store, blocksToInsert, "test")
|
2021-01-29 19:32:33 +01:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err = store.GetBlocksForBoard(boardID)
|
2021-01-29 19:32:33 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, initialCount+3)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
t.Run("existing id", func(t *testing.T) {
|
2021-01-29 19:32:33 +01:00
|
|
|
// Wait for not colliding the ID+insert_at key
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.DeleteBlock("block1", userID)
|
2021-01-29 19:32:33 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
t.Run("existing id multiple times", func(t *testing.T) {
|
2021-01-29 19:32:33 +01:00
|
|
|
// Wait for not colliding the ID+insert_at key
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.DeleteBlock("block1", userID)
|
2021-01-29 19:32:33 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
// Wait for not colliding the ID+insert_at key
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
err = store.DeleteBlock("block1", userID)
|
2021-01-29 19:32:33 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("from not existing id", func(t *testing.T) {
|
|
|
|
// Wait for not colliding the ID+insert_at key
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.DeleteBlock("not-exists", userID)
|
2021-01-29 19:32:33 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
|
|
|
}
|
2021-04-30 16:31:04 +02:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func testUndeleteBlock(t *testing.T, store store.Store) {
|
|
|
|
boardID := testBoardID
|
2022-02-22 18:42:49 +01:00
|
|
|
userID := testUserID
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err := store.GetBlocksForBoard(boardID)
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
initialCount := len(blocks)
|
|
|
|
|
|
|
|
blocksToInsert := []model.Block{
|
|
|
|
{
|
|
|
|
ID: "block1",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: boardID,
|
2022-02-22 18:42:49 +01:00
|
|
|
ModifiedBy: userID,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "block2",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: boardID,
|
2022-02-22 18:42:49 +01:00
|
|
|
ModifiedBy: userID,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "block3",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: boardID,
|
2022-02-22 18:42:49 +01:00
|
|
|
ModifiedBy: userID,
|
|
|
|
},
|
|
|
|
}
|
2022-03-22 15:24:34 +01:00
|
|
|
InsertBlocks(t, store, blocksToInsert, "user-id-1")
|
|
|
|
defer DeleteBlocks(t, store, blocksToInsert, "test")
|
2022-02-22 18:42:49 +01:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err = store.GetBlocksForBoard(boardID)
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, initialCount+3)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
t.Run("existing id", func(t *testing.T) {
|
2022-02-22 18:42:49 +01:00
|
|
|
// Wait for not colliding the ID+insert_at key
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.DeleteBlock("block1", userID)
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
block, err := store.GetBlock("block1")
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, block)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
time.Sleep(1 * time.Millisecond)
|
|
|
|
err = store.UndeleteBlock("block1", userID)
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
block, err = store.GetBlock("block1")
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, block)
|
|
|
|
})
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
t.Run("existing id multiple times", func(t *testing.T) {
|
2022-02-22 18:42:49 +01:00
|
|
|
// Wait for not colliding the ID+insert_at key
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.DeleteBlock("block1", userID)
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
block, err := store.GetBlock("block1")
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, block)
|
|
|
|
|
|
|
|
// Wait for not colliding the ID+insert_at key
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
err = store.UndeleteBlock("block1", userID)
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
block, err = store.GetBlock("block1")
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, block)
|
|
|
|
|
|
|
|
// Wait for not colliding the ID+insert_at key
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
err = store.UndeleteBlock("block1", userID)
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
block, err = store.GetBlock("block1")
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, block)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("from not existing id", func(t *testing.T) {
|
|
|
|
// Wait for not colliding the ID+insert_at key
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.UndeleteBlock("not-exists", userID)
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
block, err := store.GetBlock("not-exists")
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, block)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func testGetBlocks(t *testing.T, store store.Store) {
|
|
|
|
boardID := testBoardID
|
|
|
|
blocks, err := store.GetBlocksForBoard(boardID)
|
2021-04-30 16:31:04 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
blocksToInsert := []model.Block{
|
|
|
|
{
|
|
|
|
ID: "block1",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: boardID,
|
2021-04-30 16:31:04 +02:00
|
|
|
ParentID: "",
|
2021-07-09 03:09:02 +02:00
|
|
|
ModifiedBy: testUserID,
|
2021-04-30 16:31:04 +02:00
|
|
|
Type: "test",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "block2",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: boardID,
|
2021-04-30 16:31:04 +02:00
|
|
|
ParentID: "block1",
|
2021-07-09 03:09:02 +02:00
|
|
|
ModifiedBy: testUserID,
|
2021-04-30 16:31:04 +02:00
|
|
|
Type: "test",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "block3",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: boardID,
|
2021-04-30 16:31:04 +02:00
|
|
|
ParentID: "block1",
|
2021-07-09 03:09:02 +02:00
|
|
|
ModifiedBy: testUserID,
|
2021-04-30 16:31:04 +02:00
|
|
|
Type: "test",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "block4",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: boardID,
|
2021-04-30 16:31:04 +02:00
|
|
|
ParentID: "block1",
|
2021-07-09 03:09:02 +02:00
|
|
|
ModifiedBy: testUserID,
|
2021-04-30 16:31:04 +02:00
|
|
|
Type: "test2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "block5",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: boardID,
|
2021-04-30 16:31:04 +02:00
|
|
|
ParentID: "block2",
|
2021-07-09 03:09:02 +02:00
|
|
|
ModifiedBy: testUserID,
|
2021-04-30 16:31:04 +02:00
|
|
|
Type: "test",
|
|
|
|
},
|
|
|
|
}
|
2022-03-22 15:24:34 +01:00
|
|
|
InsertBlocks(t, store, blocksToInsert, "user-id-1")
|
|
|
|
defer DeleteBlocks(t, store, blocksToInsert, "test")
|
2021-04-30 16:31:04 +02:00
|
|
|
|
|
|
|
t.Run("not existing parent", func(t *testing.T) {
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err = store.GetBlocksWithParentAndType(boardID, "not-exists", "test")
|
2021-04-30 16:31:04 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 0)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("not existing type", func(t *testing.T) {
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err = store.GetBlocksWithParentAndType(boardID, "block1", "not-existing")
|
2021-04-30 16:31:04 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 0)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("valid parent and type", func(t *testing.T) {
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err = store.GetBlocksWithParentAndType(boardID, "block1", "test")
|
2021-04-30 16:31:04 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 2)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("not existing parent", func(t *testing.T) {
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err = store.GetBlocksWithParent(boardID, "not-exists")
|
2021-04-30 16:31:04 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 0)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("valid parent", func(t *testing.T) {
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err = store.GetBlocksWithParent(boardID, "block1")
|
2021-04-30 16:31:04 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 3)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("not existing type", func(t *testing.T) {
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err = store.GetBlocksWithType(boardID, "not-exists")
|
2021-04-30 16:31:04 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 0)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("valid type", func(t *testing.T) {
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err = store.GetBlocksWithType(boardID, "test")
|
2021-04-30 16:31:04 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 4)
|
|
|
|
})
|
2021-05-13 23:04:49 +02:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
t.Run("not existing board", func(t *testing.T) {
|
2021-05-13 23:04:49 +02:00
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err = store.GetBlocksWithBoardID("not-exists")
|
2021-05-13 23:04:49 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 0)
|
|
|
|
})
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
t.Run("all blocks of the a board", func(t *testing.T) {
|
2021-05-13 23:04:49 +02:00
|
|
|
time.Sleep(1 * time.Millisecond)
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err = store.GetBlocksWithBoardID(boardID)
|
2021-05-13 23:04:49 +02:00
|
|
|
require.NoError(t, err)
|
2022-03-22 15:24:34 +01:00
|
|
|
require.Len(t, blocks, 5)
|
2021-05-13 23:04:49 +02:00
|
|
|
})
|
|
|
|
}
|
2021-07-08 16:36:43 +02:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func testGetBlock(t *testing.T, store store.Store) {
|
2021-07-08 16:36:43 +02:00
|
|
|
t.Run("get a block", func(t *testing.T) {
|
|
|
|
block := model.Block{
|
|
|
|
ID: "block-id-10",
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: "board-id-1",
|
2021-07-08 16:36:43 +02:00
|
|
|
ModifiedBy: "user-id-1",
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
err := store.InsertBlock(&block, "user-id-1")
|
2021-07-08 16:36:43 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
fetchedBlock, err := store.GetBlock("block-id-10")
|
2021-07-08 16:36:43 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, fetchedBlock)
|
|
|
|
require.Equal(t, "block-id-10", fetchedBlock.ID)
|
2022-03-22 15:24:34 +01:00
|
|
|
require.Equal(t, "board-id-1", fetchedBlock.BoardID)
|
2021-07-08 16:36:43 +02:00
|
|
|
require.Equal(t, "user-id-1", fetchedBlock.CreatedBy)
|
|
|
|
require.Equal(t, "user-id-1", fetchedBlock.ModifiedBy)
|
2021-10-07 13:51:01 +02:00
|
|
|
assert.WithinDurationf(t, time.Now(), utils.GetTimeForMillis(fetchedBlock.CreateAt), 1*time.Second, "create time should be current time")
|
|
|
|
assert.WithinDurationf(t, time.Now(), utils.GetTimeForMillis(fetchedBlock.UpdateAt), 1*time.Second, "update time should be current time")
|
2021-07-08 16:36:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("get a non-existing block", func(t *testing.T) {
|
2022-03-22 15:24:34 +01:00
|
|
|
fetchedBlock, err := store.GetBlock("non-existing-id")
|
2021-07-08 16:36:43 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, fetchedBlock)
|
|
|
|
})
|
|
|
|
}
|
2022-03-22 15:24:34 +01:00
|
|
|
|
|
|
|
func testDuplicateBlock(t *testing.T, store store.Store) {
|
2022-06-22 23:57:27 +02:00
|
|
|
blocksToInsert := subtreeSampleBlocks
|
|
|
|
blocksToInsert = append(blocksToInsert,
|
|
|
|
model.Block{
|
|
|
|
ID: "grandchild1a",
|
|
|
|
BoardID: testBoardID,
|
|
|
|
ParentID: "child1",
|
|
|
|
ModifiedBy: testUserID,
|
|
|
|
Type: model.TypeComment,
|
|
|
|
},
|
|
|
|
model.Block{
|
|
|
|
ID: "grandchild2a",
|
|
|
|
BoardID: testBoardID,
|
|
|
|
ParentID: "child2",
|
|
|
|
ModifiedBy: testUserID,
|
|
|
|
Type: model.TypeComment,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
InsertBlocks(t, store, blocksToInsert, "user-id-1")
|
2022-03-22 15:24:34 +01:00
|
|
|
time.Sleep(1 * time.Millisecond)
|
|
|
|
defer DeleteBlocks(t, store, subtreeSampleBlocks, "test")
|
|
|
|
|
|
|
|
t.Run("duplicate existing block as no template", func(t *testing.T) {
|
|
|
|
blocks, err := store.DuplicateBlock(testBoardID, "child1", testUserID, false)
|
|
|
|
require.NoError(t, err)
|
2022-04-06 16:04:21 +02:00
|
|
|
require.Len(t, blocks, 2)
|
2022-03-22 15:24:34 +01:00
|
|
|
require.Equal(t, false, blocks[0].Fields["isTemplate"])
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("duplicate existing block as template", func(t *testing.T) {
|
|
|
|
blocks, err := store.DuplicateBlock(testBoardID, "child1", testUserID, true)
|
|
|
|
require.NoError(t, err)
|
2022-04-06 16:04:21 +02:00
|
|
|
require.Len(t, blocks, 2)
|
2022-03-22 15:24:34 +01:00
|
|
|
require.Equal(t, true, blocks[0].Fields["isTemplate"])
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("duplicate not existing block", func(t *testing.T) {
|
|
|
|
blocks, err := store.DuplicateBlock(testBoardID, "not-existing-id", testUserID, false)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Nil(t, blocks)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("duplicate not existing board", func(t *testing.T) {
|
|
|
|
blocks, err := store.DuplicateBlock("not-existing-board", "not-existing-id", testUserID, false)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Nil(t, blocks)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("not matching board/block", func(t *testing.T) {
|
|
|
|
blocks, err := store.DuplicateBlock("other-id", "child1", testUserID, false)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Nil(t, blocks)
|
|
|
|
})
|
|
|
|
}
|
GetBoardMetadata API (#2569)
* wip
* Added data migration for populating categories
* wip
* Added data migration for populating categories
* Store WIP
* migration WIP
* category CRUD APIs complete
* category block API WIP
* block category update API done
* Fetcehed data into store
* Started displayting sidebar data
* sidebar WIP
* Dashboard - basic changes
* Sidebar dashboard btn and board switcher UI only
* Sidebar dashboard btn and board switcher UI only
* create category dialog WIP
* Create category webapp side done
* Integrated move card to other category
* board to block
* Disabled dashboard route for now as we'll implement it in phase 2
* WIP
* Added logic to open last board/view on per team level
* Add workspace to teams and boards migrations (#1986)
* Add workspace to teams and boards migrations
* Update json annotations on board models
* boards search dialog WIP
* Seach dialog WIP
* Implemented opening boiard from search results
* Boards switcher styliung
* Handled update category WS event
* Template support
* personal server support and styling fixes
* test fix WIP
* Fixed a bug causing boards to not be moved correctly beteen categories
* Fixed webapp tests
* fix
* Store changes (#2011)
* Permissions phase 1 - Websocket updates (#2014)
* Store changes
* Websockets changes
* Permissions phase 1 - Permissions service (#2015)
* Store changes
* Websockets changes
* Permissions service
* Api and app updates (#2016)
* Store changes
* Websockets changes
* Permissions service
* New API and App changes
* Delete and Patch boards and blocks endpoints
* Used correct variable
* Webapp changes WIP
* Open correct team URL
* Fixed get block API
* Used React context for workspace users
* WIP
* On load navigation sorted out
* WIP
* Nav fix
* categories WS broadcast
* Used real search API
* Fixed unfurl ppreview
* set active team in sidebar
* IMplemented navigation on changing team in sidebar
* Misc fixes
* close rows inside transaction (#2045)
* update syntax for mysql (#2044)
* Upadted mutator for new patchBlock API
* Updated patchBlock API to use new URL
* Listeining to correct event in plugin mode
* Implemented WS messages for category operations:
* Fix duplicated build tags on Makefile
* Sidebar enhancements
* Add missing prefix to SQLite migration and fix flaky tests
* Sidebar boards menu enhancement
* Fix board page interactions (#2144)
* Fix patch board card properties error
* Fix board interactions
* Fix insert blocks interactions
* Fix app tests (#2104)
* Add json1 tag to vscode launch (#2157)
* Fix add, delete and update boards and add board patch generation (#2146)
* Fix update boards and add board patch generation
* Make add board and add template work, as well as deleting a board
* Update the state on board deletion
* Delete unused variable
* Fix bad parenthesis
* Fix board creation inside plugin, options were coming null due websocket message serialization
* update property type mutators to use boards API (#2168)
* Add permissions modal (#2196)
* Initial integration
* Permissions modal, websocket updates and API tests implemented
* Avoid updating/removing user if there is only one admin left
* Fix duplicates on board search
* Adds integration test
* Addressing PR review comments
Co-authored-by: Jesús Espino <jespinog@gmail.com>
* Merge
* I'm able to compile now
* Some fixes around tests execution
* Fixing migrations
* Fixing migrations order
* WIP
* Fixing some other compilation problems on tests
* Some typescript tests fixed
* Fixing javascript tests
* Fixing compilation
* Fixing some problems to create boards
* Load the templates on initial load
* Improvements over initial team templates import
* Adding new fields in the database
* Working on adding duplicate board api
* Removing RootID concept entirely
* Improving a bit the subscriptions
* Fixing store tests for notificationHints
* Fixing more tests
* fixing tests
* Fixing tests
* Fixing tests
* Fixing some small bugs related to templates
* Fixing registration link generation/regeneration
* Fixing cypress tests
* Adding store tests for duplicateBoard and duplicateBlock
* Addressing some TODO comments
* Making the export api simpler
* Add redirect component for old workspace urls
* Removing Dashboard code
* Delete only the built-in templates on update
* fixing tests
* Adding users autocompletion
* Updating snapshots
* Fixing bad merge
* fix panic when creating new card in notifysubscriptions (#2352)
* fix lint errors (#2353)
* fix lint errors
* fix panic when creating new card in notifysubscriptions (#2352)
* fix lint errors
* fix unit test
* Revert "fix unit test"
This reverts commit 0ad78aed65745521c0bb45790c9ea91b6c316c44.
Co-authored-by: Doug Lauder <wiggin77@warpmail.net>
* fix sql syntax error for SearchUsersByTeam (#2357)
* Fix mentions delivery (#2358)
* fix sql syntax error for SearchUsersByTeam
* fix mentions delivery
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* update api for octoClient calls, pass correct variables to mutator (#2359)
* Fixing tests after merge
* Fix sidebar context menu UI issue (#2399)
* Fix notification diff for text blocks (#2386)
* fix notification diff for text blocks; fix various linter errors.
* fix URLs to cards
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* Permissions branch: Fix card links (#2391)
* fix notification diff for text blocks; fix various linter errors.
* fix URLs to cards
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* Fixing sqlite tests
* Fixing server tests
* Update migrations to create global templates. (#2397)
* fix duplicate templates
* revert migrate.go
* update UI for empty templates
* implement updating built-in templates as global (teamId = 0)
* handle error if board not found
* update unit test
* fix more tests
* Update blocks_test.go
Fix merge issue
* fix migration sql error (#2414)
* Fixing frontend tests
* Set target team ID when using a global template (#2419)
* Fix some server tests
* Fixing onboarding creation
* Permissions branch: Fix unit tests and CI errors (part 1) (#2425)
* Fixing some small memory leaks (#2400)
* Fixing some small memory leaks
* fixing tests
* passing the tags to all test targets
* Increasing the timeout of the tests
* Fix some type checkings
* Permissions branch: Fixes all the linter errors (#2429)
* fix linter errors
* Reestructuring the router and splitting in more subcomponents (#2403)
* Reestructuring the router and splitting in more subcomponents
* Removing console.log calls
* Removing unneeded selector
* Addressing PR comment
* Fix redirection to one team when you load directly the boards home path
* Using properly the lastTeamID to redirect the user if needed
* don't allow last admin change/deleted (#2416)
* don't allow last admin change/deleted
* update for i18-extract
* fixed en.json
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Harshil Sharma <harshilsharma63@gmail.com>
* Splitting BoardPage component into simpler/smaller components (#2435)
* Splitting BoardPage component into simpler/smaller components
* Removing unneeded import
* Replace go migrate with morph permissions (#2424)
* merge origin/replace-go-migrate-with-morph
* run go mod tidy on mattermost-plugin and increase test timeout
* fix merge issue temprorarily
* remove some debug changes
* fixing the linter
* Allow always team 0 (global) templates fetch (#2472)
* Fix problem with viewId 0 in the URL (#2473)
* Migrate from binddata to goembed (#2471)
* Adding join logic to the board switcher (#2434)
* Adding join logic to the board switcher
* Using already existing client function and removing the joinBoard one
* Adding support for autojoin based on url
* Fixing frontend tests
* fix webapp compile error, missing enableSharedBoards (#2501)
* Fixing duplication on postgres
* Adding back views to the sidebar (#2494)
* Fix #2507. Update Swagger comments (#2508)
* Fix the flash of the template selector on board/team switch (#2490)
* Fix the flash of the template selector on board/team switch
* More fixes specially around error handling
* Fixing the bot badge (#2487)
* simplifying a bit the team store sync between channels and focalboard (#2481)
* Fix menu tests (#2528)
* fix failing menu tests
* fix lint error
* Added keyboard shortcut for boards switcher (#2407)
* Added keyboard shortcut for boards switcher
* Fixed a type error
* Added some inline comments
* Fixed lint
* Fixed bug with scroll jumping when the card is opened: (#2477)
- avoid remounting of `ScrollingComponent` for each render of `Kanban` component
- property `autoFocus` set to false for `CalculationOptions` because it triggers `blur` even for the button in Jest tests and closes the menu
- snapshots for tests with `CalculationOptions` updated
* Adding the frontend support for permissions and applying it to a big part of the interface. (#2536)
* Initial work on permissions gates
* Applying permissions gates in more places
* Adding more checks to the interface
* Adding more permissions gates and keeping the store up to date
* fixing some tests
* Fixing some more tests
* Fixing another test
* Fixing all tests and adding some more
* Adding no-permission snapshot tests
* Addressing PR review comments
* Fixing invert behavior
* Permissions branch: No sqlstore calls after app shutdown (#2530)
* fix webapp compile error, missing enableSharedBoards
* refactor app init wip
* - ensure all block change notifications are finished before shutting down app
- fix unit tests for mysql (insert_at only has 1 second resolution!)
* adjust logging
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* Fixed migrations to allow upgrading from previous version (#2535)
* Added mechanism to check if schema migration is needed
* WIP
* WIP
* WIP
* WIP
* Fixed migration
* Fixed for SQLite
* minor cleaniup
* Deleted old schema migration table after running migrations
* Removed a debug log
* Fixed a bug where the code always tried to delete a table which may or may not exist
* Show properly the user avatar in the ShareBoard component (#2542)
* Fixing the last CI problems from the permissions-branch (#2541)
* Fix history ordering
* Giving some times to avoid possible race conditions
* Empty
* Reverting accidental change in the config.json
* Optimizing table view (#2540)
* Optimizing table view
* Reducing the amount of rendering for tables
* Some other performance improvements
* Improve the activeView updates
* Some extra simplifications
* Another small improvement
* Fixing tests
* Fixing linter errors
* Reducing a bit the amount of dependency with big objects in the store
* Small simplification
* Removing Commenter role from the user role selector (#2561)
* Shareboard cleanup (#2550)
* Initial work on permissions gates
* Applying permissions gates in more places
* Adding more checks to the interface
* Adding more permissions gates and keeping the store up to date
* fixing some tests
* Fixing some more tests
* Fixing another test
* Fixing all tests and adding some more
* Adding no-permission snapshot tests
* Addressing PR review comments
* cleanup some shareboard settings
* remove unused property, fix for user items being displayed for non admin
* revert change, allow users to show
Co-authored-by: Jesús Espino <jespinog@gmail.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* GetBoardMetadata API
* Integration tests. WIP
* getBoardHistory
* Working integration test
* Fix ordering, add store tests
* Fix: Update board_history update_at on patch
* sqltests
* Fix unmarshall delete boards_history
* testGetBlockMetadata with delete and undelete
* Handle board not found
* Fixing comments and cards with the new optimizations in the store (#2560)
* Fixing property creation (#2563)
* Cleanup
* Fix user selection in table view (#2565)
* Fixing focus new row in table view (#2567)
* Permissions branch: Fix sqlite table lock (CI) (#2568)
* fix sqlite table lock
* remove test db on teardown
* revert .gitignore
* fix goimport on migration code
* fix typo
* more linter fixes
* clean up tmp db for sqlstore tests
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* Fixing snapshots
* Remove debug log
* Return metadata for deleted boards
* Migrating center panel to functional component (#2562)
* Migrating center panel to functional component
* Fixing some tests
* Fixing another test
* Fixing linter errors
* Fixing types errors
* Fixing linter error
* Fixing cypress tests
* Fixing the last cypress test
* Simpliying a bit the code
* Making property insertion more robust
* Updating checkbox test
* License check
* Cleanup and update Swagger docs
* Merge from main
* Fix bad merge
* Fix Linux-app build break
* do mod tidy
* Fix server lint
* Require credentials (not only read token)
* Add missing defer CloseRows
* do mod tidy
Co-authored-by: Harshil Sharma <harshilsharma63@gmail.com>
Co-authored-by: Miguel de la Cruz <miguel@mcrx.me>
Co-authored-by: Scott Bishel <scott.bishel@mattermost.com>
Co-authored-by: Jesús Espino <jespinog@gmail.com>
Co-authored-by: Doug Lauder <wiggin77@warpmail.net>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Harshil Sharma <18575143+harshilsharma63@users.noreply.github.com>
Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Co-authored-by: kamre <eremchenko@gmail.com>
2022-03-29 23:47:49 +02:00
|
|
|
|
|
|
|
func testGetBlockMetadata(t *testing.T, store store.Store) {
|
|
|
|
boardID := testBoardID
|
|
|
|
blocks, err := store.GetBlocksForBoard(boardID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
blocksToInsert := []model.Block{
|
|
|
|
{
|
|
|
|
ID: "block1",
|
|
|
|
BoardID: boardID,
|
|
|
|
ParentID: "",
|
|
|
|
ModifiedBy: testUserID,
|
|
|
|
Type: "test",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "block2",
|
|
|
|
BoardID: boardID,
|
|
|
|
ParentID: "block1",
|
|
|
|
ModifiedBy: testUserID,
|
|
|
|
Type: "test",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "block3",
|
|
|
|
BoardID: boardID,
|
|
|
|
ParentID: "block1",
|
|
|
|
ModifiedBy: testUserID,
|
|
|
|
Type: "test",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "block4",
|
|
|
|
BoardID: boardID,
|
|
|
|
ParentID: "block1",
|
|
|
|
ModifiedBy: testUserID,
|
|
|
|
Type: "test2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "block5",
|
|
|
|
BoardID: boardID,
|
|
|
|
ParentID: "block2",
|
|
|
|
ModifiedBy: testUserID,
|
|
|
|
Type: "test",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range blocksToInsert {
|
|
|
|
time.Sleep(20 * time.Millisecond)
|
|
|
|
subBlocks := []model.Block{v}
|
|
|
|
InsertBlocks(t, store, subBlocks, testUserID)
|
|
|
|
}
|
|
|
|
defer DeleteBlocks(t, store, blocksToInsert, "test")
|
|
|
|
|
|
|
|
t.Run("get full block history", func(t *testing.T) {
|
|
|
|
opts := model.QueryBlockHistoryOptions{
|
|
|
|
Descending: false,
|
|
|
|
}
|
|
|
|
blocks, err = store.GetBlockHistoryDescendants(boardID, opts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 5)
|
|
|
|
expectedBlock := blocksToInsert[0]
|
|
|
|
block := blocks[0]
|
|
|
|
|
|
|
|
require.Equal(t, expectedBlock.ID, block.ID)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("get full block history descending", func(t *testing.T) {
|
|
|
|
opts := model.QueryBlockHistoryOptions{
|
|
|
|
Descending: true,
|
|
|
|
}
|
|
|
|
blocks, err = store.GetBlockHistoryDescendants(boardID, opts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 5)
|
|
|
|
expectedBlock := blocksToInsert[len(blocksToInsert)-1]
|
|
|
|
block := blocks[0]
|
|
|
|
|
|
|
|
require.Equal(t, expectedBlock.ID, block.ID)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("get limited block history", func(t *testing.T) {
|
|
|
|
opts := model.QueryBlockHistoryOptions{
|
|
|
|
Limit: 3,
|
|
|
|
Descending: false,
|
|
|
|
}
|
|
|
|
blocks, err = store.GetBlockHistoryDescendants(boardID, opts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 3)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("get first block history", func(t *testing.T) {
|
|
|
|
opts := model.QueryBlockHistoryOptions{
|
|
|
|
Limit: 1,
|
|
|
|
Descending: false,
|
|
|
|
}
|
|
|
|
blocks, err = store.GetBlockHistoryDescendants(boardID, opts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 1)
|
|
|
|
expectedBlock := blocksToInsert[0]
|
|
|
|
block := blocks[0]
|
|
|
|
|
|
|
|
require.Equal(t, expectedBlock.ID, block.ID)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("get last block history", func(t *testing.T) {
|
|
|
|
opts := model.QueryBlockHistoryOptions{
|
|
|
|
Limit: 1,
|
|
|
|
Descending: true,
|
|
|
|
}
|
|
|
|
blocks, err = store.GetBlockHistoryDescendants(boardID, opts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 1)
|
|
|
|
expectedBlock := blocksToInsert[len(blocksToInsert)-1]
|
|
|
|
block := blocks[0]
|
|
|
|
|
|
|
|
require.Equal(t, expectedBlock.ID, block.ID)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("get block history after updateAt", func(t *testing.T) {
|
|
|
|
rBlocks, err2 := store.GetBlocksWithType(boardID, "test")
|
|
|
|
require.NoError(t, err2)
|
|
|
|
require.NotZero(t, rBlocks[2].UpdateAt)
|
|
|
|
|
|
|
|
opts := model.QueryBlockHistoryOptions{
|
|
|
|
AfterUpdateAt: rBlocks[2].UpdateAt,
|
|
|
|
Descending: false,
|
|
|
|
}
|
|
|
|
blocks, err = store.GetBlockHistoryDescendants(boardID, opts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 2)
|
|
|
|
expectedBlock := blocksToInsert[3]
|
|
|
|
block := blocks[0]
|
|
|
|
|
|
|
|
require.Equal(t, expectedBlock.ID, block.ID)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("get block history before updateAt", func(t *testing.T) {
|
|
|
|
rBlocks, err2 := store.GetBlocksWithType(boardID, "test")
|
|
|
|
require.NoError(t, err2)
|
|
|
|
require.NotZero(t, rBlocks[2].UpdateAt)
|
|
|
|
|
|
|
|
opts := model.QueryBlockHistoryOptions{
|
|
|
|
BeforeUpdateAt: rBlocks[2].UpdateAt,
|
|
|
|
Descending: true,
|
|
|
|
}
|
|
|
|
blocks, err = store.GetBlockHistoryDescendants(boardID, opts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 2)
|
|
|
|
expectedBlock := blocksToInsert[1]
|
|
|
|
block := blocks[0]
|
|
|
|
|
|
|
|
require.Equal(t, expectedBlock.ID, block.ID)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("get full block history after delete", func(t *testing.T) {
|
|
|
|
time.Sleep(20 * time.Millisecond)
|
|
|
|
err = store.DeleteBlock(blocksToInsert[0].ID, testUserID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
opts := model.QueryBlockHistoryOptions{
|
|
|
|
Descending: true,
|
|
|
|
}
|
|
|
|
blocks, err = store.GetBlockHistoryDescendants(boardID, opts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 6)
|
|
|
|
expectedBlock := blocksToInsert[0]
|
|
|
|
block := blocks[0]
|
|
|
|
|
|
|
|
require.Equal(t, expectedBlock.ID, block.ID)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("get full block history after undelete", func(t *testing.T) {
|
|
|
|
time.Sleep(20 * time.Millisecond)
|
|
|
|
err = store.UndeleteBlock(blocksToInsert[0].ID, testUserID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
opts := model.QueryBlockHistoryOptions{
|
|
|
|
Descending: true,
|
|
|
|
}
|
|
|
|
blocks, err = store.GetBlockHistoryDescendants(boardID, opts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, blocks, 7)
|
|
|
|
expectedBlock := blocksToInsert[0]
|
|
|
|
block := blocks[0]
|
|
|
|
|
|
|
|
require.Equal(t, expectedBlock.ID, block.ID)
|
|
|
|
})
|
|
|
|
}
|