summaryrefslogtreecommitdiffstats
path: root/cmd/commands/roles_test.go
blob: 4e00aeac88de018fd5d7d1b95712b6c4adc3dd43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package commands

import (
	"testing"

	"github.com/mattermost/mattermost-server/api4"
	"github.com/mattermost/mattermost-server/cmd"
	"github.com/mattermost/mattermost-server/model"
)

func TestAssignRole(t *testing.T) {
	th := api4.Setup().InitBasic()
	defer th.TearDown()

	cmd.CheckCommand(t, "roles", "system_admin", th.BasicUser.Email)

	if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil {
		t.Fatal()
	} else {
		user := result.Data.(*model.User)
		if user.Roles != "system_user system_admin" {
			t.Fatal("Got wrong roles:", user.Roles)
		}
	}

	cmd.CheckCommand(t, "roles", "member", th.BasicUser.Email)

	if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil {
		t.Fatal()
	} else {
		user := result.Data.(*model.User)
		if user.Roles != "system_user" {
			t.Fatal("Got wrong roles:", user.Roles, user.Id)
		}
	}
}