focalboard/server/services/permissions/localpermissions/helpers_test.go
Doug Lauder 936cc820ab
Standardize err not found (#2834)
* cleanup log levels

* Standardize on model.IsErrNotFound instead of the mix of error checking done previously.

* fix merge conflicts

* fix comment typo

* add description to asserts
2022-04-20 11:02:12 -04:00

61 lines
1.7 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package localpermissions
import (
"testing"
"github.com/mattermost/focalboard/server/model"
permissionsMocks "github.com/mattermost/focalboard/server/services/permissions/mocks"
mmModel "github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/shared/mlog"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
)
type TestHelper struct {
t *testing.T
ctrl *gomock.Controller
store *permissionsMocks.MockStore
permissions *Service
}
func SetupTestHelper(t *testing.T) *TestHelper {
ctrl := gomock.NewController(t)
mockStore := permissionsMocks.NewMockStore(ctrl)
return &TestHelper{
t: t,
ctrl: ctrl,
store: mockStore,
permissions: New(mockStore, mlog.CreateConsoleTestLogger(false, mlog.LvlDebug)),
}
}
func (th *TestHelper) checkBoardPermissions(roleName string, member *model.BoardMember, hasPermissionTo, hasNotPermissionTo []*mmModel.Permission) {
for _, p := range hasPermissionTo {
th.t.Run(roleName+" "+p.Id, func(t *testing.T) {
th.store.EXPECT().
GetMemberForBoard(member.BoardID, member.UserID).
Return(member, nil).
Times(1)
hasPermission := th.permissions.HasPermissionToBoard(member.UserID, member.BoardID, p)
assert.True(t, hasPermission)
})
}
for _, p := range hasNotPermissionTo {
th.t.Run(roleName+" "+p.Id, func(t *testing.T) {
th.store.EXPECT().
GetMemberForBoard(member.BoardID, member.UserID).
Return(member, nil).
Times(1)
hasPermission := th.permissions.HasPermissionToBoard(member.UserID, member.BoardID, p)
assert.False(t, hasPermission)
})
}
}