-
Notifications
You must be signed in to change notification settings - Fork 1
/
date_test.go
51 lines (41 loc) · 1.44 KB
/
date_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
package scalars_test
import (
"strings"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
scalars "github.com/nrfta/go-graphql-scalars"
)
type sampleTime struct {
TimeString string
}
var (
correctTime = "2019-06-24"
wrongTime = "2019-06-2435"
)
var _ = Describe("Unmarshal Date Test", func() {
It("returns a time object when proper time string passed in", func() {
Expect(scalars.UnmarshalDate(correctTime)).Should(BeAssignableToTypeOf(time.Time{}))
})
It("returns an error when improper formatted time passed in", func() {
_, err := scalars.UnmarshalDate(wrongTime)
Expect(err).ToNot(BeNil())
})
It("handles ios 8601 as input", func() {
Expect(scalars.UnmarshalDate("2006-01-02T15:04:05-07:00")).Should(BeAssignableToTypeOf(time.Time{}))
})
})
var (
testTimeString = "2019-01-02"
testTime, _ = time.Parse("2006-01-02", testTimeString)
testStringBuilder = &strings.Builder{}
)
var _ = Describe("Marshal Date Test", func() {
It("returns a function that writes the time from string format into a slice of bytes", func() {
scalars.MarshalDate(testTime).MarshalGQL(testStringBuilder)
marshaledTimeString := testStringBuilder.String()
marshaledTimeString = (marshaledTimeString[1 : len(marshaledTimeString)-1]) // gets rid of extra quotes around Marshalled String
Expect(marshaledTimeString).To(Equal(testTimeString))
Expect(scalars.UnmarshalDate(correctTime)).Should(BeAssignableToTypeOf(time.Time{}))
})
})