Skip to content

Commit

Permalink
Merge pull request #940 from Green-Software-Foundation/regroup-fix
Browse files Browse the repository at this point in the history
Fix `regroup` validation error message
  • Loading branch information
jmcook1186 committed Aug 7, 2024
2 parents f4330c3 + 98bdee7 commit c4cf1f1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
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

0 comments on commit c4cf1f1

Please sign in to comment.