Skip to content

Commit

Permalink
feat: Added RAW_VALUE placement to c_set_value anonymization pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
hknokh committed Aug 13, 2024
1 parent 8dc57f4 commit 52e2343
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/modules/components/common_components/mockGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";



/**
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/modules/components/common_components/statics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down
7 changes: 4 additions & 3 deletions src/modules/models/job_models/migrationJobTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ export default class MigrationJobTask {
cachedCSVContent.updatedFilenames.add(childTask.data.sourceCsvFilename);
}
});
}
}
// else {
// csvIssues.push({
// "Date update": Common.formatDateTime(new Date()),
Expand Down Expand Up @@ -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 || '';
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 52e2343

Please sign in to comment.