-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecode_resource_object_test.go
35 lines (31 loc) · 1 KB
/
decode_resource_object_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package jsonapi_test
import (
"github.com/ryanmoran/jsonapi"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("DecodeResourceObject", func() {
Describe("UnmarshalJSON", func() {
Context("failure cases", func() {
Context("when the JSON cannot be unmarshaled", func() {
It("returns an error", func() {
var payload SimplePayload
object := jsonapi.NewDecodeResourceObject(&payload)
err := object.UnmarshalJSON([]byte("%%%"))
Expect(err).To(MatchError(ContainSubstring("invalid character '%'")))
})
})
})
Context("when the type field and decodeable type don't match", func() {
It("returns an error", func() {
var payload SimplePayload
object := jsonapi.NewDecodeResourceObject(&payload)
err := object.UnmarshalJSON([]byte(`{
"type": "invalid-type",
"id": "some-id"
}`))
Expect(err).To(MatchError("cannot decode *jsonapi_test.SimplePayload &{}: types \"simple-payload\" and \"invalid-type\" do not match"))
})
})
})
})