Skip to content

Commit

Permalink
Fixes failing tests for 'site admin remove' command
Browse files Browse the repository at this point in the history
  • Loading branch information
milanholemans committed Sep 21, 2024
1 parent 780c72a commit d9b8f73
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
56 changes: 28 additions & 28 deletions src/m365/spo/commands/site/site-admin-remove.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe(commands.SITE_ADMIN_REMOVE, () => {
}

if (opts.url === `${adminUrl}/_api/SPO.Tenant/sites('${siteId}')?$select=OwnerLoginName`) {
return JSON.stringify({ OwnerLoginName: primaryAdminLoginName });
return { OwnerLoginName: primaryAdminLoginName };
}

if (opts.url === `https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com:/sites/site?$select=id`) {
Expand All @@ -156,9 +156,9 @@ describe(commands.SITE_ADMIN_REMOVE, () => {

const postStub = sinon.stub(request, 'post').callsFake(async opts => {
if (opts.url === `${adminUrl}/_api/SPO.Tenant/GetSiteAdministrators?siteId='${siteId}'`) {
return JSON.stringify({
return {
value: listOfAdminsFromAdminSource
});
};
}

if (opts.url === `${adminUrl}/_api/SPOInternalUseOnly.Tenant/SetSiteSecondaryAdministrators`) {
Expand Down Expand Up @@ -195,7 +195,7 @@ describe(commands.SITE_ADMIN_REMOVE, () => {
}

if (opts.url === `${adminUrl}/_api/SPO.Tenant/sites('${siteId}')?$select=OwnerLoginName`) {
return JSON.stringify({ OwnerLoginName: primaryAdminLoginName });
return { OwnerLoginName: primaryAdminLoginName };
}


Expand All @@ -208,7 +208,7 @@ describe(commands.SITE_ADMIN_REMOVE, () => {

const postStub = sinon.stub(request, 'post').callsFake(async opts => {
if (opts.url === `${adminUrl}/_api/SPO.Tenant/GetSiteAdministrators?siteId='${siteId}'`) {
return JSON.stringify({
return {
value: [
...listOfAdminsFromAdminSource,
{
Expand All @@ -218,7 +218,7 @@ describe(commands.SITE_ADMIN_REMOVE, () => {
userPrincipalName: ''
}
]
});
};
}

if (opts.url === `${adminUrl}/_api/SPOInternalUseOnly.Tenant/SetSiteSecondaryAdministrators`) {
Expand Down Expand Up @@ -255,7 +255,7 @@ describe(commands.SITE_ADMIN_REMOVE, () => {
}

if (opts.url === `${adminUrl}/_api/SPO.Tenant/sites('${siteId}')?$select=OwnerLoginName`) {
return JSON.stringify({ OwnerLoginName: primaryAdminLoginName });
return { OwnerLoginName: primaryAdminLoginName };
}

if (opts.url === `https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com:/sites/site?$select=id`) {
Expand All @@ -267,9 +267,9 @@ describe(commands.SITE_ADMIN_REMOVE, () => {

const postStub = sinon.stub(request, 'post').callsFake(async opts => {
if (opts.url === `${adminUrl}/_api/SPO.Tenant/GetSiteAdministrators?siteId='${siteId}'`) {
return JSON.stringify({
return {
value: listOfAdminsFromAdminSource
});
};
}

if (opts.url === `${adminUrl}/_api/SPOInternalUseOnly.Tenant/SetSiteSecondaryAdministrators`) {
Expand Down Expand Up @@ -297,7 +297,7 @@ describe(commands.SITE_ADMIN_REMOVE, () => {
}

if (opts.url === `${adminUrl}/_api/SPO.Tenant/sites('${siteId}')?$select=OwnerLoginName`) {
return JSON.stringify({ OwnerLoginName: primaryAdminLoginName });
return { OwnerLoginName: primaryAdminLoginName };
}

if (opts.url === `https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com:/sites/site?$select=id`) {
Expand All @@ -309,9 +309,9 @@ describe(commands.SITE_ADMIN_REMOVE, () => {

sinon.stub(request, 'post').callsFake(async opts => {
if (opts.url === `${adminUrl}/_api/SPO.Tenant/GetSiteAdministrators?siteId='${siteId}'`) {
return JSON.stringify({
return {
value: listOfAdminsFromAdminSource
});
};
}

if (opts.url === `${adminUrl}/_api/SPOInternalUseOnly.Tenant/SetSiteSecondaryAdministrators` && opts.data.secondaryAdministratorsFieldsData) {
Expand All @@ -331,7 +331,7 @@ describe(commands.SITE_ADMIN_REMOVE, () => {
}

if (opts.url === `${adminUrl}/_api/SPO.Tenant/sites('${siteId}')?$select=OwnerLoginName`) {
return JSON.stringify({ OwnerLoginName: primaryAdminLoginName });
return { OwnerLoginName: primaryAdminLoginName };
}

if (opts.url === `https://graph.microsoft.com/v1.0/users('user1loginName%40email.com')`) {
Expand All @@ -347,9 +347,9 @@ describe(commands.SITE_ADMIN_REMOVE, () => {

const postStub = sinon.stub(request, 'post').callsFake(async opts => {
if (opts.url === `${adminUrl}/_api/SPO.Tenant/GetSiteAdministrators?siteId='${siteId}'`) {
return JSON.stringify({
return {
value: listOfAdminsFromAdminSource
});
};
}

if (opts.url === `${adminUrl}/_api/SPOInternalUseOnly.Tenant/SetSiteSecondaryAdministrators`) {
Expand Down Expand Up @@ -377,7 +377,7 @@ describe(commands.SITE_ADMIN_REMOVE, () => {
}

if (opts.url === `${adminUrl}/_api/SPO.Tenant/sites('${siteId}')?$select=OwnerLoginName`) {
return JSON.stringify({ OwnerLoginName: primaryAdminLoginName });
return { OwnerLoginName: primaryAdminLoginName };
}

if (opts.url === `https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com:/sites/site?$select=id`) {
Expand All @@ -397,7 +397,7 @@ describe(commands.SITE_ADMIN_REMOVE, () => {
}

if (opts.url === `${adminUrl}/_api/SPO.Tenant/sites('${siteId}')?$select=OwnerLoginName`) {
return JSON.stringify({ OwnerLoginName: primaryAdminLoginName });
return { OwnerLoginName: primaryAdminLoginName };
}

if (opts.url === `https://graph.microsoft.com/v1.0/users('userPrimaryAdminEmail%40email.com')`) {
Expand All @@ -422,7 +422,7 @@ describe(commands.SITE_ADMIN_REMOVE, () => {
}

if (opts.url === `${adminUrl}/_api/SPO.Tenant/sites('${siteId}')?$select=OwnerLoginName`) {
return JSON.stringify({ OwnerLoginName: primaryAdminLoginName });
return { OwnerLoginName: primaryAdminLoginName };
}

if (opts.url === `https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com:/sites/site?$select=id`) {
Expand All @@ -434,7 +434,7 @@ describe(commands.SITE_ADMIN_REMOVE, () => {

const postStub = sinon.stub(request, 'post').callsFake(async opts => {
if (opts.url === `${adminUrl}/_api/SPO.Tenant/GetSiteAdministrators?siteId='${siteId}'`) {
return JSON.stringify({
return {
value: [
...listOfAdminsFromAdminSource,
{
Expand All @@ -444,7 +444,7 @@ describe(commands.SITE_ADMIN_REMOVE, () => {
userPrincipalName: ''
}
]
});
};
}

if (opts.url === `${adminUrl}/_api/SPOInternalUseOnly.Tenant/SetSiteSecondaryAdministrators`) {
Expand Down Expand Up @@ -473,7 +473,7 @@ describe(commands.SITE_ADMIN_REMOVE, () => {
}

if (opts.url === `${adminUrl}/_api/SPO.Tenant/sites('${siteId}')?$select=OwnerLoginName`) {
return JSON.stringify({ OwnerLoginName: primaryAdminLoginName });
return { OwnerLoginName: primaryAdminLoginName };
}

if (opts.url === `https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com:/sites/site?$select=id`) {
Expand All @@ -485,7 +485,7 @@ describe(commands.SITE_ADMIN_REMOVE, () => {

const postStub = sinon.stub(request, 'post').callsFake(async opts => {
if (opts.url === `${adminUrl}/_api/SPO.Tenant/GetSiteAdministrators?siteId='${siteId}'`) {
return JSON.stringify({
return {
value: [
...listOfAdminsFromAdminSource,
{
Expand All @@ -495,7 +495,7 @@ describe(commands.SITE_ADMIN_REMOVE, () => {
userPrincipalName: ''
}
]
});
};
}

if (opts.url === `${adminUrl}/_api/SPOInternalUseOnly.Tenant/SetSiteSecondaryAdministrators`) {
Expand Down Expand Up @@ -524,7 +524,7 @@ describe(commands.SITE_ADMIN_REMOVE, () => {
}

if (opts.url === `${adminUrl}/_api/SPO.Tenant/sites('${siteId}')?$select=OwnerLoginName`) {
return JSON.stringify({ OwnerLoginName: primaryAdminLoginName });
return { OwnerLoginName: primaryAdminLoginName };
}

if (opts.url === `https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com:/sites/site?$select=id`) {
Expand All @@ -536,7 +536,7 @@ describe(commands.SITE_ADMIN_REMOVE, () => {

const postStub = sinon.stub(request, 'post').callsFake(async opts => {
if (opts.url === `${adminUrl}/_api/SPO.Tenant/GetSiteAdministrators?siteId='${siteId}'`) {
return JSON.stringify({
return {
value: [
...listOfAdminsFromAdminSource,
{
Expand All @@ -546,7 +546,7 @@ describe(commands.SITE_ADMIN_REMOVE, () => {
userPrincipalName: ''
}
]
});
};
}

if (opts.url === `${adminUrl}/_api/SPOInternalUseOnly.Tenant/SetSiteSecondaryAdministrators`) {
Expand Down Expand Up @@ -712,9 +712,9 @@ describe(commands.SITE_ADMIN_REMOVE, () => {
}

if (opts.url === `${adminUrl}/_api/SPO.Tenant/GetSiteAdministrators?siteId='${incorrectSiteId}'`) {
return JSON.stringify({
return {
value: listOfAdminsFromAdminSource
});
};
}

if (opts.url === `https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com:/sites/site?$select=id`) {
Expand Down
11 changes: 6 additions & 5 deletions src/m365/spo/commands/site/site-admin-remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ class SpoSiteAdminRemoveCommand extends SpoCommand {
headers: {
accept: 'application/json;odata=nometadata',
'content-type': 'application/json;charset=utf-8'
}
},
responseType: 'json'
};

const response: string = await request.post<string>(requestOptions);
const responseContent: AdminResult = JSON.parse(response);
return responseContent.value;
const response = await request.post<AdminResult>(requestOptions);
return response.value;
}

private async getCorrectLoginName(options: Options): Promise<string> {
Expand Down Expand Up @@ -216,7 +216,8 @@ class SpoSiteAdminRemoveCommand extends SpoCommand {
secondaryAdministratorLoginNames:
admins.map(u => u.loginName)
}
}
},
responseType: 'json'
};

await request.post<string>(requestOptions);
Expand Down

0 comments on commit d9b8f73

Please sign in to comment.