Use 201 status code where appropriate for APIv4 (#5903)

This commit is contained in:
Joram Wilander
2017-03-31 09:56:20 -04:00
committed by Christopher Speller
parent 4e224c2996
commit 5f6d50bff1
11 changed files with 21 additions and 0 deletions

View File

@@ -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()

View File

@@ -66,5 +66,6 @@ func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("")
w.WriteHeader(http.StatusCreated)
ReturnStatusOK(w)
}

View File

@@ -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()))
}
}

View File

@@ -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")

View File

@@ -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()))
}

View File

@@ -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")
}

View File

@@ -52,6 +52,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
w.WriteHeader(http.StatusCreated)
w.Write([]byte(rp.ToJson()))
}

View File

@@ -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")

View File

@@ -336,6 +336,7 @@ func addTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
w.WriteHeader(http.StatusCreated)
w.Write([]byte(member.ToJson()))
}

View File

@@ -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 {

View File

@@ -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)