Skip to content

Commit

Permalink
Merge pull request #32 from marcopollivier/main
Browse files Browse the repository at this point in the history
Add NewBool function to convert regular bool to hubspot boolean
  • Loading branch information
kk-no authored May 20, 2024
2 parents d62f156 + a08b968 commit f288b6c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f288b6c

Please sign in to comment.