Skip to content

Migrate entra groupsetting and groupsettingtemplate commands to Zod#7366

Draft
waldekmastykarz wants to merge 2 commits into
pnp:mainfrom
waldekmastykarz:waldekmastykarz/migrate-entra-groupsetting-zod
Draft

Migrate entra groupsetting and groupsettingtemplate commands to Zod#7366
waldekmastykarz wants to merge 2 commits into
pnp:mainfrom
waldekmastykarz:waldekmastykarz/migrate-entra-groupsetting-zod

Conversation

@waldekmastykarz
Copy link
Copy Markdown
Member

Summary

Migrates all 7 entra groupsetting and entra groupsettingtemplate commands to use Zod schemas for option validation, replacing the legacy #initOptions(), #initValidators(), #initTelemetry(), and #initOptionSets() patterns.

Closes #7297

Commands migrated

Command Schema type Notes
entra groupsetting add looseObject Supports unknown options
entra groupsetting get strictObject
entra groupsetting list strictObject No custom options
entra groupsetting remove strictObject
entra groupsetting set looseObject Supports unknown options
entra groupsettingtemplate get strictObject Option set via getRefinedSchema
entra groupsettingtemplate list strictObject No custom options

Changes per command

  • Replaced interface Options extends GlobalOptions with Zod schema definitions
  • Replaced manual GUID validation with z.uuid()
  • Added .alias() for short option names
  • Implemented get schema() getter
  • Used getRefinedSchema() for option set validation (groupsettingtemplate get)
  • Removed constructor-based #initOptions(), #initValidators(), #initTelemetry(), #initOptionSets()

Test changes

  • Validation tests updated from command.validate() to commandOptionsSchema.safeParse()
  • Removed legacy supports specifying tests that checked command.options array
  • Removed settingsNames stubs no longer needed for option set validation

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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 + optional getRefinedSchema) 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 than command.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().

Comment thread src/m365/entra/commands/groupsetting/groupsetting-set.spec.ts Outdated
Comment thread src/m365/entra/commands/groupsetting/groupsetting-set.ts Outdated
Comment thread src/m365/entra/commands/groupsetting/groupsetting-add.spec.ts Outdated
Comment on lines +9 to +12
const options = z.looseObject({
...globalOptionsZod.shape,
templateId: z.uuid().alias('i')
});
@MartinM85 MartinM85 marked this pull request as draft June 3, 2026 08:26
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>
@waldekmastykarz waldekmastykarz marked this pull request as ready for review June 5, 2026 11:13
@MartinM85 MartinM85 self-assigned this Jun 6, 2026
Copy link
Copy Markdown
Contributor

@MartinM85 MartinM85 left a comment

Choose a reason for hiding this comment

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

Hi @waldekmastykarz , I have a couple of comments, great job otherwise. 👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would suggest to update .spec.ts. file and add tests for 'no options' and 'unknown options'.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would suggest to use the commandOptionsSchema.parse

Suggested change
await assert.rejects(command.action(logger, { options: commandOptionsSchema.parse({ displayName: 'Invalid' })}),

Same for other tests in this file.

Comment on lines 146 to 153
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'
}
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would suggest to use the commandOptionsSchema.parse to test that unknown options can be passed.

Suggested change
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 } });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would suggest to use the commandOptionsSchema.parse.

Suggested change
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' } });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would suggest to use the commandOptionsSchema.parse.

Suggested change
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' } });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would suggest to use the commandOptionsSchema.parse.

Suggested change
await command.action(logger, { options: commandOptionsSchema.parse({ templateId: '62375ab9-6b52-47ed-826b-58e47e0e304b' }) });

Same for other tests in this file.

@MartinM85 MartinM85 marked this pull request as draft June 6, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate entra groupsetting and groupsettingtemplate commands to Zod

3 participants