* Updates to post type

* Update tests
Этот коммит содержится в:
Joram Wilander
2017-10-09 13:30:48 -04:00
коммит произвёл Chris
родитель 0da0cf1a21
Коммит 9adaf53e11
7 изменённых файлов: 58 добавлений и 6 удалений

Просмотреть файл

@@ -61,6 +61,11 @@ func TestCreatePost(t *testing.T) {
t.Fatal("Newly craeted post shouldn't have EditAt set")
}
_, err = Client.CreatePost(&model.Post{ChannelId: channel1.Id, Message: "#hashtag a" + model.NewId() + "a", Type: model.POST_SYSTEM_GENERIC})
if err == nil {
t.Fatal("should have failed - bad post type")
}
post2 := &model.Post{ChannelId: channel1.Id, Message: "zz" + model.NewId() + "a", RootId: rpost1.Data.(*model.Post).Id}
rpost2, err := Client.CreatePost(post2)
if err != nil {
@@ -454,13 +459,12 @@ func TestUpdatePost(t *testing.T) {
}
}
post3 := &model.Post{ChannelId: channel1.Id, Message: "zz" + model.NewId() + "a", Type: model.POST_JOIN_LEAVE}
rpost3, err := Client.CreatePost(post3)
rpost3, err := th.App.CreatePost(&model.Post{ChannelId: channel1.Id, Message: "zz" + model.NewId() + "a", Type: model.POST_JOIN_LEAVE, UserId: th.BasicUser.Id}, channel1, false)
if err != nil {
t.Fatal(err)
}
up3 := &model.Post{Id: rpost3.Data.(*model.Post).Id, ChannelId: channel1.Id, Message: "zz" + model.NewId() + " update post 3"}
up3 := &model.Post{Id: rpost3.Id, ChannelId: channel1.Id, Message: "zz" + model.NewId() + " update post 3"}
if _, err := Client.UpdatePost(up3); err == nil {
t.Fatal("shouldn't have been able to update system message")
}

Просмотреть файл

@@ -66,6 +66,13 @@ func TestCreatePost(t *testing.T) {
t.Fatal("create at should not match")
}
post.RootId = ""
post.ParentId = ""
post.Type = model.POST_SYSTEM_GENERIC
_, resp = Client.CreatePost(post)
CheckBadRequestStatus(t, resp)
post.Type = ""
post.RootId = rpost2.Id
post.ParentId = rpost2.Id
_, resp = Client.CreatePost(post)
@@ -417,9 +424,10 @@ func TestUpdatePost(t *testing.T) {
t.Fatal("failed to updates")
}
post2 := &model.Post{ChannelId: channel.Id, Message: "zz" + model.NewId() + "a", Type: model.POST_JOIN_LEAVE}
rpost2, resp := Client.CreatePost(post2)
CheckNoError(t, resp)
rpost2, err := th.App.CreatePost(&model.Post{ChannelId: channel.Id, Message: "zz" + model.NewId() + "a", Type: model.POST_JOIN_LEAVE, UserId: th.BasicUser.Id}, channel, false)
if err != nil {
t.Fatal(err)
}
up2 := &model.Post{Id: rpost2.Id, ChannelId: channel.Id, Message: "zz" + model.NewId() + " update post 2"}
_, resp = Client.UpdatePost(rpost2.Id, up2)

Просмотреть файл

@@ -41,6 +41,11 @@ func (a *App) CreateCommandPost(post *model.Post, teamId string, response *model
post.Message = parseSlackLinksToMarkdown(response.Text)
post.CreateAt = model.GetMillis()
if strings.HasPrefix(post.Type, model.POST_SYSTEM_MESSAGE_PREFIX) {
err := model.NewAppError("CreateCommandPost", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "post.type"}, "", http.StatusBadRequest)
return nil, err
}
if response.Attachments != nil {
parseSlackAttachment(post, response.Attachments)
}

Просмотреть файл

@@ -45,3 +45,23 @@ func TestMoveCommand(t *testing.T) {
assert.Nil(t, err)
assert.EqualValues(t, targetTeam.Id, retrievedCommand.TeamId)
}
func TestCreateCommandPost(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
post := &model.Post{
ChannelId: th.BasicChannel.Id,
UserId: th.BasicUser.Id,
Type: model.POST_SYSTEM_GENERIC,
}
resp := &model.CommandResponse{
Text: "some message",
}
_, err := th.App.CreateCommandPost(post, th.BasicTeam.Id, resp)
if err == nil && err.Id != "api.context.invalid_param.app_error" {
t.Fatal("should have failed - bad post type")
}
}

Просмотреть файл

@@ -29,6 +29,11 @@ func (a *App) CreatePostAsUser(post *model.Post) (*model.Post, *model.AppError)
channel = result.Data.(*model.Channel)
}
if strings.HasPrefix(post.Type, model.POST_SYSTEM_MESSAGE_PREFIX) {
err := model.NewAppError("CreatePostAsUser", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "post.type"}, "", http.StatusBadRequest)
return nil, err
}
if channel.DeleteAt != 0 {
err := model.NewAppError("createPost", "api.post.create_post.can_not_post_to_deleted.error", nil, "", http.StatusBadRequest)
return nil, err

Просмотреть файл

@@ -131,6 +131,11 @@ func (a *App) CreateWebhookPost(userId string, channel *model.Channel, text, ove
post := &model.Post{UserId: userId, ChannelId: channel.Id, Message: text, Type: postType}
post.AddProp("from_webhook", "true")
if strings.HasPrefix(post.Type, model.POST_SYSTEM_MESSAGE_PREFIX) {
err := model.NewAppError("CreateWebhookPost", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "post.type"}, "", http.StatusBadRequest)
return nil, err
}
if metrics := a.Metrics; metrics != nil {
metrics.IncrementWebhookPost()
}

Просмотреть файл

@@ -44,4 +44,9 @@ func TestCreateWebhookPost(t *testing.T) {
t.Fatal(k)
}
}
_, err = th.App.CreateWebhookPost(hook.UserId, th.BasicChannel, "foo", "user", "http://iconurl", nil, model.POST_SYSTEM_GENERIC)
if err == nil {
t.Fatal("should have failed - bad post type")
}
}