Skip to content

Commit

Permalink
Merge pull request #63 from k-capehart/feat/handle-300-response
Browse files Browse the repository at this point in the history
feat: handle 300 response for when multiple matches are found for a single salesforce external id
  • Loading branch information
k-capehart authored Sep 20, 2024
2 parents 3c494e3 + a829c3c commit 3496b09
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ Anyone is welcome to contribute.
- Open an issue or discussion post to track the effort
- Fork this repository, then clone it
- Place this in your own module's `go.mod` to enable testing local changes
- `replace github.com/k-capehart/go-salesforce => /path_to_local_fork/`
- `replace github.com/k-capehart/go-salesforce/v2 => /path_to_local_fork/`
- Run tests
- `go test -cover`
- Generate code coverage output
Expand Down
2 changes: 1 addition & 1 deletion salesforce.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func doRequest(auth *authentication, payload requestPayload) (*http.Response, er
if err != nil {
return resp, err
}
if resp.StatusCode < 200 || resp.StatusCode > 299 {
if resp.StatusCode < 200 || resp.StatusCode > 300 {
resp, err = processSalesforceError(*resp, auth, payload)
}

Expand Down
19 changes: 19 additions & 0 deletions salesforce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ func setupTestServer(body any, status int) (*httptest.Server, authentication) {
func Test_doRequest(t *testing.T) {
server, sfAuth := setupTestServer("", http.StatusOK)
defer server.Close()

badServer, badSfAuth := setupTestServer("", http.StatusBadRequest)
defer badServer.Close()

recordArrayResp := [2]string{"testRecord1", "testRecord2"}
serverWith300Resp, authWith300Resp := setupTestServer(recordArrayResp, http.StatusMultipleChoices)
defer serverWith300Resp.Close()

type args struct {
auth *authentication
payload requestPayload
Expand Down Expand Up @@ -79,6 +84,20 @@ func Test_doRequest(t *testing.T) {
want: http.StatusBadRequest,
wantErr: true,
},
{
name: "handle_multiple_records_with_same_externalId_statusCode_300",
args: args{
auth: &authWith300Resp,
payload: requestPayload{
method: http.MethodGet,
uri: "/sobjects/Contact/ContactExternalId__c/Avng1",
content: jsonType,
body: "",
},
},
want: http.StatusMultipleChoices,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 3496b09

Please sign in to comment.