forked from sbstjn/appsync-resolvers
-
Notifications
You must be signed in to change notification settings - Fork 1
/
payload_test.go
54 lines (43 loc) · 1.13 KB
/
payload_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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package resolvers
import (
"encoding/json"
"reflect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Payload", func() {
Context("Invalid JSON", func() {
message := payload{json.RawMessage(`{""name": "example"}`)}
example := resolver{func(args struct {
Name string `json:"name"`
}) error {
return nil
}}
args, err := message.parse(reflect.TypeOf(example.function).In(0))
It("should error", func() {
Expect(err).To(HaveOccurred())
})
It("should return nil", func() {
Expect(args).To(BeNil())
})
})
Context("Valid JSON and resolver with parameter", func() {
message := payload{json.RawMessage(`{"name": "example"}`)}
example := resolver{func(args struct {
Name string `json:"name"`
}) error {
return nil
}}
args, err := message.parse(reflect.TypeOf(example.function).In(0))
It("should not error", func() {
Expect(err).NotTo(HaveOccurred())
})
It("should return struct", func() {
Expect(args).NotTo(BeNil())
})
It("should parse data", func() {
Expect(args).To(HaveLen(1))
Expect(args[0].FieldByName("Name").String()).To(Equal("example"))
})
})
})