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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
package api4
import (
"testing"
"github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
)
func TestGetUserStatus(t *testing.T) {
th := Setup().InitBasic()
defer TearDown()
Client := th.Client
userStatus, resp := Client.GetUserStatus(th.BasicUser.Id, "")
CheckNoError(t, resp)
if userStatus.Status != "offline" {
t.Fatal("Should return offline status")
}
app.SetStatusOnline(th.BasicUser.Id, "", true)
userStatus, resp = Client.GetUserStatus(th.BasicUser.Id, "")
CheckNoError(t, resp)
if userStatus.Status != "online" {
t.Fatal("Should return online status")
}
app.SetStatusAwayIfNeeded(th.BasicUser.Id, true)
userStatus, resp = Client.GetUserStatus(th.BasicUser.Id, "")
CheckNoError(t, resp)
if userStatus.Status != "away" {
t.Fatal("Should return away status")
}
app.SetStatusOffline(th.BasicUser.Id, true)
userStatus, resp = Client.GetUserStatus(th.BasicUser.Id, "")
CheckNoError(t, resp)
if userStatus.Status != "offline" {
t.Fatal("Should return offline status")
}
//Get user2 status logged as user1
userStatus, resp = Client.GetUserStatus(th.BasicUser2.Id, "")
CheckNoError(t, resp)
if userStatus.Status != "offline" {
t.Fatal("Should return offline status")
}
Client.Logout()
th.LoginBasic2()
userStatus, resp = Client.GetUserStatus(th.BasicUser2.Id, "")
CheckNoError(t, resp)
if userStatus.Status != "offline" {
t.Fatal("Should return offline status")
}
}
func TestGetUsersStatusesByIds(t *testing.T) {
th := Setup().InitBasic()
defer TearDown()
Client := th.Client
usersIds := []string{th.BasicUser.Id, th.BasicUser2.Id}
usersStatuses, resp := Client.GetUsersStatusesByIds(usersIds)
CheckNoError(t, resp)
for _, userStatus := range usersStatuses {
if userStatus.Status != "offline" {
t.Fatal("Status should be offline")
}
}
app.SetStatusOnline(th.BasicUser.Id, "", true)
app.SetStatusOnline(th.BasicUser2.Id, "", true)
usersStatuses, resp = Client.GetUsersStatusesByIds(usersIds)
CheckNoError(t, resp)
for _, userStatus := range usersStatuses {
if userStatus.Status != "online" {
t.Fatal("Status should be offline")
}
}
app.SetStatusAwayIfNeeded(th.BasicUser.Id, true)
app.SetStatusAwayIfNeeded(th.BasicUser2.Id, true)
usersStatuses, resp = Client.GetUsersStatusesByIds(usersIds)
CheckNoError(t, resp)
for _, userStatus := range usersStatuses {
if userStatus.Status != "away" {
t.Fatal("Status should be offline")
}
}
}
func TestUpdateUserStatus(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()
Client := th.Client
toUpdateUserStatus := &model.Status{Status: "online"}
updateUserStatus, resp := Client.UpdateUserStatus(th.BasicUser.Id, toUpdateUserStatus)
CheckNoError(t, resp)
if updateUserStatus.Status != "online" {
t.Fatal("Should return online status")
}
toUpdateUserStatus.Status = "away"
updateUserStatus, resp = Client.UpdateUserStatus(th.BasicUser.Id, toUpdateUserStatus)
CheckNoError(t, resp)
if updateUserStatus.Status != "away" {
t.Fatal("Should return away status")
}
toUpdateUserStatus.Status = "offline"
updateUserStatus, resp = Client.UpdateUserStatus(th.BasicUser.Id, toUpdateUserStatus)
CheckNoError(t, resp)
if updateUserStatus.Status != "offline" {
t.Fatal("Should return offline status")
}
toUpdateUserStatus.Status = "online"
updateUserStatus, resp = Client.UpdateUserStatus(th.BasicUser2.Id, toUpdateUserStatus)
CheckForbiddenStatus(t, resp)
toUpdateUserStatus.Status = "online"
updateUserStatus, resp = th.SystemAdminClient.UpdateUserStatus(th.BasicUser2.Id, toUpdateUserStatus)
if updateUserStatus.Status != "online" {
t.Fatal("Should return online status")
}
}
|