diff options
author | Hanzei <Hanzei@users.noreply.github.com> | 2018-08-20 18:21:16 +0200 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2018-08-20 09:21:16 -0700 |
commit | 56d92de3f20fa1d89c2d2c09b03e933a1325af8b (patch) | |
tree | 29fb0302e2ec3c694be6219e9e26ee76518b1072 /model/post_test.go | |
parent | 0aa0adb9113455da719877f2a3553df1e0ee0a97 (diff) | |
download | chat-56d92de3f20fa1d89c2d2c09b03e933a1325af8b.tar.gz chat-56d92de3f20fa1d89c2d2c09b03e933a1325af8b.tar.bz2 chat-56d92de3f20fa1d89c2d2c09b03e933a1325af8b.zip |
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
Diffstat (limited to 'model/post_test.go')
-rw-r--r-- | model/post_test.go | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/model/post_test.go b/model/post_test.go index af350d76e..b15134c89 100644 --- a/model/post_test.go +++ b/model/post_test.go @@ -11,14 +11,46 @@ import ( "github.com/stretchr/testify/assert" ) -func TestPostJson(t *testing.T) { +func TestPostToJson(t *testing.T) { o := Post{Id: NewId(), Message: NewId()} - json := o.ToJson() - ro := PostFromJson(strings.NewReader(json)) + j := o.ToJson() + ro := PostFromJson(strings.NewReader(j)) - if o.Id != ro.Id { - t.Fatal("Ids do not match") - } + assert.NotNil(t, ro) + 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) { |