Add ToJson() to PostActionIntegrationResponse (#9247)
* Add ToJson() to PostActionIntegrationResponse This commits adds a ToJson() methode to PostActionIntegrationResponse. It also adds tests for other ToJson() methods * Add PostActionIntegrationResponseFromJson function * Add PostActionIntegrationRequesteFromJson() function * Fix test names * Add testcase
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
0aa0adb911
Коммит
56d92de3f2
@@ -352,6 +352,29 @@ func (r *PostActionIntegrationRequest) ToJson() string {
|
|||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PostActionIntegrationRequesteFromJson(data io.Reader) *PostActionIntegrationRequest {
|
||||||
|
var o *PostActionIntegrationRequest
|
||||||
|
err := json.NewDecoder(data).Decode(&o)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *PostActionIntegrationResponse) ToJson() string {
|
||||||
|
b, _ := json.Marshal(r)
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func PostActionIntegrationResponseFromJson(data io.Reader) *PostActionIntegrationResponse {
|
||||||
|
var o *PostActionIntegrationResponse
|
||||||
|
err := json.NewDecoder(data).Decode(&o)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
func (o *Post) Attachments() []*SlackAttachment {
|
func (o *Post) Attachments() []*SlackAttachment {
|
||||||
if attachments, ok := o.Props["attachments"].([]*SlackAttachment); ok {
|
if attachments, ok := o.Props["attachments"].([]*SlackAttachment); ok {
|
||||||
return attachments
|
return attachments
|
||||||
|
|||||||
@@ -11,14 +11,46 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPostJson(t *testing.T) {
|
func TestPostToJson(t *testing.T) {
|
||||||
o := Post{Id: NewId(), Message: NewId()}
|
o := Post{Id: NewId(), Message: NewId()}
|
||||||
json := o.ToJson()
|
j := o.ToJson()
|
||||||
ro := PostFromJson(strings.NewReader(json))
|
ro := PostFromJson(strings.NewReader(j))
|
||||||
|
|
||||||
if o.Id != ro.Id {
|
assert.NotNil(t, ro)
|
||||||
t.Fatal("Ids do not match")
|
assert.Equal(t, o, *ro)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPostFromJsonError(t *testing.T) {
|
||||||
|
ro := PostFromJson(strings.NewReader(""))
|
||||||
|
assert.Nil(t, ro)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPostActionIntegrationRequestToJson(t *testing.T) {
|
||||||
|
o := PostActionIntegrationRequest{UserId: NewId(), Context: StringInterface{"a": "abc"}}
|
||||||
|
j := o.ToJson()
|
||||||
|
ro := PostActionIntegrationRequesteFromJson(strings.NewReader(j))
|
||||||
|
|
||||||
|
assert.NotNil(t, ro)
|
||||||
|
assert.Equal(t, o, *ro)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPostActionIntegrationRequestFromJsonError(t *testing.T) {
|
||||||
|
ro := PostActionIntegrationRequesteFromJson(strings.NewReader(""))
|
||||||
|
assert.Nil(t, ro)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPostActionIntegrationResponseToJson(t *testing.T) {
|
||||||
|
o := PostActionIntegrationResponse{Update: &Post{Id: NewId(), Message: NewId()}, EphemeralText: NewId()}
|
||||||
|
j := o.ToJson()
|
||||||
|
ro := PostActionIntegrationResponseFromJson(strings.NewReader(j))
|
||||||
|
|
||||||
|
assert.NotNil(t, ro)
|
||||||
|
assert.Equal(t, o, *ro)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPostActionIntegrationResponseFromJsonError(t *testing.T) {
|
||||||
|
ro := PostActionIntegrationResponseFromJson(strings.NewReader(""))
|
||||||
|
assert.Nil(t, ro)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPostIsValid(t *testing.T) {
|
func TestPostIsValid(t *testing.T) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user