ab3bf6312c
* Persistent user config (#2133) * Added user config API * Add unit tests * lint fix * Fixed webapp tests * Fixed webapp tests * Updated props in store after updating * Minor fixes * Removed redundent data from audit logs * Onboarding Tour (#2287) * Created private board * Roughly displayed tour * Synced with Dhama's changes * WIP * Trying to add GIF * Added 3 tour steps * WIP * WIP * WIP * checked in missed file * Synced with feature branch * WIp * Adde skip tour option * Fixed image loading for on-prem * Made tour work on presonal server: * Adde missed file * Adding telemetry * Adding telemetry * Added tour tip telemetry * Fixed pulsating dot styling for personal server * reverted personal config * Added reset tour button * Displayed share tour tip of feature is enabled * Lint fixes * Fixed webapp tests * Fixed webapp tests * Completed webapp tests * Completed webapp tests * Webapp lint fixes * Added server tests * Testing cypress skip tour fix * Fixed Cypress tests * Added share board tour step * Added share board tour step * webapp lint fixes * Updated logic to pick welcome board * Updated tests: * lint fixes * Updating UI changes * Fixed a bug causing card tour to re-appear * FIxed minor issue * FIxed bug where card tour didn't start in clickingh on card * Fixed tests * Make update user props use string instead of interface * Fixed a value type * Updating gif size * Updating resolution breakpoint * Updating tutorial tip * Updating view selector * Refactored tour components * Misc fixes * minor refactoring * GH-2258: allow date range to overflow (#2268) * allow date range to overflow * Fixed issue with date overflowing into neighbouring column Co-authored-by: Harshil Sharma <harshilsharma63@gmail.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com> * Update readme with accurate Linux standalone app build instructions (#2351) * Bump follow-redirects from 1.14.7 to 1.14.8 in /experiments/webext (#2339) Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.14.7 to 1.14.8. - [Release notes](https://github.com/follow-redirects/follow-redirects/releases) - [Commits](https://github.com/follow-redirects/follow-redirects/compare/v1.14.7...v1.14.8) --- updated-dependencies: - dependency-name: follow-redirects dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Switch component style fixed: selector specificity increased by adding additional class. (#2179) * Adding sever side undelete endpoint (#2222) * Adding sever side undelete endpoint * Removing long lines golangci-lint errors * Fixing linter errors * Fixing a test problem * Fixing tests Co-authored-by: Mattermod <mattermod@users.noreply.github.com> * Removing transactions from sqlite backend (#2361) * Removing transactions from sqlite backend * Skipping tests in sqlite because the lack of transactions * Generating the mocks * Fixing golangci-lint * Fixing problem opening the tour tooltip on card open * Fixing texts missmatch * Adding the Product Tour entry in the user settings menu * Fixing some tests * Fixing tests Co-authored-by: Asaad Mahmood <asaadmahmood@users.noreply.github.com> Co-authored-by: Scott Bishel <scott.bishel@mattermost.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Doug Lauder <wiggin77@warpmail.net> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: kamre <eremchenko@gmail.com> Co-authored-by: Jesús Espino <jespinog@gmail.com> * Restored package json * Restored package json Co-authored-by: Asaad Mahmood <asaadmahmood@users.noreply.github.com> Co-authored-by: Scott Bishel <scott.bishel@mattermost.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Doug Lauder <wiggin77@warpmail.net> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: kamre <eremchenko@gmail.com> Co-authored-by: Jesús Espino <jespinog@gmail.com>
229 lines
6.1 KiB
Go
229 lines
6.1 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package storetests
|
|
|
|
import (
|
|
"database/sql"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
"github.com/mattermost/focalboard/server/services/store"
|
|
"github.com/mattermost/focalboard/server/utils"
|
|
)
|
|
|
|
func StoreTestUserStore(t *testing.T, setup func(t *testing.T) (store.Store, func())) {
|
|
t.Run("SetGetSystemSettings", func(t *testing.T) {
|
|
store, tearDown := setup(t)
|
|
defer tearDown()
|
|
testGetWorkspaceUsers(t, store)
|
|
})
|
|
|
|
t.Run("CreateAndGetUser", func(t *testing.T) {
|
|
store, tearDown := setup(t)
|
|
defer tearDown()
|
|
testCreateAndGetUser(t, store)
|
|
})
|
|
|
|
t.Run("CreateAndUpateUser", func(t *testing.T) {
|
|
store, tearDown := setup(t)
|
|
defer tearDown()
|
|
testCreateAndUpdateUser(t, store)
|
|
})
|
|
|
|
t.Run("CreateAndGetRegisteredUserCount", func(t *testing.T) {
|
|
store, tearDown := setup(t)
|
|
defer tearDown()
|
|
testCreateAndGetRegisteredUserCount(t, store)
|
|
})
|
|
t.Run("TestPatchUserProps", func(t *testing.T) {
|
|
store, tearDown := setup(t)
|
|
defer tearDown()
|
|
testPatchUserProps(t, store)
|
|
})
|
|
}
|
|
|
|
func testGetWorkspaceUsers(t *testing.T, store store.Store) {
|
|
t.Run("GetWorkspaceUSers", func(t *testing.T) {
|
|
users, err := store.GetUsersByWorkspace("workspace_1")
|
|
require.Equal(t, 0, len(users))
|
|
require.Equal(t, sql.ErrNoRows, err)
|
|
|
|
userID := utils.NewID(utils.IDTypeUser)
|
|
|
|
err = store.CreateUser(&model.User{
|
|
ID: userID,
|
|
Username: "darth.vader",
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
defer func() {
|
|
_ = store.UpdateUser(&model.User{
|
|
ID: userID,
|
|
DeleteAt: utils.GetMillis(),
|
|
})
|
|
}()
|
|
|
|
users, err = store.GetUsersByWorkspace("workspace_1")
|
|
require.Equal(t, 1, len(users))
|
|
require.Equal(t, "darth.vader", users[0].Username)
|
|
require.NoError(t, err)
|
|
})
|
|
}
|
|
|
|
func testCreateAndGetUser(t *testing.T, store store.Store) {
|
|
user := &model.User{
|
|
ID: utils.NewID(utils.IDTypeUser),
|
|
Username: "damao",
|
|
Email: "mock@email.com",
|
|
}
|
|
|
|
t.Run("CreateUser", func(t *testing.T) {
|
|
err := store.CreateUser(user)
|
|
require.NoError(t, err)
|
|
})
|
|
|
|
t.Run("GetUserByID", func(t *testing.T) {
|
|
got, err := store.GetUserByID(user.ID)
|
|
require.NoError(t, err)
|
|
require.Equal(t, user.ID, got.ID)
|
|
require.Equal(t, user.Username, got.Username)
|
|
require.Equal(t, user.Email, got.Email)
|
|
})
|
|
|
|
t.Run("GetUserByUsername", func(t *testing.T) {
|
|
got, err := store.GetUserByUsername(user.Username)
|
|
require.NoError(t, err)
|
|
require.Equal(t, user.ID, got.ID)
|
|
require.Equal(t, user.Username, got.Username)
|
|
require.Equal(t, user.Email, got.Email)
|
|
})
|
|
|
|
t.Run("GetUserByEmail", func(t *testing.T) {
|
|
got, err := store.GetUserByEmail(user.Email)
|
|
require.NoError(t, err)
|
|
require.Equal(t, user.ID, got.ID)
|
|
require.Equal(t, user.Username, got.Username)
|
|
require.Equal(t, user.Email, got.Email)
|
|
})
|
|
}
|
|
|
|
func testCreateAndUpdateUser(t *testing.T, store store.Store) {
|
|
user := &model.User{
|
|
ID: utils.NewID(utils.IDTypeUser),
|
|
}
|
|
err := store.CreateUser(user)
|
|
require.NoError(t, err)
|
|
|
|
t.Run("UpdateUser", func(t *testing.T) {
|
|
user.Username = "damao"
|
|
user.Email = "mock@email.com"
|
|
user.Props = map[string]interface{}{"a": "b"}
|
|
err := store.UpdateUser(user)
|
|
require.NoError(t, err)
|
|
|
|
got, err := store.GetUserByID(user.ID)
|
|
require.NoError(t, err)
|
|
require.Equal(t, user.ID, got.ID)
|
|
require.Equal(t, user.Username, got.Username)
|
|
require.Equal(t, user.Email, got.Email)
|
|
require.Equal(t, user.Props, got.Props)
|
|
})
|
|
|
|
t.Run("UpdateUserPassword", func(t *testing.T) {
|
|
newPassword := utils.NewID(utils.IDTypeNone)
|
|
err := store.UpdateUserPassword(user.Username, newPassword)
|
|
require.NoError(t, err)
|
|
|
|
got, err := store.GetUserByUsername(user.Username)
|
|
require.NoError(t, err)
|
|
require.Equal(t, user.Username, got.Username)
|
|
require.Equal(t, newPassword, got.Password)
|
|
})
|
|
|
|
t.Run("UpdateUserPasswordByID", func(t *testing.T) {
|
|
newPassword := utils.NewID(utils.IDTypeNone)
|
|
err := store.UpdateUserPasswordByID(user.ID, newPassword)
|
|
require.NoError(t, err)
|
|
|
|
got, err := store.GetUserByID(user.ID)
|
|
require.NoError(t, err)
|
|
require.Equal(t, user.ID, got.ID)
|
|
require.Equal(t, newPassword, got.Password)
|
|
})
|
|
}
|
|
|
|
func testCreateAndGetRegisteredUserCount(t *testing.T, store store.Store) {
|
|
randomN := int(time.Now().Unix() % 10)
|
|
for i := 0; i < randomN; i++ {
|
|
err := store.CreateUser(&model.User{
|
|
ID: utils.NewID(utils.IDTypeUser),
|
|
})
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
got, err := store.GetRegisteredUserCount()
|
|
require.NoError(t, err)
|
|
require.Equal(t, randomN, got)
|
|
}
|
|
|
|
func testPatchUserProps(t *testing.T, store store.Store) {
|
|
user := &model.User{
|
|
ID: utils.NewID(utils.IDTypeUser),
|
|
}
|
|
err := store.CreateUser(user)
|
|
require.NoError(t, err)
|
|
|
|
// Only update props
|
|
patch := model.UserPropPatch{
|
|
UpdatedFields: map[string]string{
|
|
"new_key_1": "new_value_1",
|
|
"new_key_2": "new_value_2",
|
|
"new_key_3": "new_value_3",
|
|
},
|
|
}
|
|
|
|
err = store.PatchUserProps(user.ID, patch)
|
|
require.NoError(t, err)
|
|
fetchedUser, err := store.GetUserByID(user.ID)
|
|
require.NoError(t, err)
|
|
require.Equal(t, fetchedUser.Props["new_key_1"], "new_value_1")
|
|
require.Equal(t, fetchedUser.Props["new_key_2"], "new_value_2")
|
|
require.Equal(t, fetchedUser.Props["new_key_3"], "new_value_3")
|
|
|
|
// Delete a prop
|
|
patch = model.UserPropPatch{
|
|
DeletedFields: []string{
|
|
"new_key_1",
|
|
},
|
|
}
|
|
|
|
err = store.PatchUserProps(user.ID, patch)
|
|
require.NoError(t, err)
|
|
fetchedUser, err = store.GetUserByID(user.ID)
|
|
require.NoError(t, err)
|
|
_, ok := fetchedUser.Props["new_key_1"]
|
|
require.False(t, ok)
|
|
require.Equal(t, fetchedUser.Props["new_key_2"], "new_value_2")
|
|
require.Equal(t, fetchedUser.Props["new_key_3"], "new_value_3")
|
|
|
|
// update and delete together
|
|
patch = model.UserPropPatch{
|
|
UpdatedFields: map[string]string{
|
|
"new_key_3": "new_value_3_new_again",
|
|
},
|
|
DeletedFields: []string{
|
|
"new_key_2",
|
|
},
|
|
}
|
|
err = store.PatchUserProps(user.ID, patch)
|
|
require.NoError(t, err)
|
|
fetchedUser, err = store.GetUserByID(user.ID)
|
|
require.NoError(t, err)
|
|
_, ok = fetchedUser.Props["new_key_2"]
|
|
require.False(t, ok)
|
|
require.Equal(t, fetchedUser.Props["new_key_3"], "new_value_3_new_again")
|
|
}
|