Skip to content
Open
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
10 changes: 5 additions & 5 deletions sobject/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,17 @@ func (d *dml) upsertResponse(request *http.Request) (UpsertValue, error) {

decoder := json.NewDecoder(response.Body)

var isInsert bool
var value UpsertValue

switch response.StatusCode {
case http.StatusCreated:
case http.StatusCreated, http.StatusOK:
defer response.Body.Close()
isInsert = true
err = decoder.Decode(&value)
if err != nil {
return UpsertValue{}, err
}
case http.StatusNoContent:
isInsert = false
break // out of the switch
default:
defer response.Body.Close()
var upsetErrs []sfdc.Error
Expand All @@ -284,7 +282,9 @@ func (d *dml) upsertResponse(request *http.Request) (UpsertValue, error) {
return UpsertValue{}, errMsg
}

value.Inserted = isInsert
if response.StatusCode == http.StatusCreated {
value.Inserted = true
}

return value, nil
}
Expand Down
42 changes: 42 additions & 0 deletions sobject/dml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,48 @@ func Test_dml_Upsert(t *testing.T) {
},
wantErr: false,
},
{
name: "Upsert Response Updated Passing",
fields: fields{
session: &mockSessionFormatter{
url: "https://test.salesforce.com",
client: mockHTTPClient(func(req *http.Request) *http.Response {
resp := `
{
"id" : "001D000000IqhSLIAZ",
"errors" : [ ],
"success" : true
}`

return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(strings.NewReader(resp)),
Header: make(http.Header),
}
}),
},
},
args: args{
upserter: &mockUpsert{
sobject: "Account",
id: "12345",
external: "external__c",
fields: map[string]interface{}{
"Name": "Some Test Name",
"Active": false,
},
},
},
want: UpsertValue{
Inserted: false,
InsertValue: InsertValue{
Success: true,
Errors: make([]sfdc.Error, 0),
ID: "001D000000IqhSLIAZ",
},
},
wantErr: false,
},
{
name: "Upsert Response Passing",
fields: fields{
Expand Down