snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
This commit is contained in:
296
server/channels/app/view_test.go
Normal file
296
server/channels/app/view_test.go
Normal file
@@ -0,0 +1,296 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
)
|
||||
|
||||
func makeTestView(channelID, userID string) *model.View {
|
||||
kanban := &model.KanbanProps{
|
||||
GroupBy: model.KanbanGroupBy{
|
||||
FieldID: model.NewId(),
|
||||
Columns: []model.KanbanColumn{
|
||||
{ID: model.NewId(), Name: "Todo", OptionIDs: []string{model.NewId()}},
|
||||
{ID: model.NewId(), Name: "Done", OptionIDs: []string{model.NewId()}},
|
||||
},
|
||||
},
|
||||
}
|
||||
props, _ := kanban.ToProps()
|
||||
return &model.View{
|
||||
ChannelId: channelID,
|
||||
Type: model.ViewTypeKanban,
|
||||
CreatorId: userID,
|
||||
Title: "Test View",
|
||||
Props: props,
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppCreateView(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic(t)
|
||||
|
||||
t.Run("creates a view", func(t *testing.T) {
|
||||
view := makeTestView(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
saved, appErr := th.App.CreateView(th.Context, view, "")
|
||||
require.Nil(t, appErr)
|
||||
require.NotEmpty(t, saved.Id)
|
||||
assert.Equal(t, th.BasicChannel.Id, saved.ChannelId)
|
||||
})
|
||||
|
||||
t.Run("exceeding max views per channel returns error", func(t *testing.T) {
|
||||
channel := th.CreateChannel(t, th.BasicTeam)
|
||||
|
||||
for i := range model.MaxViewsPerChannel {
|
||||
_, appErr := th.App.CreateView(th.Context, makeTestView(channel.Id, th.BasicUser.Id), "")
|
||||
require.Nil(t, appErr, "failed to create view %d", i)
|
||||
}
|
||||
|
||||
_, appErr := th.App.CreateView(th.Context, makeTestView(channel.Id, th.BasicUser.Id), "")
|
||||
require.NotNil(t, appErr)
|
||||
assert.Equal(t, http.StatusBadRequest, appErr.StatusCode)
|
||||
assert.Equal(t, "app.view.create.limit.app_error", appErr.Id)
|
||||
})
|
||||
}
|
||||
|
||||
func TestAppGetView(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic(t)
|
||||
|
||||
t.Run("gets a view by ID", func(t *testing.T) {
|
||||
view := makeTestView(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
saved, appErr := th.App.CreateView(th.Context, view, "")
|
||||
require.Nil(t, appErr)
|
||||
|
||||
got, appErr := th.App.GetView(th.Context, saved.Id)
|
||||
require.Nil(t, appErr)
|
||||
assert.Equal(t, saved.Id, got.Id)
|
||||
})
|
||||
|
||||
t.Run("returns 404 for non-existent view", func(t *testing.T) {
|
||||
_, appErr := th.App.GetView(th.Context, model.NewId())
|
||||
require.NotNil(t, appErr)
|
||||
assert.Equal(t, http.StatusNotFound, appErr.StatusCode)
|
||||
})
|
||||
}
|
||||
|
||||
func TestAppGetViewsForChannel(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic(t)
|
||||
|
||||
t.Run("lists views for a channel", func(t *testing.T) {
|
||||
channel := th.CreateChannel(t, th.BasicTeam)
|
||||
_, appErr := th.App.CreateView(th.Context, makeTestView(channel.Id, th.BasicUser.Id), "")
|
||||
require.Nil(t, appErr)
|
||||
_, appErr = th.App.CreateView(th.Context, makeTestView(channel.Id, th.BasicUser.Id), "")
|
||||
require.Nil(t, appErr)
|
||||
|
||||
views, appErr := th.App.GetViewsForChannel(th.Context, channel.Id, model.ViewQueryOpts{})
|
||||
require.Nil(t, appErr)
|
||||
assert.Len(t, views, 2)
|
||||
})
|
||||
|
||||
t.Run("empty channel returns empty list", func(t *testing.T) {
|
||||
channel := th.CreateChannel(t, th.BasicTeam)
|
||||
views, appErr := th.App.GetViewsForChannel(th.Context, channel.Id, model.ViewQueryOpts{})
|
||||
require.Nil(t, appErr)
|
||||
assert.Empty(t, views)
|
||||
})
|
||||
|
||||
t.Run("returns 400 for empty channelID", func(t *testing.T) {
|
||||
_, appErr := th.App.GetViewsForChannel(th.Context, "", model.ViewQueryOpts{})
|
||||
require.NotNil(t, appErr)
|
||||
assert.Equal(t, http.StatusBadRequest, appErr.StatusCode)
|
||||
})
|
||||
}
|
||||
|
||||
func TestAppUpdateView(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic(t)
|
||||
|
||||
t.Run("updates a view", func(t *testing.T) {
|
||||
saved, appErr := th.App.CreateView(th.Context, makeTestView(th.BasicChannel.Id, th.BasicUser.Id), "")
|
||||
require.Nil(t, appErr)
|
||||
|
||||
newTitle := "Updated Title"
|
||||
updated, appErr := th.App.UpdateView(th.Context, saved, &model.ViewPatch{Title: &newTitle}, "")
|
||||
require.Nil(t, appErr)
|
||||
assert.Equal(t, newTitle, updated.Title)
|
||||
})
|
||||
|
||||
t.Run("nil view returns error", func(t *testing.T) {
|
||||
newTitle := "Title"
|
||||
_, appErr := th.App.UpdateView(th.Context, nil, &model.ViewPatch{Title: &newTitle}, "")
|
||||
require.NotNil(t, appErr)
|
||||
assert.Equal(t, http.StatusBadRequest, appErr.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("validation error returns 400", func(t *testing.T) {
|
||||
saved, appErr := th.App.CreateView(th.Context, makeTestView(th.BasicChannel.Id, th.BasicUser.Id), "")
|
||||
require.Nil(t, appErr)
|
||||
|
||||
emptyTitle := ""
|
||||
_, appErr = th.App.UpdateView(th.Context, saved, &model.ViewPatch{Title: &emptyTitle}, "")
|
||||
require.NotNil(t, appErr)
|
||||
assert.Equal(t, http.StatusBadRequest, appErr.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("not found returns 404", func(t *testing.T) {
|
||||
ghost := makeTestView(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
ghost.Id = model.NewId()
|
||||
ghost.Title = "Ghost"
|
||||
ghost.CreateAt = model.GetMillis()
|
||||
ghost.UpdateAt = model.GetMillis()
|
||||
newTitle := "Title"
|
||||
_, appErr := th.App.UpdateView(th.Context, ghost, &model.ViewPatch{Title: &newTitle}, "")
|
||||
require.NotNil(t, appErr)
|
||||
assert.Equal(t, http.StatusNotFound, appErr.StatusCode)
|
||||
})
|
||||
}
|
||||
|
||||
func TestAppDeleteView(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic(t)
|
||||
|
||||
t.Run("deletes a view", func(t *testing.T) {
|
||||
saved, appErr := th.App.CreateView(th.Context, makeTestView(th.BasicChannel.Id, th.BasicUser.Id), "")
|
||||
require.Nil(t, appErr)
|
||||
|
||||
appErr = th.App.DeleteView(th.Context, saved, "")
|
||||
require.Nil(t, appErr)
|
||||
|
||||
_, appErr = th.App.GetView(th.Context, saved.Id)
|
||||
require.NotNil(t, appErr)
|
||||
assert.Equal(t, http.StatusNotFound, appErr.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("nil view returns error", func(t *testing.T) {
|
||||
appErr := th.App.DeleteView(th.Context, nil, "")
|
||||
require.NotNil(t, appErr)
|
||||
assert.Equal(t, http.StatusBadRequest, appErr.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("not found returns 404", func(t *testing.T) {
|
||||
ghost := &model.View{Id: model.NewId(), ChannelId: th.BasicChannel.Id}
|
||||
appErr := th.App.DeleteView(th.Context, ghost, "")
|
||||
require.NotNil(t, appErr)
|
||||
assert.Equal(t, http.StatusNotFound, appErr.StatusCode)
|
||||
})
|
||||
}
|
||||
|
||||
func TestAppUpdateViewSortOrder(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic(t)
|
||||
|
||||
t.Run("reorders views", func(t *testing.T) {
|
||||
channel := th.CreateChannel(t, th.BasicTeam)
|
||||
var created []*model.View
|
||||
for i := range 3 {
|
||||
v := makeTestView(channel.Id, th.BasicUser.Id)
|
||||
v.Title = "Reorder View"
|
||||
v.SortOrder = i
|
||||
saved, appErr := th.App.CreateView(th.Context, v, "")
|
||||
require.Nil(t, appErr)
|
||||
created = append(created, saved)
|
||||
}
|
||||
|
||||
views, appErr := th.App.UpdateViewSortOrder(th.Context, created[2].Id, channel.Id, 0, "")
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, views, 3)
|
||||
assert.Equal(t, created[2].Id, views[0].Id)
|
||||
assert.Equal(t, created[0].Id, views[1].Id)
|
||||
assert.Equal(t, created[1].Id, views[2].Id)
|
||||
})
|
||||
|
||||
t.Run("invalid index returns 400", func(t *testing.T) {
|
||||
channel := th.CreateChannel(t, th.BasicTeam)
|
||||
v := makeTestView(channel.Id, th.BasicUser.Id)
|
||||
saved, appErr := th.App.CreateView(th.Context, v, "")
|
||||
require.Nil(t, appErr)
|
||||
|
||||
_, appErr = th.App.UpdateViewSortOrder(th.Context, saved.Id, channel.Id, 99, "")
|
||||
require.NotNil(t, appErr)
|
||||
assert.Equal(t, http.StatusBadRequest, appErr.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("non-existent view returns 404", func(t *testing.T) {
|
||||
channel := th.CreateChannel(t, th.BasicTeam)
|
||||
v := makeTestView(channel.Id, th.BasicUser.Id)
|
||||
_, appErr := th.App.CreateView(th.Context, v, "")
|
||||
require.Nil(t, appErr)
|
||||
|
||||
_, appErr = th.App.UpdateViewSortOrder(th.Context, model.NewId(), channel.Id, 0, "")
|
||||
require.NotNil(t, appErr)
|
||||
assert.Equal(t, http.StatusNotFound, appErr.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("empty channel returns 400", func(t *testing.T) {
|
||||
_, appErr := th.App.UpdateViewSortOrder(th.Context, model.NewId(), model.NewId(), 0, "")
|
||||
require.NotNil(t, appErr)
|
||||
assert.Equal(t, http.StatusBadRequest, appErr.StatusCode)
|
||||
})
|
||||
}
|
||||
|
||||
func TestViewWebsocketEvents(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := Setup(t).InitBasic(t)
|
||||
|
||||
eventFilter := []model.WebsocketEventType{
|
||||
model.WebsocketEventViewCreated,
|
||||
model.WebsocketEventViewUpdated,
|
||||
model.WebsocketEventViewDeleted,
|
||||
model.WebsocketEventViewSorted,
|
||||
}
|
||||
messages, closeWS := connectFakeWebSocket(t, th, th.BasicUser.Id, "", eventFilter)
|
||||
defer closeWS()
|
||||
|
||||
saved, appErr := th.App.CreateView(th.Context, makeTestView(th.BasicChannel.Id, th.BasicUser.Id), "")
|
||||
require.Nil(t, appErr)
|
||||
|
||||
received := <-messages
|
||||
assert.Equal(t, model.WebsocketEventViewCreated, received.EventType())
|
||||
var createdView model.View
|
||||
require.NoError(t, json.Unmarshal([]byte(received.GetData()["view"].(string)), &createdView))
|
||||
assert.Equal(t, saved.Id, createdView.Id)
|
||||
|
||||
newTitle := "Updated Title"
|
||||
updated, appErr := th.App.UpdateView(th.Context, saved, &model.ViewPatch{Title: &newTitle}, "")
|
||||
require.Nil(t, appErr)
|
||||
|
||||
received = <-messages
|
||||
assert.Equal(t, model.WebsocketEventViewUpdated, received.EventType())
|
||||
var updatedView model.View
|
||||
require.NoError(t, json.Unmarshal([]byte(received.GetData()["view"].(string)), &updatedView))
|
||||
assert.Equal(t, updated.Id, updatedView.Id)
|
||||
assert.Equal(t, newTitle, updatedView.Title)
|
||||
|
||||
// Create a second view for sort-order testing
|
||||
saved2, appErr := th.App.CreateView(th.Context, makeTestView(th.BasicChannel.Id, th.BasicUser.Id), "")
|
||||
require.Nil(t, appErr)
|
||||
received = <-messages
|
||||
assert.Equal(t, model.WebsocketEventViewCreated, received.EventType())
|
||||
|
||||
sortedViews, appErr := th.App.UpdateViewSortOrder(th.Context, saved2.Id, th.BasicChannel.Id, 0, "")
|
||||
require.Nil(t, appErr)
|
||||
|
||||
received = <-messages
|
||||
assert.Equal(t, model.WebsocketEventViewSorted, received.EventType())
|
||||
var wsViews []*model.View
|
||||
require.NoError(t, json.Unmarshal([]byte(received.GetData()["views"].(string)), &wsViews))
|
||||
assert.Len(t, wsViews, len(sortedViews))
|
||||
|
||||
appErr = th.App.DeleteView(th.Context, saved, "")
|
||||
require.Nil(t, appErr)
|
||||
|
||||
received = <-messages
|
||||
assert.Equal(t, model.WebsocketEventViewDeleted, received.EventType())
|
||||
assert.Equal(t, saved.Id, received.GetData()["view_id"])
|
||||
}
|
||||
Reference in New Issue
Block a user