Skip to content

Commit 234e8a6

Browse files
authored
chore: fix bulk result NUTs W-19367052 (#1308)
* chore: run bulk result NUTs * test: fix bulk result NUTs
1 parent b2ba18d commit 234e8a6

4 files changed

Lines changed: 33 additions & 10 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
- 'yarn test:nuts:bulk:export'
2626
- 'yarn test:nuts:bulk:import'
2727
- 'yarn test:nuts:bulk:update'
28+
- 'yarn test:nuts:bulk:results'
2829
- 'yarn test:nuts:data:bulk-upsert-delete'
2930
- 'yarn test:nuts:data:create'
3031
- 'yarn test:nuts:data:query'

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
"test:nuts:bulk:export": "nyc mocha \"./test/commands/data/export/*.nut.ts\" --slow 4500 --timeout 600000 --parallel --jobs 20",
110110
"test:nuts:bulk:import": "nyc mocha \"./test/commands/data/import/*.nut.ts\" --slow 4500 --timeout 600000 --parallel --jobs 20",
111111
"test:nuts:bulk:update": "nyc mocha \"./test/commands/data/update/*.nut.ts\" --slow 4500 --timeout 600000 --parallel --jobs 20",
112+
"test:nuts:bulk:results": "nyc mocha \"./test/commands/data/bulk/*.nut.ts\" --slow 4500 --timeout 600000 --parallel --jobs 20",
112113
"test:nuts:data:bulk-upsert-delete": "nyc mocha \"./test/commands/data/dataBulk.nut.ts\" --slow 4500 --timeout 600000 --parallel --jobs 20",
113114
"test:nuts:data:create": "nyc mocha \"./test/commands/data/create/*.nut.ts\" --slow 4500 --timeout 600000 --parallel --jobs 20",
114115
"test:nuts:data:query": "nyc mocha \"./test/commands/data/query/*.nut.ts\" --slow 4500 --timeout 600000 --parallel --jobs 20",

src/bulkIngest.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,18 @@ export async function bulkIngest(opts: {
135135
if (jobInfo.numberRecordsFailed) {
136136
stages.error();
137137

138-
throw messages.createError(
138+
const err = messages.createError(
139139
'error.failedRecordDetails',
140140
[jobInfo.numberRecordsFailed],
141141
[conn.getUsername(), job.id, conn.getUsername(), job.id]
142142
);
143+
144+
err.setData({
145+
jobId: jobInfo.id,
146+
state: jobInfo.state,
147+
});
148+
149+
throw err;
143150
}
144151

145152
stages.stop();
@@ -242,11 +249,18 @@ export async function bulkIngestResume(opts: {
242249
};
243250
}
244251

245-
throw messages.createError(
252+
const err = messages.createError(
246253
'error.failedRecordDetails',
247254
[jobInfo.numberRecordsFailed],
248255
[conn.getUsername(), job.id, conn.getUsername(), job.id]
249256
);
257+
258+
err.setData({
259+
jobId: jobInfo.id,
260+
state: jobInfo.state,
261+
});
262+
263+
throw err;
250264
}
251265

252266
stages.stop();

test/commands/data/bulk/results.nut.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import path from 'node:path';
99
import { EOL } from 'node:os';
1010
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
1111
import { expect } from 'chai';
12-
import { ensureString } from '@salesforce/ts-types';
12+
import { AnyJson, ensureString } from '@salesforce/ts-types';
1313
import { validateCsv } from '../../../testUtil.js';
1414
import { DataImportBulkResult } from '../../../../src/commands/data/import/bulk.js';
1515
import { DataBulkResultsResult } from '../../../../src/commands/data/bulk/results.js';
@@ -61,15 +61,22 @@ describe('data bulk results NUTs', () => {
6161
it('should get success/failure results from a bulk import', async () => {
6262
const csvFile = await generateAccountsCsv(session.project.dir, 5000);
6363

64-
const bulkImportAsync = execCmd<DataImportBulkResult>(
65-
`data import bulk --file ${csvFile} --sobject account --wait 3 --json`,
66-
{ ensureExitCode: 0 }
67-
).jsonOutput?.result as DataImportBulkResult;
64+
type bulkImportErrResponse = AnyJson & {
65+
data: {
66+
jobId: string;
67+
state: string;
68+
};
69+
};
70+
71+
// the CSV will have 5000 wrong rows so the command is expected to fail, we just need the job ID from the response to get results
72+
const bulkImportErr = execCmd(`data import bulk --file ${csvFile} --sobject account --wait 5 --json`, {
73+
ensureExitCode: 1,
74+
}).jsonOutput as unknown as bulkImportErrResponse;
6875

69-
expect(bulkImportAsync.jobId).not.to.be.undefined;
70-
expect(bulkImportAsync.jobId).to.be.length(18);
76+
expect(bulkImportErr.data.jobId).not.to.be.undefined;
77+
expect(bulkImportErr.data.jobId).to.be.length(18);
7178

72-
const results = execCmd<DataBulkResultsResult>(`data bulk results --job-id ${bulkImportAsync.jobId} --json`, {
79+
const results = execCmd<DataBulkResultsResult>(`data bulk results --job-id ${bulkImportErr.data.jobId} --json`, {
7380
ensureExitCode: 0,
7481
}).jsonOutput?.result as DataBulkResultsResult;
7582

0 commit comments

Comments
 (0)