summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-03-31 09:56:20 -0400
committerChristopher Speller <crspeller@gmail.com>2017-03-31 09:56:20 -0400
commit5f6d50bff1b4098bc0ef3c120e7b12104e5c4894 (patch)
tree6fe69bc72fa77547dd4bba2afb0f51fa6e79ca93
parent4e224c299697e570e98c388bf23a42ffa1e6af0d (diff)
downloadchat-5f6d50bff1b4098bc0ef3c120e7b12104e5c4894.tar.gz
chat-5f6d50bff1b4098bc0ef3c120e7b12104e5c4894.tar.bz2
chat-5f6d50bff1b4098bc0ef3c120e7b12104e5c4894.zip
Use 201 status code where appropriate for APIv4 (#5903)
-rw-r--r--api4/apitestlib.go9
-rw-r--r--api4/brand.go1
-rw-r--r--api4/channel.go1
-rw-r--r--api4/channel_test.go2
-rw-r--r--api4/command.go1
-rw-r--r--api4/command_test.go1
-rw-r--r--api4/post.go1
-rw-r--r--api4/post_test.go1
-rw-r--r--api4/team.go1
-rw-r--r--api4/team_test.go2
-rw-r--r--api4/user_test.go1
11 files changed, 21 insertions, 0 deletions
diff --git a/api4/apitestlib.go b/api4/apitestlib.go
index 749053271..863237367 100644
--- a/api4/apitestlib.go
+++ b/api4/apitestlib.go
@@ -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()
diff --git a/api4/brand.go b/api4/brand.go
index 00e6bbbff..f9a301acf 100644
--- a/api4/brand.go
+++ b/api4/brand.go
@@ -66,5 +66,6 @@ func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("")
+ w.WriteHeader(http.StatusCreated)
ReturnStatusOK(w)
}
diff --git a/api4/channel.go b/api4/channel.go
index b7f9508d6..c9a6ac6c5 100644
--- a/api4/channel.go
+++ b/api4/channel.go
@@ -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()))
}
}
diff --git a/api4/channel_test.go b/api4/channel_test.go
index 1875f2c44..1d8053a0a 100644
--- a/api4/channel_test.go
+++ b/api4/channel_test.go
@@ -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")
diff --git a/api4/command.go b/api4/command.go
index 123be1932..64766ef3c 100644
--- a/api4/command.go
+++ b/api4/command.go
@@ -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()))
}
diff --git a/api4/command_test.go b/api4/command_test.go
index 34396808f..aa3ad37b6 100644
--- a/api4/command_test.go
+++ b/api4/command_test.go
@@ -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")
}
diff --git a/api4/post.go b/api4/post.go
index af5fc8cfa..9c671ec21 100644
--- a/api4/post.go
+++ b/api4/post.go
@@ -52,6 +52,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
+ w.WriteHeader(http.StatusCreated)
w.Write([]byte(rp.ToJson()))
}
diff --git a/api4/post_test.go b/api4/post_test.go
index 8f954efaa..bf896f081 100644
--- a/api4/post_test.go
+++ b/api4/post_test.go
@@ -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")
diff --git a/api4/team.go b/api4/team.go
index 489265251..4bca56994 100644
--- a/api4/team.go
+++ b/api4/team.go
@@ -336,6 +336,7 @@ func addTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
+ w.WriteHeader(http.StatusCreated)
w.Write([]byte(member.ToJson()))
}
diff --git a/api4/team_test.go b/api4/team_test.go
index 40f5ec778..a38acf2e6 100644
--- a/api4/team_test.go
+++ b/api4/team_test.go
@@ -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 {
diff --git a/api4/user_test.go b/api4/user_test.go
index 21b240957..7653601e0 100644
--- a/api4/user_test.go
+++ b/api4/user_test.go
@@ -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)