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

Fix regroup validation error message #940

Merged
merged 3 commits into from
Aug 7, 2024
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
4 changes: 2 additions & 2 deletions src/__tests__/if-run/lib/regroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('lib/regroup: ', () => {
expect(error).toBeInstanceOf(InputValidationError);
expect(error).toEqual(
new InputValidationError(
'"groups" parameter is required. Error code: invalid_type.'
'"regroup" parameter is not an array or should contain at least one key. Error code: invalid_type.'
)
);
}
Expand Down Expand Up @@ -135,7 +135,7 @@ describe('lib/regroup: ', () => {
expect(error).toBeInstanceOf(InputValidationError);
expect(error).toEqual(
new InputValidationError(
'"groups" parameter is regroup phase is not an array or should contain at least one key.. Error code: too_small.'
'"regroup" parameter is array must contain at least 1 element(s). Error code: too_small.'
)
);
}
Expand Down
3 changes: 1 addition & 2 deletions src/if-run/config/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export const STRINGS = {
METRIC_MISSING: (metric: string, index: number) =>
`Aggregation metric ${metric} is not found in inputs[${index}].`,
INVALID_GROUP_KEY: (key: string) => `Invalid group ${key}.`,
REGROUP_ERROR:
'Regroup phase is not an array or should contain at least one key.',
REGROUP_ERROR: 'not an array or should contain at least one key',
INVALID_EXHAUST_PLUGIN: (pluginName: string) =>
`Invalid exhaust plugin: ${pluginName}.`,
UNKNOWN_PARAM: (name: string) =>
Expand Down
7 changes: 4 additions & 3 deletions src/if-run/lib/regroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ export const Regroup = (inputs: PluginParams[], groups: string[]) => {
/**
* Validates groups array.
*/
const validateGroups = (groups: string[]) => {
const inputData = {groups};
const validateGroups = (regroup: string[]) => {
const inputData = {regroup};
const validationSchema = z.record(
z.string(),
z.array(z.string()).min(1, REGROUP_ERROR)
z.array(z.string(), {message: REGROUP_ERROR}).min(1)
);

validate(validationSchema, inputData);

return groups;
Expand Down