Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NewBool function to convert regular bool to hubspot boolean #32

Merged
merged 2 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading