Skip to content

Commit 9afdc77

Browse files
committed
[ENG-2914] fix(salesforce): Batch WriteResult has either errors or data (unit-tests)
1 parent 1e6cacf commit 9afdc77

2 files changed

Lines changed: 11 additions & 32 deletions

File tree

providers/salesforce/batch-write_test.go

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestBatchCreate(t *testing.T) { // nolint:funlen,gocognit,cyclop,maintidx
7474
"statusCode": "REQUIRED_FIELD_MISSING",
7575
"message": "Required fields are missing: [LastName]",
7676
"fields": ["LastName"]}`)},
77-
Data: map[string]any{"referenceId": "ref0"},
77+
Data: nil,
7878
}, {
7979
Success: false,
8080
RecordId: "",
@@ -126,7 +126,7 @@ func TestBatchCreate(t *testing.T) { // nolint:funlen,gocognit,cyclop,maintidx
126126
"message": "Duplicate ReferenceId found: ref1",
127127
"fields": []}`),
128128
},
129-
Data: map[string]any{"referenceId": "ref1"},
129+
Data: nil,
130130
}},
131131
SuccessCount: 0,
132132
FailureCount: 2,
@@ -272,33 +272,15 @@ func TestBatchUpdate(t *testing.T) { // nolint:funlen,gocognit,cyclop,maintidx
272272
"statusCode": "MISSING_ARGUMENT",
273273
"message": "Id not specified in an update call",
274274
"fields": []}`)},
275-
Data: map[string]any{
276-
"success": false,
277-
"errors": []any{
278-
map[string]any{
279-
"statusCode": "MISSING_ARGUMENT",
280-
"message": "Id not specified in an update call",
281-
"fields": []any{},
282-
},
283-
},
284-
},
275+
Data: nil,
285276
}, {
286277
Success: false,
287278
RecordId: "",
288279
Errors: []any{mockutils.JSONErrorWrapper(`{
289280
"statusCode": "MISSING_ARGUMENT",
290281
"message": "Id not specified in an update call",
291282
"fields": []}`)},
292-
Data: map[string]any{
293-
"success": false,
294-
"errors": []any{
295-
map[string]any{
296-
"statusCode": "MISSING_ARGUMENT",
297-
"message": "Id not specified in an update call",
298-
"fields": []any{},
299-
},
300-
},
301-
},
283+
Data: nil,
302284
}},
303285
SuccessCount: 0,
304286
FailureCount: 2,
@@ -337,16 +319,7 @@ func TestBatchUpdate(t *testing.T) { // nolint:funlen,gocognit,cyclop,maintidx
337319
"statusCode": "MISSING_ARGUMENT",
338320
"message": "Id not specified in an update call",
339321
"fields": []}`)},
340-
Data: map[string]any{
341-
"success": false,
342-
"errors": []any{
343-
map[string]any{
344-
"statusCode": "MISSING_ARGUMENT",
345-
"message": "Id not specified in an update call",
346-
"fields": []any{},
347-
},
348-
},
349-
},
322+
Data: nil,
350323
}},
351324
SuccessCount: 1,
352325
FailureCount: 1,

test/utils/mockutils/writeResult.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ type writeResultComparator struct{}
1313
// SubsetData checks that expected WriteResult.Data is a subset of actual WriteResult.Data
1414
// other fields are strictly compared.
1515
func (writeResultComparator) SubsetData(actual, expected *common.WriteResult) bool {
16+
// We are expecting more fields than there in the existence.
1617
if len(actual.Data) < len(expected.Data) {
1718
return false
1819
}
1920

21+
// At least one field should be mentioned.
22+
if len(actual.Data) > 0 && len(expected.Data) == 0 {
23+
return false
24+
}
25+
2026
for k, expectedValue := range expected.Data {
2127
actualValue, ok := actual.Data[k]
2228
if !ok {

0 commit comments

Comments
 (0)