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

FIO-8119: remove tags from data if value is null #213

Merged
Merged
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
18 changes: 18 additions & 0 deletions src/process/normalize/__tests__/normalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ProcessorContext,
ProcessorScope,
DayComponent,
TagsComponent,
} from 'types';
import { normalizeProcessSync } from '../';
import { generateProcessorContext } from '../../__tests__/fixtures/util';
Expand Down Expand Up @@ -338,4 +339,21 @@ describe('Normalize processor', function () {
normalizeProcessSync(context);
expect({ day: '01/2025' }).to.deep.equal({ day: '01/2025' });
});

it('Should remove the tag component from the submission object if data is set to null', async function () {
const tagsComponent: TagsComponent = {
input: true,
delimeter: '',
maxTags: 1,
storeas: '',
type: 'tags',
key: 'tags',
};
const data = {
tags: null,
};
const context: ProcessorContext<ProcessorScope> = generateProcessorContext(tagsComponent, data);
normalizeProcessSync(context);
expect(context.data).to.deep.equal({});
});
});
3 changes: 3 additions & 0 deletions src/process/normalize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ export const normalizeProcessSync: ProcessorFnSync<NormalizeScope> = (context) =
scope.normalize[path].normalized = true;
} else if (isTagsComponent(component)) {
set(data, path, normalizeTagsComponentValue(component, value));
if (data[path] === null) {
delete data[path];
}
scope.normalize[path].normalized = true;
} else if (isTextFieldComponent(component)) {
set(data, path, normalizeTextFieldComponentValue(component, defaultValues, value, path));
Expand Down
Loading