MM-32396 Create endpoint for listing all the roles (#16988)

* Create an endpoint for listing roles

* Add function to client model

* Create tests for listing roles endpoint

* Apply code review suggestions

* Restore GetAllRoles app method

* Use AppContext instead of App

* Minor fix

* Refactor according to new changes

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Berke Kalkan
2021-11-08 16:38:41 +03:00
коммит произвёл GitHub
родитель 25257d6ef6
Коммит e70c5a605a
9 изменённых файлов: 114 добавлений и 0 удалений

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

@@ -15,6 +15,28 @@ import (
"github.com/mattermost/mattermost-server/v6/model"
)
func TestGetAllRoles(t *testing.T) {
th := Setup(t)
defer th.TearDown()
roles, err := th.App.Srv().Store.Role().GetAll()
require.NoError(t, err)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
received, resp, err := client.GetAllRoles()
require.NoError(t, err)
CheckOKStatus(t, resp)
assert.EqualValues(t, received, roles)
})
t.Run("NormalClient", func(t *testing.T) {
_, resp, err := th.Client.GetAllRoles()
require.Error(t, err)
CheckForbiddenStatus(t, resp)
})
}
func TestGetRole(t *testing.T) {
th := Setup(t)
defer th.TearDown()