Migrate entra groupsetting and groupsettingtemplate commands to Zod#7366
Migrate entra groupsetting and groupsettingtemplate commands to Zod#7366waldekmastykarz wants to merge 2 commits into
Conversation
Migrate all 7 commands to use Zod schemas for option validation: - entra groupsetting add - entra groupsetting get - entra groupsetting list - entra groupsetting remove - entra groupsetting set - entra groupsettingtemplate get - entra groupsettingtemplate list Closes pnp#7297 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR migrates the Entra groupsetting and groupsettingtemplate command set from legacy option initialization/validation/telemetry patterns to Zod-based schemas, aligning these commands with the newer validation and telemetry flow in the CLI.
Changes:
- Introduces Zod schemas (
schema+ optionalgetRefinedSchema) for option validation across the 7 commands. - Replaces manual GUID validation with
z.uuid()and adds short option aliases via.alias(). - Updates unit tests to validate via
command.getSchemaToParse().safeParse()rather thancommand.validate().
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/m365/entra/commands/groupsettingtemplate/groupsettingtemplate-list.ts | Adds Zod schema for global-only options and exposes it via schema. |
| src/m365/entra/commands/groupsettingtemplate/groupsettingtemplate-get.ts | Adds strict Zod schema + refined schema enforcing the id/displayName option set. |
| src/m365/entra/commands/groupsettingtemplate/groupsettingtemplate-get.spec.ts | Updates validation tests to use safeParse() against the schema-to-parse. |
| src/m365/entra/commands/groupsetting/groupsetting-set.ts | Migrates to loose Zod schema to support unknown options + GUID validation via z.uuid(). |
| src/m365/entra/commands/groupsetting/groupsetting-set.spec.ts | Updates tests to validate via Zod schema parsing. |
| src/m365/entra/commands/groupsetting/groupsetting-remove.ts | Migrates to strict Zod schema with id and optional force flag. |
| src/m365/entra/commands/groupsetting/groupsetting-remove.spec.ts | Updates validation tests to use schema parsing; removes legacy option-list assertions. |
| src/m365/entra/commands/groupsetting/groupsetting-list.ts | Adds Zod schema for global-only options and exposes it via schema. |
| src/m365/entra/commands/groupsetting/groupsetting-get.ts | Migrates to strict Zod schema for id with UUID validation + alias. |
| src/m365/entra/commands/groupsetting/groupsetting-get.spec.ts | Updates GUID validation tests to use safeParse(). |
| src/m365/entra/commands/groupsetting/groupsetting-add.ts | Migrates to loose Zod schema for templateId + allows unknown options. |
| src/m365/entra/commands/groupsetting/groupsetting-add.spec.ts | Updates GUID validation tests to use safeParse(). |
| const options = z.looseObject({ | ||
| ...globalOptionsZod.shape, | ||
| templateId: z.uuid().alias('i') | ||
| }); |
Address review comments: - Export options const in groupsetting-add.ts and groupsetting-set.ts - Fix spec files to import options from their own command file Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
MartinM85
left a comment
There was a problem hiding this comment.
Hi @waldekmastykarz , I have a couple of comments, great job otherwise. 👍
There was a problem hiding this comment.
I would suggest to update .spec.ts. file and add tests for 'no options' and 'unknown options'.
There was a problem hiding this comment.
I would suggest to update .spec.ts. file and add tests for 'no options' and 'unknown options'.
| throw 'Invalid request'; | ||
| }); | ||
|
|
||
| await assert.rejects(command.action(logger, { options: { displayName: 'Invalid' } } as any), |
There was a problem hiding this comment.
I would suggest to use the commandOptionsSchema.parse
| await assert.rejects(command.action(logger, { options: commandOptionsSchema.parse({ displayName: 'Invalid' })}), |
Same for other tests in this file.
| await command.action(logger, { | ||
| options: { | ||
| id: 'c391b57d-5783-4c53-9236-cefb5c6ef323', | ||
| UsageGuidelinesUrl: 'https://contoso.sharepoint.com/sites/compliance', | ||
| ClassificationList: 'HBI, MBI, LBI, GDPR', | ||
| DefaultClassification: 'MBI' | ||
| } | ||
| }); |
There was a problem hiding this comment.
I would suggest to use the commandOptionsSchema.parse to test that unknown options can be passed.
| await command.action(logger, { | |
| options: commandOptionsSchema.parse({ | |
| id: 'c391b57d-5783-4c53-9236-cefb5c6ef323', | |
| UsageGuidelinesUrl: 'https://contoso.sharepoint.com/sites/compliance', | |
| ClassificationList: 'HBI, MBI, LBI, GDPR', | |
| DefaultClassification: 'MBI' | |
| }) | |
| }); |
Same for other tests in this file.
| throw 'Invalid request'; | ||
| }); | ||
|
|
||
| await command.action(logger, { options: { id: '28beab62-7540-4db1-a23f-29a6018a3848', force: true } }); |
There was a problem hiding this comment.
I would suggest to use the commandOptionsSchema.parse.
| await command.action(logger, { options: commandOptionsSchema.parse({ id: '28beab62-7540-4db1-a23f-29a6018a3848', force: true }) }); |
Same for other tests in this file.
| throw 'Invalid request'; | ||
| }); | ||
|
|
||
| await command.action(logger, { options: { id: '1caf7dcd-7e83-4c3a-94f7-932a1299c844' } }); |
There was a problem hiding this comment.
I would suggest to use the commandOptionsSchema.parse.
| await command.action(logger, { options: commandOptionsSchema.parse({ id: '1caf7dcd-7e83-4c3a-94f7-932a1299c844' }) }); |
Same for other tests in this file.
| throw 'Invalid Request'; | ||
| }); | ||
|
|
||
| await command.action(logger, { options: { templateId: '62375ab9-6b52-47ed-826b-58e47e0e304b' } }); |
There was a problem hiding this comment.
I would suggest to use the commandOptionsSchema.parse.
| await command.action(logger, { options: commandOptionsSchema.parse({ templateId: '62375ab9-6b52-47ed-826b-58e47e0e304b' }) }); |
Same for other tests in this file.
Summary
Migrates all 7
entra groupsettingandentra groupsettingtemplatecommands to use Zod schemas for option validation, replacing the legacy#initOptions(),#initValidators(),#initTelemetry(), and#initOptionSets()patterns.Closes #7297
Commands migrated
entra groupsetting addlooseObjectentra groupsetting getstrictObjectentra groupsetting liststrictObjectentra groupsetting removestrictObjectentra groupsetting setlooseObjectentra groupsettingtemplate getstrictObjectgetRefinedSchemaentra groupsettingtemplate liststrictObjectChanges per command
interface Options extends GlobalOptionswith Zod schema definitionsz.uuid().alias()for short option namesget schema()gettergetRefinedSchema()for option set validation (groupsettingtemplate get)#initOptions(),#initValidators(),#initTelemetry(),#initOptionSets()Test changes
command.validate()tocommandOptionsSchema.safeParse()supports specifyingtests that checkedcommand.optionsarraysettingsNamesstubs no longer needed for option set validation