[MM-16934] Add API endpoint to update channel privacy (#11993)

* Add API endpoint to update channel privacy setting

* Fix language files

* Improve tests by making sure channel has been updated correctly

* Improve tests
Этот коммит содержится в:
Claudio Costa
2019-09-16 19:34:36 +02:00
коммит произвёл GitHub
родитель 6a2f09ae78
Коммит ad9784d7e3
4 изменённых файлов: 126 добавлений и 0 удалений

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

@@ -1387,6 +1387,68 @@ func TestConvertChannelToPrivate(t *testing.T) {
}
}
func TestUpdateChannelPrivacy(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
type testTable []struct {
name string
channel *model.Channel
expectedPrivacy string
}
defaultChannel, _ := th.App.GetChannelByName(model.DEFAULT_CHANNEL, th.BasicTeam.Id, false)
privateChannel := th.CreatePrivateChannel()
publicChannel := th.CreatePublicChannel()
tt := testTable{
{"Updating default channel should fail with forbidden status if not logged in", defaultChannel, model.CHANNEL_OPEN},
{"Updating private channel should fail with forbidden status if not logged in", privateChannel, model.CHANNEL_PRIVATE},
{"Updating public channel should fail with forbidden status if not logged in", publicChannel, model.CHANNEL_OPEN},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
_, resp := Client.UpdateChannelPrivacy(tc.channel.Id, tc.expectedPrivacy)
CheckForbiddenStatus(t, resp)
})
}
th.LoginTeamAdmin()
tt = testTable{
{"Converting default channel to private should fail", defaultChannel, model.CHANNEL_PRIVATE},
{"Updating privacy to an invalid setting should fail", publicChannel, "invalid"},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
_, resp := Client.UpdateChannelPrivacy(tc.channel.Id, tc.expectedPrivacy)
CheckBadRequestStatus(t, resp)
})
}
tt = testTable{
{"Default channel should stay public", defaultChannel, model.CHANNEL_OPEN},
{"Public channel should stay public", publicChannel, model.CHANNEL_OPEN},
{"Private channel should stay private", privateChannel, model.CHANNEL_PRIVATE},
{"Public channel should convert to private", publicChannel, model.CHANNEL_PRIVATE},
{"Private channel should convert to public", privateChannel, model.CHANNEL_OPEN},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
updatedChannel, resp := Client.UpdateChannelPrivacy(tc.channel.Id, tc.expectedPrivacy)
CheckNoError(t, resp)
assert.Equal(t, updatedChannel.Type, tc.expectedPrivacy)
updatedChannel, err := th.App.GetChannel(tc.channel.Id)
require.Nil(t, err)
assert.Equal(t, updatedChannel.Type, tc.expectedPrivacy)
})
}
}
func TestRestoreChannel(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()