mirror of
https://github.com/mattermost/mattermost.git
synced 2026-02-03 20:40:00 -05:00
Some checks failed
API / build (push) Waiting to run
Server CI / Compute Go Version (push) Waiting to run
Server CI / Check mocks (push) Blocked by required conditions
Server CI / Check go mod tidy (push) Blocked by required conditions
Server CI / check-style (push) Blocked by required conditions
Server CI / Check serialization methods for hot structs (push) Blocked by required conditions
Server CI / Vet API (push) Blocked by required conditions
Server CI / Check migration files (push) Blocked by required conditions
Server CI / Generate email templates (push) Blocked by required conditions
Server CI / Check store layers (push) Blocked by required conditions
Server CI / Check mmctl docs (push) Blocked by required conditions
Server CI / Postgres with binary parameters (push) Blocked by required conditions
Server CI / Postgres (push) Blocked by required conditions
Server CI / Postgres (FIPS) (push) Blocked by required conditions
Server CI / Generate Test Coverage (push) Blocked by required conditions
Server CI / Run mmctl tests (push) Blocked by required conditions
Server CI / Run mmctl tests (FIPS) (push) Blocked by required conditions
Server CI / Build mattermost server app (push) Blocked by required conditions
Web App CI / check-lint (push) Waiting to run
Web App CI / check-i18n (push) Waiting to run
Web App CI / check-types (push) Waiting to run
Web App CI / test (push) Waiting to run
Web App CI / build (push) Waiting to run
Migration-assist Sync / Check if migration-assist have been synced (push) Has been cancelled
* lint fix * CI * added new migration mocks * Used setup for tests * some comment * Removed unnecesseery nil check * Form validation * WIP tests * WIP tests * WIP tests * fix: mock content flagging config selector with correct reasons format Co-authored-by: aider (anthropic/claude-sonnet-4-20250514) <aider@aider.chat> * fix: add mock for getContentFlaggingConfig in flag post modal test Co-authored-by: aider (anthropic/claude-sonnet-4-20250514) <aider@aider.chat> * Updated error code order in API docs * removed empty files * Added tests * lint fixes * minor tweak * lint fix * type fix * fixed test * nit * test enhancements * API WIP * API WIP * creating values * creating content flagging channel and properties * Able to save properties * Added another property field * WIP * WIP * Added validations * Added data validations and hidden post if confifgured to * lint fixes * Added API spec * Added some tests * Added tests for getContentReviewBot * test: add comprehensive tests for getContentReviewChannels function * Added more app layer tests * Added TestCanFlagPost * test: Add comprehensive tests for FlagPost function * Added all app layer tests * Removed a file that was reamoved downstream * test: add content flagging test file * test: add comprehensive tests for FlagContentRequest.IsValid method * Added model tests * test: add comprehensive tests for SqlPropertyValueStore.CreateMany * test: add comprehensive tests for flagPost() API function * Added API tests * linter fix * WIP * sent post flagging confirmation message * fixed i18n nissues * fixed i18n nissues * CI * WIP * WIP * Added API call * test: add test for Client4.flagPost API call in FlagPostModal * fix: remove userEvent.setup() from flag post modal test * test: wrap submit button click in act for proper state updates * Updated tests * lint fix * Updated test * fix: reset contentFlaggingGroupId for test isolation in content flagging tests * removed cached group ID * removed debug log * CI * Updated to allow special characters in comments * Handled empty comment * Created getContentFlaggingFields API * created getPostPropertyValues API * Used finally * WIP * Created useContentFlaggingFields hook * WIP * WIP * Added option to retain data for reviewers * Displayed deleted post's preview * DIsplayed all properties * Adding field name i18n * WIP - managing i18n able texts * Finished displaying all fields * Manual cleanup * lint fixes * team role filter logic fix * Fixed tests * created new API to fetch flagged posts * lint fix * Added new client methods * test: add comprehensive tests for content flagging APIs * Added new API tests * fixed openapi spec * Fixed DataSpillageReport tests * Fixed PostMarkdown test * Fixed PostPreviewPropertyRenderer test * Added metadata to card renderer * test fixes * Added no comment placeholder * Added view detail button * Created RemoveFlaggedMessageConfirmationModal modal * Added key and remove flag request modal * IMplemented delete flagged post * Handled edge cases of deleting flagged post * keep message * UI integration * Added WS event for post report update and handled deleted files of flagged post * Added error handling in keep/remove forms * i18n fixes * Fixed test * Updated OpenAPI specs * fixed types * fixed types * refactoring * refactor: improve test mocking for data spillage report component * test mock updates * Fixed tests * Updated reducer * not resetting mocks * Added migrations for content flagging tables * Created new structure * review fixes * Used correct ot name * WIP * review fixes * review fixes * Added new property translations * CI * CI * CI * Improved test * fixed test * CI * New UI component * WIP * Updated settings APIs * cached DB data * used cached reviewer data * Updated tests * Lint fixes * test: add tests for saveContentFlaggingSettings and getContentFlaggingSettings APIs * test fix * test: add tests for SaveContentFlaggingConfig and GetContentFlaggingConfigReviewerIDs * Updated tests * test: add content flagging test for local cache layer * test: add comprehensive tests for content flagging store cache * Updated tests * lint fix * Updated mobile text * Added content flagging SQL store mocks * Added API specs for new APIs * fixed tests * feat: add TestContentFlaggingStore function for content flagging store testing * feat: add comprehensive tests for content flagging store * Added SQL store tests * test: add content flagging test for local cache layer * test: add tests for content flagging store caching * Added cache layer tests * Updated tests * Fixed * Handled JSON error * fixes * fixes * Fixed retry layer test * fixerdf i18n * Fixed test * CI * building index concurrently * CI * fixed a test * CI * cleanup * Integrate flag post api (#33798) * WIP * WIP * Added API call * test: add test for Client4.flagPost API call in FlagPostModal * fix: remove userEvent.setup() from flag post modal test * test: wrap submit button click in act for proper state updates * Updated tests * lint fix * CI * Updated to allow special characters in comments * Handled empty comment * Used finally * CI * Fixed test * Spillage card integration (#33832) * Created getContentFlaggingFields API * created getPostPropertyValues API * WIP * Created useContentFlaggingFields hook * WIP * WIP * Added option to retain data for reviewers * Displayed deleted post's preview * DIsplayed all properties * Adding field name i18n * WIP - managing i18n able texts * Finished displaying all fields * Manual cleanup * lint fixes * team role filter logic fix * Fixed tests * created new API to fetch flagged posts * lint fix * Added new client methods * test: add comprehensive tests for content flagging APIs * Added new API tests * fixed openapi spec * Fixed DataSpillageReport tests * Fixed PostMarkdown test * Fixed PostPreviewPropertyRenderer test * Added metadata to card renderer * test fixes * Added no comment placeholder * Fixed test * refactor: improve test mocking for data spillage report component * test mock updates * Updated reducer * not resetting mocks * WIP * review fixes * CI * Fixed * fixes * Content flagging actions implementation (#33852) * Added view detail button * Created RemoveFlaggedMessageConfirmationModal modal * Added key and remove flag request modal * IMplemented delete flagged post * Handled edge cases of deleting flagged post * keep message * UI integration * Added WS event for post report update and handled deleted files of flagged post * Added error handling in keep/remove forms * i18n fixes * Updated OpenAPI specs * fixed types * fixed types * refactoring * Fixed tests * review fixes * Added new property translations * Improved test * fixed test * CI * fixes * CI * fixed a test * CI * Review fixes --------- Co-authored-by: aider (anthropic/claude-sonnet-4-20250514) <aider@aider.chat>
379 lines
12 KiB
Go
379 lines
12 KiB
Go
package model
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestContentFlaggingNotificationSettings_SetDefault(t *testing.T) {
|
|
t.Run("should set default event target mappings", func(t *testing.T) {
|
|
settings := &ContentFlaggingNotificationSettings{}
|
|
settings.SetDefaults()
|
|
|
|
require.Nil(t, settings.IsValid())
|
|
|
|
require.NotNil(t, settings.EventTargetMapping)
|
|
require.Equal(t, []NotificationTarget{TargetReviewers}, settings.EventTargetMapping[EventFlagged])
|
|
require.Equal(t, []NotificationTarget{TargetReviewers}, settings.EventTargetMapping[EventAssigned])
|
|
require.Equal(t, []NotificationTarget{TargetReviewers, TargetAuthor, TargetReporter}, settings.EventTargetMapping[EventContentRemoved])
|
|
require.Equal(t, []NotificationTarget{TargetReviewers, TargetReporter}, settings.EventTargetMapping[EventContentDismissed])
|
|
})
|
|
|
|
t.Run("should not override existing mappings", func(t *testing.T) {
|
|
settings := &ContentFlaggingNotificationSettings{
|
|
EventTargetMapping: map[ContentFlaggingEvent][]NotificationTarget{
|
|
EventFlagged: {TargetReviewers},
|
|
},
|
|
}
|
|
settings.SetDefaults()
|
|
|
|
require.Nil(t, settings.IsValid())
|
|
require.Equal(t, []NotificationTarget{TargetReviewers}, settings.EventTargetMapping[EventFlagged])
|
|
require.Equal(t, []NotificationTarget{TargetReviewers}, settings.EventTargetMapping[EventAssigned])
|
|
})
|
|
}
|
|
|
|
func TestContentFlaggingNotificationSettings_IsValid(t *testing.T) {
|
|
t.Run("should be valid when reviewers are notified for flagged events", func(t *testing.T) {
|
|
settings := &ContentFlaggingNotificationSettings{
|
|
EventTargetMapping: map[ContentFlaggingEvent][]NotificationTarget{
|
|
EventFlagged: {TargetReviewers, TargetAuthor},
|
|
},
|
|
}
|
|
|
|
err := settings.IsValid()
|
|
require.Nil(t, err)
|
|
})
|
|
|
|
t.Run("should be invalid when no targets for flagged events", func(t *testing.T) {
|
|
settings := &ContentFlaggingNotificationSettings{
|
|
EventTargetMapping: map[ContentFlaggingEvent][]NotificationTarget{
|
|
EventFlagged: {},
|
|
},
|
|
}
|
|
|
|
err := settings.IsValid()
|
|
require.NotNil(t, err)
|
|
require.Equal(t, "model.config.is_valid.notification_settings.reviewer_flagged_notification_disabled", err.Id)
|
|
})
|
|
|
|
t.Run("should be invalid when flagged event mapping is nil", func(t *testing.T) {
|
|
settings := &ContentFlaggingNotificationSettings{
|
|
EventTargetMapping: map[ContentFlaggingEvent][]NotificationTarget{},
|
|
}
|
|
|
|
err := settings.IsValid()
|
|
require.NotNil(t, err)
|
|
require.Equal(t, "model.config.is_valid.notification_settings.reviewer_flagged_notification_disabled", err.Id)
|
|
})
|
|
|
|
t.Run("should be invalid when reviewers not included in flagged event targets", func(t *testing.T) {
|
|
settings := &ContentFlaggingNotificationSettings{
|
|
EventTargetMapping: map[ContentFlaggingEvent][]NotificationTarget{
|
|
EventFlagged: {TargetAuthor, TargetReporter},
|
|
},
|
|
}
|
|
|
|
err := settings.IsValid()
|
|
require.NotNil(t, err)
|
|
require.Equal(t, "model.config.is_valid.notification_settings.reviewer_flagged_notification_disabled", err.Id)
|
|
})
|
|
|
|
t.Run("should be invalid when invalid events and targets are specified", func(t *testing.T) {
|
|
settings := &ContentFlaggingNotificationSettings{
|
|
EventTargetMapping: map[ContentFlaggingEvent][]NotificationTarget{
|
|
"invalid_event": {TargetAuthor, TargetReporter},
|
|
},
|
|
}
|
|
|
|
err := settings.IsValid()
|
|
require.NotNil(t, err)
|
|
require.Equal(t, "model.config.is_valid.notification_settings.invalid_event", err.Id)
|
|
|
|
settings = &ContentFlaggingNotificationSettings{
|
|
EventTargetMapping: map[ContentFlaggingEvent][]NotificationTarget{
|
|
EventFlagged: {"invalid_target_1", "invalid_target_2"},
|
|
},
|
|
}
|
|
|
|
err = settings.IsValid()
|
|
require.NotNil(t, err)
|
|
require.Equal(t, "model.config.is_valid.notification_settings.invalid_target", err.Id)
|
|
|
|
settings = &ContentFlaggingNotificationSettings{
|
|
EventTargetMapping: map[ContentFlaggingEvent][]NotificationTarget{
|
|
"invalid_event": {"invalid_target_1", "invalid_target_2"},
|
|
},
|
|
}
|
|
|
|
err = settings.IsValid()
|
|
require.NotNil(t, err)
|
|
require.Equal(t, "model.config.is_valid.notification_settings.invalid_event", err.Id)
|
|
})
|
|
}
|
|
|
|
func TestReviewerSettings_IsValid(t *testing.T) {
|
|
t.Run("should be valid when common reviewers enabled with reviewer IDs", func(t *testing.T) {
|
|
settings := &ReviewSettingsRequest{
|
|
ReviewerSettings: ReviewerSettings{
|
|
CommonReviewers: NewPointer(true),
|
|
SystemAdminsAsReviewers: NewPointer(false),
|
|
TeamAdminsAsReviewers: NewPointer(false),
|
|
},
|
|
ReviewerIDsSettings: ReviewerIDsSettings{
|
|
CommonReviewerIds: []string{"user1", "user2"},
|
|
TeamReviewersSetting: map[string]*TeamReviewerSetting{},
|
|
},
|
|
}
|
|
|
|
err := settings.IsValid()
|
|
require.Nil(t, err)
|
|
})
|
|
|
|
t.Run("should be valid when common reviewers enabled with Additional Reviewers", func(t *testing.T) {
|
|
settings := &ReviewSettingsRequest{
|
|
ReviewerSettings: ReviewerSettings{
|
|
CommonReviewers: NewPointer(true),
|
|
SystemAdminsAsReviewers: NewPointer(true),
|
|
TeamAdminsAsReviewers: NewPointer(false),
|
|
},
|
|
ReviewerIDsSettings: ReviewerIDsSettings{
|
|
CommonReviewerIds: []string{},
|
|
TeamReviewersSetting: map[string]*TeamReviewerSetting{},
|
|
},
|
|
}
|
|
|
|
err := settings.IsValid()
|
|
require.Nil(t, err)
|
|
})
|
|
|
|
t.Run("should be invalid when common reviewers enabled but no reviewers specified", func(t *testing.T) {
|
|
settings := &ReviewSettingsRequest{
|
|
ReviewerSettings: ReviewerSettings{
|
|
CommonReviewers: NewPointer(true),
|
|
SystemAdminsAsReviewers: NewPointer(false),
|
|
TeamAdminsAsReviewers: NewPointer(false),
|
|
},
|
|
ReviewerIDsSettings: ReviewerIDsSettings{
|
|
CommonReviewerIds: []string{},
|
|
TeamReviewersSetting: map[string]*TeamReviewerSetting{},
|
|
},
|
|
}
|
|
|
|
err := settings.IsValid()
|
|
require.NotNil(t, err)
|
|
require.Equal(t, "model.config.is_valid.content_flagging.common_reviewers_not_set.app_error", err.Id)
|
|
})
|
|
|
|
t.Run("should be valid when team reviewers enabled with reviewer IDs", func(t *testing.T) {
|
|
settings := &ReviewSettingsRequest{
|
|
ReviewerSettings: ReviewerSettings{
|
|
CommonReviewers: NewPointer(false),
|
|
SystemAdminsAsReviewers: NewPointer(false),
|
|
TeamAdminsAsReviewers: NewPointer(false),
|
|
},
|
|
ReviewerIDsSettings: ReviewerIDsSettings{
|
|
CommonReviewerIds: []string{},
|
|
TeamReviewersSetting: map[string]*TeamReviewerSetting{
|
|
"team1": {
|
|
Enabled: NewPointer(true),
|
|
ReviewerIds: []string{"user1"},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
err := settings.IsValid()
|
|
require.Nil(t, err)
|
|
})
|
|
|
|
t.Run("should be invalid when team reviewers enabled but no reviewer IDs", func(t *testing.T) {
|
|
settings := &ReviewSettingsRequest{
|
|
ReviewerSettings: ReviewerSettings{
|
|
CommonReviewers: NewPointer(false),
|
|
SystemAdminsAsReviewers: NewPointer(false),
|
|
TeamAdminsAsReviewers: NewPointer(false),
|
|
},
|
|
ReviewerIDsSettings: ReviewerIDsSettings{
|
|
CommonReviewerIds: []string{},
|
|
TeamReviewersSetting: map[string]*TeamReviewerSetting{
|
|
"team1": {
|
|
Enabled: NewPointer(true),
|
|
ReviewerIds: []string{},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
err := settings.IsValid()
|
|
require.NotNil(t, err)
|
|
require.Equal(t, "model.config.is_valid.content_flagging.team_reviewers_not_set.app_error", err.Id)
|
|
})
|
|
|
|
t.Run("should be valid when team reviewers enabled but no reviewer IDs with Additional Reviewers", func(t *testing.T) {
|
|
settings := &ReviewSettingsRequest{
|
|
ReviewerSettings: ReviewerSettings{
|
|
CommonReviewers: NewPointer(false),
|
|
SystemAdminsAsReviewers: NewPointer(true),
|
|
TeamAdminsAsReviewers: NewPointer(false),
|
|
},
|
|
ReviewerIDsSettings: ReviewerIDsSettings{
|
|
CommonReviewerIds: []string{},
|
|
TeamReviewersSetting: map[string]*TeamReviewerSetting{
|
|
"team1": {
|
|
Enabled: NewPointer(true),
|
|
ReviewerIds: []string{},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
err := settings.IsValid()
|
|
require.Nil(t, err)
|
|
})
|
|
}
|
|
|
|
func TestAdditionalContentFlaggingSettings_SetDefault(t *testing.T) {
|
|
t.Run("should not override existing values", func(t *testing.T) {
|
|
customReasons := []string{"Custom reason"}
|
|
settings := &AdditionalContentFlaggingSettings{
|
|
Reasons: &customReasons,
|
|
}
|
|
settings.SetDefaults()
|
|
|
|
require.Nil(t, settings.IsValid())
|
|
require.Equal(t, customReasons, *settings.Reasons)
|
|
})
|
|
}
|
|
|
|
func TestAdditionalContentFlaggingSettings_IsValid(t *testing.T) {
|
|
t.Run("should be valid when reasons are provided", func(t *testing.T) {
|
|
settings := &AdditionalContentFlaggingSettings{
|
|
Reasons: &[]string{"Reason 1", "Reason 2"},
|
|
}
|
|
|
|
err := settings.IsValid()
|
|
require.Nil(t, err)
|
|
})
|
|
|
|
t.Run("should be invalid when reasons are nil", func(t *testing.T) {
|
|
settings := &AdditionalContentFlaggingSettings{
|
|
Reasons: nil,
|
|
}
|
|
|
|
err := settings.IsValid()
|
|
require.NotNil(t, err)
|
|
require.Equal(t, "model.config.is_valid.content_flagging.reasons_not_set.app_error", err.Id)
|
|
})
|
|
|
|
t.Run("should be invalid when reasons are empty", func(t *testing.T) {
|
|
settings := &AdditionalContentFlaggingSettings{
|
|
Reasons: &[]string{},
|
|
}
|
|
|
|
err := settings.IsValid()
|
|
require.NotNil(t, err)
|
|
require.Equal(t, "model.config.is_valid.content_flagging.reasons_not_set.app_error", err.Id)
|
|
})
|
|
}
|
|
|
|
func TestContentFlaggingSettings_SetDefault(t *testing.T) {
|
|
t.Run("should not override existing values", func(t *testing.T) {
|
|
enabled := true
|
|
settings := &ContentFlaggingSettingsRequest{
|
|
ContentFlaggingSettingsBase: ContentFlaggingSettingsBase{
|
|
EnableContentFlagging: &enabled,
|
|
},
|
|
}
|
|
settings.SetDefaults()
|
|
|
|
require.Nil(t, settings.IsValid())
|
|
require.True(t, *settings.EnableContentFlagging)
|
|
})
|
|
}
|
|
|
|
func TestContentFlaggingSettings_IsValid(t *testing.T) {
|
|
t.Run("should be valid when all nested settings are valid", func(t *testing.T) {
|
|
settings := &ContentFlaggingSettings{}
|
|
settings.SetDefaults()
|
|
|
|
err := settings.IsValid()
|
|
require.Nil(t, err)
|
|
})
|
|
|
|
t.Run("should be invalid when notification settings are invalid", func(t *testing.T) {
|
|
settings := &ContentFlaggingSettingsRequest{
|
|
ContentFlaggingSettingsBase: ContentFlaggingSettingsBase{
|
|
NotificationSettings: &ContentFlaggingNotificationSettings{
|
|
EventTargetMapping: map[ContentFlaggingEvent][]NotificationTarget{
|
|
EventFlagged: {},
|
|
},
|
|
},
|
|
AdditionalSettings: &AdditionalContentFlaggingSettings{},
|
|
},
|
|
}
|
|
|
|
err := settings.IsValid()
|
|
require.NotNil(t, err)
|
|
require.Contains(t, err.Id, "notification_settings")
|
|
})
|
|
|
|
t.Run("should be invalid when reviewer settings are invalid", func(t *testing.T) {
|
|
settings := &ContentFlaggingSettingsRequest{
|
|
ContentFlaggingSettingsBase: ContentFlaggingSettingsBase{
|
|
NotificationSettings: &ContentFlaggingNotificationSettings{},
|
|
AdditionalSettings: &AdditionalContentFlaggingSettings{},
|
|
},
|
|
ReviewerSettings: &ReviewSettingsRequest{
|
|
ReviewerSettings: ReviewerSettings{
|
|
CommonReviewers: NewPointer(true),
|
|
SystemAdminsAsReviewers: NewPointer(false),
|
|
TeamAdminsAsReviewers: NewPointer(false),
|
|
},
|
|
ReviewerIDsSettings: ReviewerIDsSettings{
|
|
CommonReviewerIds: []string{},
|
|
TeamReviewersSetting: map[string]*TeamReviewerSetting{},
|
|
},
|
|
},
|
|
}
|
|
settings.NotificationSettings.SetDefaults()
|
|
settings.AdditionalSettings.SetDefaults()
|
|
|
|
err := settings.IsValid()
|
|
require.NotNil(t, err)
|
|
require.Contains(t, err.Id, "common_reviewers_not_set")
|
|
})
|
|
|
|
t.Run("should be invalid when additional settings are invalid", func(t *testing.T) {
|
|
settings := &ContentFlaggingSettingsRequest{
|
|
ContentFlaggingSettingsBase: ContentFlaggingSettingsBase{
|
|
NotificationSettings: &ContentFlaggingNotificationSettings{},
|
|
AdditionalSettings: &AdditionalContentFlaggingSettings{
|
|
Reasons: &[]string{},
|
|
},
|
|
},
|
|
}
|
|
|
|
settings.SetDefaults()
|
|
|
|
err := settings.IsValid()
|
|
require.NotNil(t, err)
|
|
require.Contains(t, err.Id, "reasons_not_set")
|
|
})
|
|
}
|
|
|
|
func TestContentFlaggingConstants(t *testing.T) {
|
|
t.Run("should have correct event constants", func(t *testing.T) {
|
|
require.Equal(t, ContentFlaggingEvent("flagged"), EventFlagged)
|
|
require.Equal(t, ContentFlaggingEvent("assigned"), EventAssigned)
|
|
require.Equal(t, ContentFlaggingEvent("removed"), EventContentRemoved)
|
|
require.Equal(t, ContentFlaggingEvent("dismissed"), EventContentDismissed)
|
|
})
|
|
|
|
t.Run("should have correct target constants", func(t *testing.T) {
|
|
require.Equal(t, NotificationTarget("reviewers"), TargetReviewers)
|
|
require.Equal(t, NotificationTarget("author"), TargetAuthor)
|
|
require.Equal(t, NotificationTarget("reporter"), TargetReporter)
|
|
})
|
|
}
|