Use 201 status code where appropriate for APIv4 (#5903)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
4e224c2996
Коммит
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) {
|
func CheckForbiddenStatus(t *testing.T, resp *model.Response) {
|
||||||
if resp.Error == nil {
|
if resp.Error == nil {
|
||||||
debug.PrintStack()
|
debug.PrintStack()
|
||||||
|
|||||||
@@ -66,5 +66,6 @@ func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
c.LogAudit("")
|
c.LogAudit("")
|
||||||
|
|
||||||
|
w.WriteHeader(http.StatusCreated)
|
||||||
ReturnStatusOK(w)
|
ReturnStatusOK(w)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -738,6 +738,7 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
c.LogAudit("name=" + channel.Name + " user_id=" + cm.UserId)
|
c.LogAudit("name=" + channel.Name + " user_id=" + cm.UserId)
|
||||||
|
w.WriteHeader(http.StatusCreated)
|
||||||
w.Write([]byte(cm.ToJson()))
|
w.Write([]byte(cm.ToJson()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ func TestCreateChannel(t *testing.T) {
|
|||||||
|
|
||||||
rchannel, resp := Client.CreateChannel(channel)
|
rchannel, resp := Client.CreateChannel(channel)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
CheckCreatedStatus(t, resp)
|
||||||
|
|
||||||
if rchannel.Name != channel.Name {
|
if rchannel.Name != channel.Name {
|
||||||
t.Fatal("names did not match")
|
t.Fatal("names did not match")
|
||||||
@@ -1501,6 +1502,7 @@ func TestAddChannelMember(t *testing.T) {
|
|||||||
|
|
||||||
cm, resp := Client.AddChannelMember(publicChannel.Id, user2.Id)
|
cm, resp := Client.AddChannelMember(publicChannel.Id, user2.Id)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
CheckCreatedStatus(t, resp)
|
||||||
|
|
||||||
if cm.ChannelId != publicChannel.Id {
|
if cm.ChannelId != publicChannel.Id {
|
||||||
t.Fatal("should have returned exact channel")
|
t.Fatal("should have returned exact channel")
|
||||||
|
|||||||
@@ -41,5 +41,6 @@ func createCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.LogAudit("success")
|
c.LogAudit("success")
|
||||||
|
w.WriteHeader(http.StatusCreated)
|
||||||
w.Write([]byte(rcmd.ToJson()))
|
w.Write([]byte(rcmd.ToJson()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ func TestCreateCommand(t *testing.T) {
|
|||||||
|
|
||||||
createdCmd, resp := th.SystemAdminClient.CreateCommand(newCmd)
|
createdCmd, resp := th.SystemAdminClient.CreateCommand(newCmd)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
CheckCreatedStatus(t, resp)
|
||||||
if createdCmd.CreatorId != th.SystemAdminUser.Id {
|
if createdCmd.CreatorId != th.SystemAdminUser.Id {
|
||||||
t.Fatal("user ids didn't match")
|
t.Fatal("user ids didn't match")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.WriteHeader(http.StatusCreated)
|
||||||
w.Write([]byte(rp.ToJson()))
|
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"}
|
post := &model.Post{ChannelId: th.BasicChannel.Id, Message: "#hashtag a" + model.NewId() + "a"}
|
||||||
rpost, resp := Client.CreatePost(post)
|
rpost, resp := Client.CreatePost(post)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
CheckCreatedStatus(t, resp)
|
||||||
|
|
||||||
if rpost.Message != post.Message {
|
if rpost.Message != post.Message {
|
||||||
t.Fatal("message didn't match")
|
t.Fatal("message didn't match")
|
||||||
|
|||||||
@@ -336,6 +336,7 @@ func addTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.WriteHeader(http.StatusCreated)
|
||||||
w.Write([]byte(member.ToJson()))
|
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}
|
team := &model.Team{Name: GenerateTestUsername(), DisplayName: "Some Team", Type: model.TEAM_OPEN}
|
||||||
rteam, resp := Client.CreateTeam(team)
|
rteam, resp := Client.CreateTeam(team)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
CheckCreatedStatus(t, resp)
|
||||||
|
|
||||||
if rteam.Name != team.Name {
|
if rteam.Name != team.Name {
|
||||||
t.Fatal("names did not match")
|
t.Fatal("names did not match")
|
||||||
@@ -635,6 +636,7 @@ func TestAddTeamMember(t *testing.T) {
|
|||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
tm, resp = Client.AddTeamMember(team.Id, otherUser.Id, "", "", "")
|
tm, resp = Client.AddTeamMember(team.Id, otherUser.Id, "", "", "")
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
CheckCreatedStatus(t, resp)
|
||||||
|
|
||||||
// Check all the returned data.
|
// Check all the returned data.
|
||||||
if tm == nil {
|
if tm == nil {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ func TestCreateUser(t *testing.T) {
|
|||||||
|
|
||||||
ruser, resp := Client.CreateUser(&user)
|
ruser, resp := Client.CreateUser(&user)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
CheckCreatedStatus(t, resp)
|
||||||
|
|
||||||
Client.Login(user.Email, user.Password)
|
Client.Login(user.Email, user.Password)
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user