Files
team/server/channels/app/migrations_test.go
David KrauserandGitHub 2bda9ac2df [MM-66836] Integrate PropertyAccessService into API and app layers (#34818)
Updates all Custom Profile Attribute endpoints and app layer methods to pass caller user IDs through to the PropertyAccessService. This connects the access control service introduced in #34812 to the REST API, Plugin API, and internal app operations.

Also updates the OpenAPI spec to document the new field attributes (protected, source_plugin_id, access_mode) and adds notes about protected field restrictions.
2026-02-06 18:06:51 -05:00

59 lines
2.2 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
import (
"testing"
"github.com/mattermost/mattermost/server/public/model"
"github.com/stretchr/testify/require"
)
func TestDoSetupContentFlaggingProperties(t *testing.T) {
t.Run("should register property group and fields", func(t *testing.T) {
//we need to call the Setup method and run the full setup instead of
//just creating a new server via NewServer() because the Setup method
//also takes care of using the correct database DSN based on environment,
//settings, setting up the store and initializing services used in store such as property services.
th := Setup(t)
group, err := th.Server.propertyAccessService.GetPropertyGroup(model.ContentFlaggingGroupName)
require.NoError(t, err)
require.NotNil(t, group)
require.Equal(t, model.ContentFlaggingGroupName, group.Name)
propertyFields, err := th.Server.propertyAccessService.SearchPropertyFields(anonymousCallerId, group.ID, model.PropertyFieldSearchOpts{PerPage: 100})
require.NoError(t, err)
require.Len(t, propertyFields, 11)
data, err := th.Store.System().GetByName(contentFlaggingSetupDoneKey)
require.NoError(t, err)
require.Equal(t, "v5", data.Value)
})
t.Run("the migration is idempotent", func(t *testing.T) {
th := Setup(t)
// Now we will remove the migration done key from systems table to allow the data migration to run again
_, err := th.Store.System().PermanentDeleteByName(contentFlaggingSetupDoneKey)
require.NoError(t, err)
// Run the content flagging data migration again
err = th.Server.doSetupContentFlaggingProperties()
require.NoError(t, err)
group, err := th.Server.propertyAccessService.GetPropertyGroup(model.ContentFlaggingGroupName)
require.NoError(t, err)
require.Equal(t, model.ContentFlaggingGroupName, group.Name)
propertyFields, err := th.Server.propertyAccessService.SearchPropertyFields(anonymousCallerId, group.ID, model.PropertyFieldSearchOpts{PerPage: 100})
require.NoError(t, err)
require.Len(t, propertyFields, 11)
data, err := th.Store.System().GetByName(contentFlaggingSetupDoneKey)
require.NoError(t, err)
require.Equal(t, "v5", data.Value)
})
}