-
Notifications
You must be signed in to change notification settings - Fork 1
/
null_date_test.go
43 lines (35 loc) · 1.45 KB
/
null_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
package scalars_test
import (
"strings"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/volatiletech/null/v8"
scalars "github.com/nrfta/go-graphql-scalars"
)
var _ = Describe("Marshall/ UnMarshall null time", func() {
var (
testDateString = "2019-01-02"
testStringBuilder = &strings.Builder{}
testTime, _ = time.Parse("2006-01-02", testDateString)
)
It("Should return of null.Time type if null value passed onto UnmarshalNullDate", func() {
nullTime, err := scalars.UnmarshalNullDate(nil)
Expect(err).To(Succeed())
Expect(nullTime).Should(BeAssignableToTypeOf(null.Time{}))
Expect(nullTime.Valid).Should(BeEquivalentTo(false))
})
It("returns a valid date of null.Time type for valid input", func() {
notNullDate, _ := scalars.UnmarshalNullDate(testDateString)
Expect(notNullDate).Should(BeAssignableToTypeOf(null.Time{}))
Expect(notNullDate.Time).To(Equal(testTime))
})
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(testDateString))
notNullDate, _ := scalars.UnmarshalNullDate(marshaledTimeString)
Expect(notNullDate).Should(BeAssignableToTypeOf(null.Time{}))
})
})