-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sc-57431): Support Opportunities API (#71)
* feat(sc-57431): Support Opportunities API * feat(sc-57431): Support Opportunities API : fix test data * feat(sc-57431): Support Opportunities API : lint Co-authored-by: Soeun <[email protected]> --------- Co-authored-by: Soeun <[email protected]>
- Loading branch information
1 parent
02667da
commit b3e4ad6
Showing
9 changed files
with
954 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -530,3 +530,120 @@ func TestCreateCustomerNote(t *testing.T) { | |
t.Fatal("Unexpected result") | ||
} | ||
} | ||
|
||
func TestListCustomerOpportunities(t *testing.T) { | ||
server := httptest.NewServer( | ||
http.HandlerFunc( | ||
func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != "GET" { | ||
t.Errorf("Unexpected method %v", r.Method) | ||
} | ||
if r.RequestURI != "/v/opportunities?customer_uuid=cus_00000000-0000-0000-0000-000000000000&per_page=1" { | ||
t.Errorf("Unexpected URI %v", r.RequestURI) | ||
} | ||
w.WriteHeader(http.StatusOK) | ||
//nolint | ||
w.Write([]byte(`{ | ||
"entries": [{ | ||
"uuid": "00000000-0000-0000-0000-000000000000", | ||
"customer_uuid": "cus_00000000-0000-0000-0000-000000000000", | ||
"owner": "[email protected]", | ||
"pipeline": "New business 1", | ||
"pipeline_stage": "Discovery", | ||
"estimated_close_date": "2023-12-22", | ||
"currency": "USD", | ||
"amount_in_cents": 100, | ||
"type": "recurring", | ||
"forecast_category": "pipeline", | ||
"win_likelihood": 3, | ||
"custom": {"from_campaign": true}, | ||
"created_at": "2024-03-13T07:33:28.356Z", | ||
"updated_at": "2024-03-13T07:33:28.356Z" | ||
}], | ||
"has_more": false, | ||
"cursor": "88abf99" | ||
}`)) | ||
})) | ||
defer server.Close() | ||
SetURL(server.URL + "/v/%v") | ||
|
||
tested := &API{ | ||
ApiKey: "token", | ||
} | ||
uuid := "cus_00000000-0000-0000-0000-000000000000" | ||
params := &ListOpportunitiesParams{Cursor: Cursor{PerPage: 1}} | ||
opportunities, err := tested.ListCustomerOpporunities(params, uuid) | ||
|
||
if err != nil { | ||
spew.Dump(err) | ||
t.Fatal("Not expected to fail") | ||
} | ||
if len(opportunities.Entries) == 0 { | ||
spew.Dump(opportunities) | ||
t.Fatal("Unexpected result") | ||
} | ||
} | ||
|
||
func TestCreateCustomerOpportunity(t *testing.T) { | ||
server := httptest.NewServer( | ||
http.HandlerFunc( | ||
func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != "POST" { | ||
t.Errorf("Unexpected method %v", r.Method) | ||
} | ||
if r.RequestURI != "/v/opportunities" { | ||
t.Errorf("Unexpected URI %v", r.RequestURI) | ||
} | ||
w.WriteHeader(http.StatusCreated) | ||
//nolint | ||
w.Write([]byte(`{ | ||
"uuid": "00000000-0000-0000-0000-000000000000", | ||
"customer_uuid": "cus_00000000-0000-0000-0000-000000000000", | ||
"owner": "[email protected]", | ||
"pipeline": "New business 1", | ||
"pipeline_stage": "Discovery", | ||
"estimated_close_date": "2023-12-22", | ||
"currency": "USD", | ||
"amount_in_cents": 100, | ||
"type": "recurring", | ||
"forecast_category": "pipeline", | ||
"win_likelihood": 3, | ||
"custom": {"from_campaign": true}, | ||
"created_at": "2024-03-13T07:33:28.356Z", | ||
"updated_at": "2024-03-13T07:33:28.356Z" | ||
}`)) | ||
})) | ||
defer server.Close() | ||
SetURL(server.URL + "/v/%v") | ||
|
||
tested := &API{ | ||
ApiKey: "token", | ||
} | ||
|
||
opportunity, err := tested.CreateCustomerOpportunity(&NewOpportunity{ | ||
Owner: "[email protected]", | ||
Pipeline: "New business 1", | ||
PipelineStage: "Discovery", | ||
EstimatedCloseDate: "2023-12-22", | ||
Currency: "USD", | ||
AmountInCents: 100, | ||
Type: "recurring", | ||
ForecastCategory: "pipeline", | ||
WinLikelihood: 3, | ||
Custom: []Custom{ | ||
{ | ||
Key: "from_campaign", | ||
Value: true, | ||
}, | ||
}, | ||
}, "cus_00000000-0000-0000-0000-000000000000") | ||
|
||
if err != nil { | ||
spew.Dump(err) | ||
t.Fatal("Not expected to fail") | ||
} | ||
if opportunity.UUID != "00000000-0000-0000-0000-000000000000" { | ||
spew.Dump(opportunity) | ||
t.Fatal("Unexpected result") | ||
} | ||
} |
Oops, something went wrong.