From 52e23434875b6bec813c2a233438e01b450764c8 Mon Sep 17 00:00:00 2001 From: Haim Knokh Date: Tue, 13 Aug 2024 05:12:23 +0300 Subject: [PATCH] feat: Added RAW_VALUE placement to c_set_value anonymization pattern --- .../components/common_components/mockGenerator.ts | 9 +++++++-- src/modules/components/common_components/statics.ts | 1 + src/modules/models/job_models/migrationJobTask.ts | 7 ++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/modules/components/common_components/mockGenerator.ts b/src/modules/components/common_components/mockGenerator.ts index 4c755ee85..93f070c0f 100644 --- a/src/modules/components/common_components/mockGenerator.ts +++ b/src/modules/components/common_components/mockGenerator.ts @@ -5,6 +5,8 @@ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ +import { CONSTANTS } from "./statics"; + /** @@ -46,8 +48,11 @@ export class MockGenerator { return prefix + self.counter.counter[field]; }); - casual.define('c_set_value', function (field : any, value: any = null) { - return value; + casual.define('c_set_value', function (field: any, value: any = null, originalValue: any = null) { + if (typeof value == 'string') { + return value.replace(CONSTANTS.MOCK_EXPRESSION_ORIGINAL_VALUE, originalValue); + } + return value; }); casual.define('c_seq_date', function (field: any, from: any, step: any) { diff --git a/src/modules/components/common_components/statics.ts b/src/modules/components/common_components/statics.ts index 865200be2..ba077063c 100644 --- a/src/modules/components/common_components/statics.ts +++ b/src/modules/components/common_components/statics.ts @@ -39,6 +39,7 @@ export const CONSTANTS = { FIELDS_MAPPING_REGEX_PATTERN: '^\/(.*)\/$', FIELDS_MAPPING_EVAL_PATTERN: '^eval[(](.*)[)]$', FIELD_MAPPING_EVAL_PATTERN_ORIGINAL_VALUE: 'RAW_VALUE', + MOCK_EXPRESSION_ORIGINAL_VALUE: 'RAW_VALUE', SCRIPT_FILE_NAME: 'export.json', diff --git a/src/modules/models/job_models/migrationJobTask.ts b/src/modules/models/job_models/migrationJobTask.ts index 476c30e18..4803176c4 100644 --- a/src/modules/models/job_models/migrationJobTask.ts +++ b/src/modules/models/job_models/migrationJobTask.ts @@ -554,7 +554,7 @@ export default class MigrationJobTask { cachedCSVContent.updatedFilenames.add(childTask.data.sourceCsvFilename); } }); - } + } // else { // csvIssues.push({ // "Date update": Common.formatDateTime(new Date()), @@ -1641,7 +1641,7 @@ export default class MigrationJobTask { let fn = mockField.pattern; let mockFieldNameToUse = mockField.name == CONSTANTS.MOCK_ALL_FIELDS_PATTERN ? fieldDescribe.name : mockField.name; if (CONSTANTS.SPECIAL_MOCK_COMMANDS.some(x => fn.startsWith(x + "("))) { - fn = fn.replace(/\(/, `('${mockFieldNameToUse}',`); + fn = fn.replace(/\(/, `('${mockFieldNameToUse}',`).replace(/\)/, ', value)'); } mockField.excludedRegex = mockField.excludedRegex || ''; mockField.includedRegex = mockField.includedRegex || ''; @@ -1681,7 +1681,8 @@ export default class MigrationJobTask { if (!doNotMock) { [...fieldNameToMockFieldMap.keys()].forEach(fieldName => { if (mockAllRecord || fieldsToMockMap.has(fieldName)) { - let mockField = fieldNameToMockFieldMap.get(fieldName); + const mockField = fieldNameToMockFieldMap.get(fieldName); + const value = updatedRecord[fieldName]; value == value; if (mockField.fn == "ids") { updatedRecord[fieldName] = recordIds[index]; } else {