Allow shared channel remotes endpoint to be filtered by confirmation status (#28213)

* Allow shared channel remotes endpoint to be filtered by confirmation status

* Adds tests
Этот коммит содержится в:
Miguel de la Cruz
2024-09-18 13:36:43 +02:00
коммит произвёл GitHub
родитель 70cb1934e9
Коммит 7a0019b63a
5 изменённых файлов: 77 добавлений и 17 удалений

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

@@ -116,10 +116,12 @@ func getSharedChannelRemotesByRemoteCluster(c *Context, w http.ResponseWriter, r
}
filter := model.SharedChannelRemoteFilterOpts{
RemoteId: c.Params.RemoteId,
ExcludeHome: c.Params.ExcludeHome,
ExcludeRemote: c.Params.ExcludeRemote,
IncludeDeleted: c.Params.IncludeDeleted,
RemoteId: c.Params.RemoteId,
IncludeUnconfirmed: c.Params.IncludeUnconfirmed,
ExcludeConfirmed: c.Params.ExcludeConfirmed,
ExcludeHome: c.Params.ExcludeHome,
ExcludeRemote: c.Params.ExcludeRemote,
IncludeDeleted: c.Params.IncludeDeleted,
}
sharedChannelRemotes, err := c.App.GetSharedChannelRemotes(c.Params.Page, c.Params.PerPage, filter)
if err != nil {

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

@@ -313,6 +313,20 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) {
_, err = th.App.ShareChannel(th.Context, sc4)
require.NoError(t, err)
c5 := th.CreateChannelWithClientAndTeam(th.Client, model.ChannelTypeOpen, th.BasicTeam.Id)
sc5 := &model.SharedChannel{
ChannelId: c5.Id,
TeamId: th.BasicTeam.Id,
ShareName: "shared_5",
ShareDisplayName: "Shared Channel 5",
CreatorId: th.BasicUser.Id,
RemoteId: rc1.RemoteId,
Home: false,
}
_, err = th.App.ShareChannel(th.Context, sc5)
require.NoError(t, err)
// for the pagination test, we need to get the channelId of the
// second SharedChannelRemote that belongs to RC1, sorted by ID,
// so we accumulate those SharedChannelRemotes on creation and
@@ -321,7 +335,7 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) {
sharedChannelRemotesFromRC1 := []*model.SharedChannelRemote{}
// create the shared channel remotes
for _, sc := range []*model.SharedChannel{sc1, sc2, sc3, sc4} {
for _, sc := range []*model.SharedChannel{sc1, sc2, sc3, sc4, sc5} {
scr := &model.SharedChannelRemote{
Id: model.NewId(),
ChannelId: sc.ChannelId,
@@ -330,6 +344,10 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) {
IsInviteConfirmed: true,
RemoteId: sc.RemoteId,
}
// scr for c5 is not confirmed yet
if sc.ChannelId == sc5.ChannelId {
scr.IsInviteConfirmed = false
}
_, err = th.App.SaveSharedChannelRemote(scr)
require.NoError(t, err)
@@ -355,9 +373,7 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) {
Name string
Client *model.Client4
RemoteId string
ExcludeHome bool
ExcludeRemote bool
IncludeDeleted bool
Filter model.SharedChannelRemoteFilterOpts
Page int
PerPage int
ExpectedStatusCode int
@@ -396,7 +412,7 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) {
Name: "should return the complete list of shared channel remotes for a remote cluster, including deleted",
Client: th.SystemAdminClient,
RemoteId: rc1.RemoteId,
IncludeDeleted: true,
Filter: model.SharedChannelRemoteFilterOpts{IncludeDeleted: true},
Page: 0,
PerPage: 100,
ExpectedStatusCode: http.StatusOK,
@@ -407,7 +423,7 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) {
Name: "should return only the shared channel remotes homed localy",
Client: th.SystemAdminClient,
RemoteId: rc1.RemoteId,
ExcludeRemote: true,
Filter: model.SharedChannelRemoteFilterOpts{ExcludeRemote: true},
Page: 0,
PerPage: 100,
ExpectedStatusCode: http.StatusOK,
@@ -418,18 +434,40 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) {
Name: "should return only the shared channel remotes homed remotely",
Client: th.SystemAdminClient,
RemoteId: rc1.RemoteId,
ExcludeHome: true,
Filter: model.SharedChannelRemoteFilterOpts{ExcludeHome: true},
Page: 0,
PerPage: 100,
ExpectedStatusCode: http.StatusOK,
ExpectedError: false,
ExpectedIds: []string{sc2.ChannelId},
},
{
Name: "should return the complete list of shared channel remotes for a remote cluster including unconfirmed",
Client: th.SystemAdminClient,
RemoteId: rc1.RemoteId,
Filter: model.SharedChannelRemoteFilterOpts{IncludeUnconfirmed: true},
Page: 0,
PerPage: 100,
ExpectedStatusCode: http.StatusOK,
ExpectedError: false,
ExpectedIds: []string{sc1.ChannelId, sc2.ChannelId, sc5.ChannelId},
},
{
Name: "should return only the unconfirmed shared channel remotes for a remote cluster",
Client: th.SystemAdminClient,
RemoteId: rc1.RemoteId,
Filter: model.SharedChannelRemoteFilterOpts{ExcludeConfirmed: true},
Page: 0,
PerPage: 100,
ExpectedStatusCode: http.StatusOK,
ExpectedError: false,
ExpectedIds: []string{sc5.ChannelId},
},
{
Name: "should correctly paginate the results",
Client: th.SystemAdminClient,
RemoteId: rc1.RemoteId,
IncludeDeleted: true,
Filter: model.SharedChannelRemoteFilterOpts{IncludeDeleted: true, IncludeUnconfirmed: true},
Page: 1,
PerPage: 1,
ExpectedStatusCode: http.StatusOK,
@@ -440,7 +478,7 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) {
scrs, resp, err := tc.Client.GetSharedChannelRemotesByRemoteCluster(context.Background(), tc.RemoteId, tc.ExcludeHome, tc.ExcludeRemote, tc.IncludeDeleted, tc.Page, tc.PerPage)
scrs, resp, err := tc.Client.GetSharedChannelRemotesByRemoteCluster(context.Background(), tc.RemoteId, tc.Filter, tc.Page, tc.PerPage)
checkHTTPStatus(t, resp, tc.ExpectedStatusCode)
if tc.ExpectedError {
require.Error(t, err)