mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Use 201 status code where appropriate for APIv4 (#5903)
This commit is contained in:
committed by
Christopher Speller
parent
4e224c2996
commit
5f6d50bff1
@@ -442,6 +442,15 @@ func CheckNoError(t *testing.T, resp *model.Response) {
|
||||
}
|
||||
}
|
||||
|
||||
func CheckCreatedStatus(t *testing.T, resp *model.Response) {
|
||||
if resp.StatusCode != http.StatusCreated {
|
||||
debug.PrintStack()
|
||||
t.Log("actual: " + strconv.Itoa(resp.StatusCode))
|
||||
t.Log("expected: " + strconv.Itoa(http.StatusCreated))
|
||||
t.Fatal("wrong status code")
|
||||
}
|
||||
}
|
||||
|
||||
func CheckForbiddenStatus(t *testing.T, resp *model.Response) {
|
||||
if resp.Error == nil {
|
||||
debug.PrintStack()
|
||||
|
||||
@@ -66,5 +66,6 @@ func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
c.LogAudit("")
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
@@ -738,6 +738,7 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
} else {
|
||||
c.LogAudit("name=" + channel.Name + " user_id=" + cm.UserId)
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
w.Write([]byte(cm.ToJson()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ func TestCreateChannel(t *testing.T) {
|
||||
|
||||
rchannel, resp := Client.CreateChannel(channel)
|
||||
CheckNoError(t, resp)
|
||||
CheckCreatedStatus(t, resp)
|
||||
|
||||
if rchannel.Name != channel.Name {
|
||||
t.Fatal("names did not match")
|
||||
@@ -1501,6 +1502,7 @@ func TestAddChannelMember(t *testing.T) {
|
||||
|
||||
cm, resp := Client.AddChannelMember(publicChannel.Id, user2.Id)
|
||||
CheckNoError(t, resp)
|
||||
CheckCreatedStatus(t, resp)
|
||||
|
||||
if cm.ChannelId != publicChannel.Id {
|
||||
t.Fatal("should have returned exact channel")
|
||||
|
||||
@@ -41,5 +41,6 @@ func createCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
c.LogAudit("success")
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
w.Write([]byte(rcmd.ToJson()))
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ func TestCreateCommand(t *testing.T) {
|
||||
|
||||
createdCmd, resp := th.SystemAdminClient.CreateCommand(newCmd)
|
||||
CheckNoError(t, resp)
|
||||
CheckCreatedStatus(t, resp)
|
||||
if createdCmd.CreatorId != th.SystemAdminUser.Id {
|
||||
t.Fatal("user ids didn't match")
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
w.Write([]byte(rp.ToJson()))
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ func TestCreatePost(t *testing.T) {
|
||||
post := &model.Post{ChannelId: th.BasicChannel.Id, Message: "#hashtag a" + model.NewId() + "a"}
|
||||
rpost, resp := Client.CreatePost(post)
|
||||
CheckNoError(t, resp)
|
||||
CheckCreatedStatus(t, resp)
|
||||
|
||||
if rpost.Message != post.Message {
|
||||
t.Fatal("message didn't match")
|
||||
|
||||
@@ -336,6 +336,7 @@ func addTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
w.Write([]byte(member.ToJson()))
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ func TestCreateTeam(t *testing.T) {
|
||||
team := &model.Team{Name: GenerateTestUsername(), DisplayName: "Some Team", Type: model.TEAM_OPEN}
|
||||
rteam, resp := Client.CreateTeam(team)
|
||||
CheckNoError(t, resp)
|
||||
CheckCreatedStatus(t, resp)
|
||||
|
||||
if rteam.Name != team.Name {
|
||||
t.Fatal("names did not match")
|
||||
@@ -635,6 +636,7 @@ func TestAddTeamMember(t *testing.T) {
|
||||
th.LoginBasic()
|
||||
tm, resp = Client.AddTeamMember(team.Id, otherUser.Id, "", "", "")
|
||||
CheckNoError(t, resp)
|
||||
CheckCreatedStatus(t, resp)
|
||||
|
||||
// Check all the returned data.
|
||||
if tm == nil {
|
||||
|
||||
@@ -24,6 +24,7 @@ func TestCreateUser(t *testing.T) {
|
||||
|
||||
ruser, resp := Client.CreateUser(&user)
|
||||
CheckNoError(t, resp)
|
||||
CheckCreatedStatus(t, resp)
|
||||
|
||||
Client.Login(user.Email, user.Password)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user