MM-30918 Fix product notice check when user setting is missing (#16396)

Этот коммит содержится в:
Eli Yukelzon
2020-11-25 09:30:44 +02:00
коммит произвёл GitHub
родитель 5642d3106e
Коммит bcb861717e
2 изменённых файлов: 20 добавлений и 5 удалений

Просмотреть файл

@@ -19,7 +19,7 @@ import (
"github.com/Masterminds/semver/v3"
"github.com/pkg/errors"
"github.com/reflog/dateconstraints"
date_constraints "github.com/reflog/dateconstraints"
)
const MAX_REPEAT_VIEWINGS = 3
@@ -179,7 +179,7 @@ func validateUserConfigEntry(preferences store.PreferenceStore, userId string, k
}
pref, err := preferences.Get(userId, parts[0], parts[1])
if err != nil {
return false, err
return false, nil
}
return pref.Value == expectedValue, nil
}

Просмотреть файл

@@ -4,15 +4,17 @@
package app
import (
"errors"
"fmt"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
"github.com/stretchr/testify/require"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
"github.com/stretchr/testify/require"
)
func TestNoticeValidation(t *testing.T) {
@@ -37,6 +39,7 @@ func TestNoticeValidation(t *testing.T) {
mockUserStore.On("Count", model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: true, ExcludeRegularUsers: false, TeamId: "", ChannelId: "", ViewRestrictions: (*model.ViewUsersRestrictions)(nil), Roles: []string(nil), ChannelRoles: []string(nil), TeamRoles: []string(nil)}).Return(int64(1), nil)
mockPreferenceStore.On("Get", "test", "Stuff", "Data").Return(&model.Preference{Value: "test2"}, nil)
mockPreferenceStore.On("Get", "test", "Stuff", "Data2").Return(&model.Preference{Value: "test"}, nil)
mockPreferenceStore.On("Get", "test", "Stuff", "Data3").Return(nil, errors.New("Error!"))
mockPostStore.On("GetMaxPostSize").Return(65535, nil)
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -160,6 +163,18 @@ func TestNoticeValidation(t *testing.T) {
wantErr: false,
wantOk: true,
},
{
name: "notice with user check for property not in database",
args: args{
notice: &model.ProductNotice{
Conditions: model.Conditions{
UserConfig: map[string]interface{}{"Stuff.Data3": "stuff"},
},
},
},
wantErr: false,
wantOk: false,
},
{
name: "notice with server version check",
args: args{