Skip to content

Commit

Permalink
fix unit test and fix make test can receive test options
Browse files Browse the repository at this point in the history
  • Loading branch information
kk-no committed Nov 8, 2023
1 parent ae2da13 commit d02d4a3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ vendor: ## make go vendor
go mod vendor

.PHONY: test
test: ## run go test
go test ./...
test: ## run go test. If you need test options, pass them in like OPTIONS="-v"
go test ./... $(OPTIONS)

# Install golangci-lint
GOLANGCLI_LINT := $(BIN)/golangci-lint
Expand Down
59 changes: 51 additions & 8 deletions company_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import (

func TestCompanyServiceOp_Create(t *testing.T) {
company := &hubspot.Company{
Address: hubspot.NewString("example address"),
City: hubspot.NewString("Cambridge"),
Domain: hubspot.NewString("biglytics.net"),
Industry: hubspot.NewString("Technology"),
Name: hubspot.NewString("Biglytics"),
Phone: hubspot.NewString("(877)929-0687"),
State: hubspot.NewString("Massachusetts"),
}

type fields struct {
Expand Down Expand Up @@ -45,7 +50,14 @@ func TestCompanyServiceOp_Create(t *testing.T) {
ID: "company001",
Archived: false,
Properties: &hubspot.Company{
Address: hubspot.NewString("example address"),
City: hubspot.NewString("Cambridge"),
Createdate: &createdAt,
Domain: hubspot.NewString("biglytics.net"),
HsLastmodifieddate: &updatedAt,
Industry: hubspot.NewString("Technology"),
Name: hubspot.NewString("Biglytics"),
Phone: hubspot.NewString("(877)929-0687"),
State: hubspot.NewString("Massachusetts"),
},
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
Expand Down Expand Up @@ -93,7 +105,12 @@ func TestCompanyServiceOp_Create(t *testing.T) {

func TestCompanyServiceOp_Update(t *testing.T) {
company := &hubspot.Company{
Address: hubspot.NewString("example address"),
City: hubspot.NewString("Cambridge"),
Domain: hubspot.NewString("biglytics.net"),
Industry: hubspot.NewString("Technology"),
Name: hubspot.NewString("Biglytics"),
Phone: hubspot.NewString("(877)929-0687"),
State: hubspot.NewString("Massachusetts"),
}

type fields struct {
Expand Down Expand Up @@ -128,7 +145,14 @@ func TestCompanyServiceOp_Update(t *testing.T) {
ID: "company001",
Archived: false,
Properties: &hubspot.Company{
Address: hubspot.NewString("example address"),
City: hubspot.NewString("Cambridge"),
Createdate: &createdAt,
Domain: hubspot.NewString("biglytics.net"),
HsLastmodifieddate: &updatedAt,
Industry: hubspot.NewString("Technology"),
Name: hubspot.NewString("Biglytics"),
Phone: hubspot.NewString("(877)929-0687"),
State: hubspot.NewString("Massachusetts"),
},
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
Expand Down Expand Up @@ -178,6 +202,8 @@ func TestCompanyServiceOp_Update(t *testing.T) {
func TestCompanyServiceOp_Get(t *testing.T) {
type CustomFields struct {
hubspot.Company
CustomName *hubspot.HsStr `json:"custom_name,omitempty"`
CustomDate *hubspot.HsTime `json:"custom_date,omitempty"`
}

type fields struct {
Expand All @@ -203,18 +229,35 @@ func TestCompanyServiceOp_Get(t *testing.T) {
client: hubspot.NewMockClient(&hubspot.MockConfig{
Status: http.StatusOK,
Header: http.Header{},
Body: []byte(`{"id":"company001","properties":{"city":"Cambridge","createdate":"2019-10-30T03:30:17.883Z","domain":"biglytics.net","hs_lastmodifieddate":"2019-12-07T16:50:06.678Z","industry":"Technology","name":"Biglytics","phone":"(877)929-0687","state":"Massachusetts","address":"address"},"createdAt":"2019-10-30T03:30:17.883Z","updatedAt":"2019-12-07T16:50:06.678Z"}`),
Body: []byte(`{"id":"company001","properties":{"city":"Cambridge","createdate":"2019-10-30T03:30:17.883Z","domain":"biglytics.net","hs_lastmodifieddate":"2019-12-07T16:50:06.678Z","industry":"Technology","name":"Biglytics","phone":"(877)929-0687","state":"Massachusetts","custom_name":"biglytics","custom_date":"2019-10-30T03:30:17.883Z"},"createdAt":"2019-10-30T03:30:17.883Z","updatedAt":"2019-12-07T16:50:06.678Z"}`),
}),
},
args: args{
companyID: "company001",
company: &hubspot.Company{},
company: &CustomFields{},
option: &hubspot.RequestQueryOption{
Properties: []string{
"custom_name",
"custom_date",
},
},
},
want: &hubspot.ResponseResource{
ID: "company001",
Archived: false,
Properties: &hubspot.Company{
Address: hubspot.NewString("address"),
Properties: &CustomFields{
Company: hubspot.Company{
City: hubspot.NewString("Cambridge"),
Createdate: &createdAt,
Domain: hubspot.NewString("biglytics.net"),
HsLastmodifieddate: &updatedAt,
Industry: hubspot.NewString("Technology"),
Name: hubspot.NewString("Biglytics"),
Phone: hubspot.NewString("(877)929-0687"),
State: hubspot.NewString("Massachusetts"),
},
CustomName: hubspot.NewString("biglytics"),
CustomDate: &createdAt,
},
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
Expand Down

0 comments on commit d02d4a3

Please sign in to comment.