-
Notifications
You must be signed in to change notification settings - Fork 1
/
null_date_time_test.go
43 lines (35 loc) · 1.53 KB
/
null_date_time_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("Marshal/ Unmarshal null DateTime Test", func() {
var (
correctDateTime = "2006-01-02T15:04:05Z"
testDateTime, _ = time.Parse(time.RFC3339, correctDateTime)
testStringBuilder = &strings.Builder{}
)
It("Should return value of null.Time type if null passed onto UnmarshalNullDate", func() {
nullTime, _ := scalars.UnmarshalNullDateTime(nil)
Expect(nullTime).Should(BeAssignableToTypeOf(null.Time{}))
Expect(nullTime.Valid).Should(BeEquivalentTo(false))
})
It("returns datetime of null.Time type for valid input", func() {
notNullDate, err := scalars.UnmarshalNullDateTime(correctDateTime)
Expect(err).To(Succeed())
Expect(notNullDate).Should(BeAssignableToTypeOf(null.Time{}))
Expect(notNullDate.Time).To(Equal(testDateTime))
})
It("returns a function that writes the time from string format into a slice of bytes", func() {
scalars.MarshalNullDateTime(null.TimeFrom(testDateTime)).MarshalGQL(testStringBuilder)
marshaledDateTimeString := testStringBuilder.String()
marshaledDateTimeString = (marshaledDateTimeString[1 : len(marshaledDateTimeString)-1]) // gets rid of extra quotes around Marshalled String
Expect(marshaledDateTimeString).To(Equal(correctDateTime))
notNullDate, _ := scalars.UnmarshalNullDateTime(marshaledDateTimeString)
Expect(notNullDate).Should(BeAssignableToTypeOf(null.Time{}))
})
})