Skip to content

Commit

Permalink
Add validation for integers and guids
Browse files Browse the repository at this point in the history
  • Loading branch information
reshmee011 committed Jan 20, 2025
1 parent b63164c commit 582d528
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/m365/spo/commands/tenant/tenant-homesite-add.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,26 @@ describe(commands.TENANT_HOMESITE_ADD, () => {
assert.notStrictEqual(actual, true);
});

it('correctly handles non-integer order', async () => {
const result = await command.validate({
options: {
url: homeSite,
order: 'invalid-order'
}
}, commandInfo);
assert.strictEqual(result, 'invalid-order is not a positive integer');
});

it('correctly handles invalid GUIDs in audiences', async () => {
const result = await command.validate({
options: {
url: homeSite,
audiences: 'invalid-guid'
}
}, commandInfo);
assert.strictEqual(result, `The following GUIDs are invalid for the option 'ids': invalid-guid.`);
});

it('passes validation with URL', async () => {
const actual = await command.validate({
options: {
Expand Down
8 changes: 8 additions & 0 deletions src/m365/spo/commands/tenant/tenant-homesite-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ class SpoTenantHomeSiteAddCommand extends SpoCommand {
return isValidSharePointUrl;
}

if (args.options.order !== undefined && !validation.isValidPositiveInteger(args.options.order)) {
return `${args.options.order} is not a positive integer`;
}

const isValidGUIDArrayResult = args.options.audiences ? validation.isValidGuidArray(args.options.audiences) : true;
if (isValidGUIDArrayResult !== true) {
return `The following GUIDs are invalid for the option 'ids': ${isValidGUIDArrayResult}.`;
}
return true;
}
);
Expand Down

0 comments on commit 582d528

Please sign in to comment.