Skip to content

Commit a674fcf

Browse files
author
hknokh2
committed
fix: enable useSourceCSVFile prep for org source object sets
1 parent b0f4370 commit a674fcf

File tree

2 files changed

+79
-10
lines changed

2 files changed

+79
-10
lines changed

src/modules/models/job/MigrationJob.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -413,23 +413,17 @@ export default class MigrationJob implements ISFdmuRunCustomAddonJob {
413413
await this._loadValueMappingFileAsync();
414414

415415
const sourceIsCsv = this.script.sourceOrg?.isFileMedia ?? false;
416-
const targetIsCsv = this.script.targetOrg?.isFileMedia ?? false;
417-
if (!sourceIsCsv && !targetIsCsv) {
418-
return;
419-
}
420-
if (!sourceIsCsv) {
416+
const csvTasks = this._getCsvTasks();
417+
const hasCsvSourceTasks = csvTasks.length > 0;
418+
if (!sourceIsCsv && !hasCsvSourceTasks) {
421419
return;
422420
}
423-
424-
const csvTasks = this._getCsvTasks();
425421
if (csvTasks.length === 0) {
426422
return;
427423
}
428424

429425
await this._ensureCsvDirectoriesAsync();
430-
if (sourceIsCsv) {
431-
await this._clearCsvDirectoryAsync(this.script.sourceDirectoryPath, 'unableToDeleteSourceDirectory');
432-
}
426+
await this._clearCsvDirectoryAsync(this.script.sourceDirectoryPath, 'unableToDeleteSourceDirectory');
433427
await this._prepareUserAndGroupCsvSourcesAsync(csvTasks);
434428

435429
const logger = this._getLogger();

test/modules/job/migration-job-csv.test.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,81 @@ describe('MigrationJob CSV processing', () => {
936936
assert.equal(map?.get('Customer'), 'Client');
937937
});
938938

939+
it('prepares source CSV for useSourceCSVFile in object-set mode when source is org', async () => {
940+
const rootPath = createTempDir();
941+
const logger = createLoggingService(rootPath);
942+
Common.logger = logger;
943+
944+
const exportPath = path.join(rootPath, 'export.json');
945+
fs.writeFileSync(
946+
exportPath,
947+
JSON.stringify(
948+
{
949+
objectSets: [
950+
{
951+
objects: [
952+
{
953+
name: 'Contact',
954+
query: 'SELECT Id FROM Contact',
955+
operation: 'Readonly',
956+
},
957+
],
958+
},
959+
{
960+
objects: [
961+
{
962+
name: 'Account',
963+
query: "SELECT Id, Name FROM Account WHERE Name = 'CSV_ONLY'",
964+
operation: 'Upsert',
965+
externalId: 'Name',
966+
useSourceCSVFile: true,
967+
},
968+
],
969+
},
970+
],
971+
},
972+
null,
973+
2
974+
),
975+
'utf8'
976+
);
977+
978+
const baseScript = await ScriptLoader.loadFromPathAsync(rootPath, logger);
979+
baseScript.logger = logger;
980+
baseScript.sourceOrg = createOrg(baseScript, 'source', DATA_MEDIA_TYPE.Org);
981+
baseScript.targetOrg = createOrg(baseScript, 'target', DATA_MEDIA_TYPE.Org);
982+
const script = ScriptLoader.createScriptForObjectSet(baseScript, 1);
983+
984+
const describes = new Map<string, SObjectDescribe>([
985+
[
986+
'Account',
987+
createDescribe('Account', [
988+
{ name: 'Id', updateable: true, creatable: true },
989+
{ name: 'Name', nameField: true, updateable: true, creatable: true },
990+
]),
991+
],
992+
]);
993+
const metadataProvider = createMetadataProvider(describes);
994+
const job = new MigrationJob({ script, metadataProvider });
995+
996+
await job.loadAsync();
997+
await job.setupAsync();
998+
999+
fs.mkdirSync(script.rawSourceDirectoryPath, { recursive: true });
1000+
await Common.writeCsvFileAsync(
1001+
path.join(script.rawSourceDirectoryPath, 'Account.csv'),
1002+
[{ Name: 'CSV_ONLY' }],
1003+
true
1004+
);
1005+
1006+
await job.processCsvAsync();
1007+
1008+
const sourceFile = Common.getCSVFilename(script.sourceDirectoryPath, 'Account', CSV_SOURCE_FILE_SUFFIX);
1009+
const rows = await Common.readCsvFileAsync(sourceFile);
1010+
assert.equal(rows.length, 1);
1011+
assert.equal(rows[0]['Name'], 'CSV_ONLY');
1012+
});
1013+
9391014
it('writes CSV issues report when required columns are missing', async () => {
9401015
const rootPath = createTempDir();
9411016
const logger = createLoggingService(rootPath);

0 commit comments

Comments
 (0)