2021-12-10 16:46:37 +01:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
|
|
|
|
2020-10-18 01:09:12 +02:00
|
|
|
package sqlstore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
[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 08:12:02 +02:00
|
|
|
"github.com/mattermost/focalboard/server/model"
|
2021-01-29 17:50:20 +01:00
|
|
|
"github.com/mattermost/focalboard/server/services/store/storetests"
|
[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 08:12:02 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-10-18 01:09:12 +02:00
|
|
|
)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func TestSQLStore(t *testing.T) {
|
2021-01-29 17:50:20 +01:00
|
|
|
t.Run("BlocksStore", func(t *testing.T) { storetests.StoreTestBlocksStore(t, SetupTests) })
|
2021-01-29 20:27:43 +01:00
|
|
|
t.Run("SharingStore", func(t *testing.T) { storetests.StoreTestSharingStore(t, SetupTests) })
|
2021-04-30 16:48:45 +02:00
|
|
|
t.Run("SystemStore", func(t *testing.T) { storetests.StoreTestSystemStore(t, SetupTests) })
|
2021-06-04 15:23:15 +02:00
|
|
|
t.Run("UserStore", func(t *testing.T) { storetests.StoreTestUserStore(t, SetupTests) })
|
2021-07-22 13:56:25 +02:00
|
|
|
t.Run("SessionStore", func(t *testing.T) { storetests.StoreTestSessionStore(t, SetupTests) })
|
2022-03-22 15:24:34 +01:00
|
|
|
t.Run("TeamStore", func(t *testing.T) { storetests.StoreTestTeamStore(t, SetupTests) })
|
|
|
|
t.Run("BoardStore", func(t *testing.T) { storetests.StoreTestBoardStore(t, SetupTests) })
|
|
|
|
t.Run("BoardsAndBlocksStore", func(t *testing.T) { storetests.StoreTestBoardsAndBlocksStore(t, SetupTests) })
|
2021-12-10 16:46:37 +01:00
|
|
|
t.Run("SubscriptionStore", func(t *testing.T) { storetests.StoreTestSubscriptionsStore(t, SetupTests) })
|
|
|
|
t.Run("NotificationHintStore", func(t *testing.T) { storetests.StoreTestNotificationHintsStore(t, SetupTests) })
|
2022-04-25 20:58:08 +02:00
|
|
|
t.Run("DataRetention", func(t *testing.T) { storetests.StoreTestDataRetention(t, SetupTests) })
|
2022-06-15 12:17:44 +02:00
|
|
|
t.Run("CloudStore", func(t *testing.T) { storetests.StoreTestCloudStore(t, SetupTests) })
|
2022-06-13 10:05:42 +02:00
|
|
|
t.Run("StoreTestFileStore", func(t *testing.T) { storetests.StoreTestFileStore(t, SetupTests) })
|
2022-08-08 22:55:47 +02:00
|
|
|
t.Run("StoreTestCategoryStore", func(t *testing.T) { storetests.StoreTestCategoryStore(t, SetupTests) })
|
|
|
|
t.Run("StoreTestCategoryBoardsStore", func(t *testing.T) { storetests.StoreTestCategoryBoardsStore(t, SetupTests) })
|
[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 08:12:02 +02:00
|
|
|
t.Run("BoardsInsightsStore", func(t *testing.T) { storetests.StoreTestBoardsInsightsStore(t, SetupTests) })
|
|
|
|
}
|
|
|
|
|
|
|
|
// tests for utility functions inside sqlstore.go
|
|
|
|
|
|
|
|
func TestConcatenationSelector(t *testing.T) {
|
|
|
|
store, tearDown := SetupTests(t)
|
|
|
|
sqlStore := store.(*SQLStore)
|
|
|
|
defer tearDown()
|
|
|
|
|
|
|
|
concatenationString := sqlStore.concatenationSelector("a", ",")
|
|
|
|
switch sqlStore.dbType {
|
|
|
|
case model.SqliteDBType:
|
|
|
|
require.Equal(t, concatenationString, "group_concat(a)")
|
|
|
|
case model.MysqlDBType:
|
|
|
|
require.Equal(t, concatenationString, "GROUP_CONCAT(a SEPARATOR ',')")
|
|
|
|
case model.PostgresDBType:
|
|
|
|
require.Equal(t, concatenationString, "string_agg(a, ',')")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestElementInColumn(t *testing.T) {
|
|
|
|
store, tearDown := SetupTests(t)
|
|
|
|
sqlStore := store.(*SQLStore)
|
|
|
|
defer tearDown()
|
|
|
|
|
|
|
|
inLiteral := sqlStore.elementInColumn("test_column")
|
|
|
|
switch sqlStore.dbType {
|
|
|
|
case model.SqliteDBType:
|
|
|
|
require.Equal(t, inLiteral, "instr(test_column, ?) > 0")
|
|
|
|
case model.MysqlDBType:
|
|
|
|
require.Equal(t, inLiteral, "instr(test_column, ?) > 0")
|
|
|
|
case model.PostgresDBType:
|
|
|
|
require.Equal(t, inLiteral, "position(? in test_column) > 0")
|
|
|
|
}
|
2020-11-12 19:48:08 +01:00
|
|
|
}
|