1
0
mirror of synced 2024-11-21 20:36:06 +03:00
messenger/response_test.go

34 lines
912 B
Go
Raw Permalink Normal View History

2021-02-17 15:25:52 +03:00
package messenger
import (
2022-01-26 14:35:38 +03:00
"bytes"
2021-02-17 15:25:52 +03:00
"encoding/json"
2022-01-26 14:35:38 +03:00
"errors"
2021-02-17 15:25:52 +03:00
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_MarshalStructuredMessageElement(t *testing.T) {
data, err := json.Marshal(StructuredMessageElement{
Title: "Title",
})
require.NoError(t, err)
assert.JSONEq(t, string(data), `{"image_url":"", "subtitle":"", "title": "Title"}`)
}
2022-01-26 14:35:38 +03:00
func TestResponse_checkFacebookError_UnmarshalError(t *testing.T) {
2022-01-27 17:17:20 +03:00
r := bytes.NewReader([]byte("test error text"))
2022-01-26 14:35:38 +03:00
err := checkFacebookError(r)
assert.True(t, errors.Is(err, ErrUnmarshal))
2022-01-27 17:17:20 +03:00
assert.Contains(t, err.Error(), "test error text")
2022-01-26 14:35:38 +03:00
}
func TestResponse_getFacebookQueryResponse_UnmarshalError(t *testing.T) {
2022-01-27 17:17:20 +03:00
r := bytes.NewReader([]byte("test error text"))
2022-01-26 14:35:38 +03:00
_, err := getFacebookQueryResponse(r)
assert.True(t, errors.Is(err, ErrUnmarshal))
2022-01-27 17:17:20 +03:00
assert.Contains(t, err.Error(), "test error text")
2022-01-26 14:35:38 +03:00
}