Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit test for tranform function #183

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/cli/__tests__/engine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,24 @@ describe('Engine', () => {

expect(result).toBeNull();
});

it('returns masked string', () => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('returns masked string', () => {
it('returns the masked string', () => {

const engine = new Engine();

engine.aoo = {
tables: {},
};
Comment on lines +154 to +156
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think even this should work?

Suggested change
engine.aoo = {
tables: {},
};
engine.aoo = {};


engine.cache = {
tableName: 'users',
columns: ['name', 'description', 'id'],
transformers: {
description: () => 'This will be used',
},
};

const result = engine.transform(`Hello\tThis is coder\t3`);

expect(result).toEqual('Hello\tThis will be used\t3');
});
});
10 changes: 5 additions & 5 deletions src/cli/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Engine {
return true;
}

#transform(line: string) {
transform(line: string) {
if (!(this.cache?.transformers || this.aoo.defaultTransformer)) return line;
if (!line.trim() || line === `\\.`) return line;

Expand All @@ -160,18 +160,18 @@ class Engine {
const [middleware, mapping] = transformers;
const passedRecord = middleware(record, columns!);
if (passedRecord) {
maskedData = this.#declarativeTransformation(passedRecord, mapping);
maskedData = this.declarativeTransformation(passedRecord, mapping);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this renamed?

} else {
maskedData = record;
}
} else {
maskedData = this.#declarativeTransformation(record, transformers!);
maskedData = this.declarativeTransformation(record, transformers!);
}

return maskedData.join(`\t`);
}

#declarativeTransformation(record: string[], transformers: ColumnTypes): string[] {
declarativeTransformation(record: string[], transformers: ColumnTypes): string[] {
const columns = this.cache?.columns;
return record.map((value: String, index: number) => {
if (transformers?.hasOwnProperty(columns![index])) {
Expand Down Expand Up @@ -215,7 +215,7 @@ class Engine {
/*
Query data in progress
*/
line = this.#transform(line);
line = this.transform(line);
}
}

Expand Down