diff --git a/type.go b/type.go index c7df15b..a13c1b9 100644 --- a/type.go +++ b/type.go @@ -33,6 +33,12 @@ func (hs *HsStr) String() string { // HsBool is defined to marshal the HubSpot boolean fields of `true`, `"true"`, and so on, into a bool type. type HsBool bool +// NewBoolean returns pointer HsBool(bool) +func NewBoolean(b bool) *HsBool { + v := HsBool(b) + return &v +} + // UnmarshalJSON implemented json.Unmarshaler. // This is because there are cases where the Time value returned by HubSpot is null or "true" / "false". func (hb *HsBool) UnmarshalJSON(b []byte) error { diff --git a/type_test.go b/type_test.go index 20a87c0..9ae9e76 100644 --- a/type_test.go +++ b/type_test.go @@ -39,6 +39,23 @@ func TestHsStr_String(t *testing.T) { } } +func TestHsBool_Boolean(t *testing.T) { + tests := []struct { + input bool + expected bool + }{ + {true, true}, + {false, false}, + } + + for _, test := range tests { + result := hubspot.NewBoolean(test.input) + if *result != hubspot.HsBool(test.expected) { + t.Errorf("NewBoolean(%v) = %v; want %v", test.input, *result, test.expected) + } + } +} + var testDate = time.Date(2022, time.February, 28, 0, 0, 0, 0, time.UTC) func TestHsTime_String(t *testing.T) {