From 1a3ed9a1cf4ca7b0fb9d29c7469ab040d2c149ca Mon Sep 17 00:00:00 2001 From: Beau Cameron Date: Thu, 11 Jan 2024 16:27:00 -0700 Subject: [PATCH] Rootweb fix Current rebasing logic handles for /_api/site and /_api/web only. Any methods attached to rootweb eventually get truncated. This adds a new /_api/site/rootweb regex test to rebase to. --- packages/sp/webs/types.ts | 2 +- test/sp/sites.ts | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/sp/webs/types.ts b/packages/sp/webs/types.ts index 3767b35f1..d4e64cbba 100644 --- a/packages/sp/webs/types.ts +++ b/packages/sp/webs/types.ts @@ -71,7 +71,7 @@ function rebaseWebUrl(candidate: string, path: string | undefined): string { // - test if `candidate` already has an api path // - ensure that we append the correct one as sometimes a web is not defined // by _api/web, in the case of _api/site/rootweb for example - const matches = /(_api[/|\\](site|web))/i.exec(candidate); + const matches = /(_api[/|\\](site\/rootweb|site|web))/i.exec(candidate); if (matches?.length > 0) { // we want just the base url part (before the _api) candidate = extractWebUrl(candidate); diff --git a/test/sp/sites.ts b/test/sp/sites.ts index 03c673502..555e79161 100644 --- a/test/sp/sites.ts +++ b/test/sp/sites.ts @@ -3,12 +3,13 @@ import "@pnp/sp/sites"; import "@pnp/sp/webs"; import "@pnp/sp/lists/web"; import { IDocumentLibraryInformation, IOpenWebByIdResult, ISiteLogoProperties, Site, SiteLogoAspect, SiteLogoType } from "@pnp/sp/sites"; +import "@pnp/sp/site-users"; +import { IWebEnsureUserResult } from "@pnp/sp/site-users"; import { IWeb } from "@pnp/sp/webs"; import { combine, getRandomString, stringIsNullOrEmpty } from "@pnp/core"; import { IContextInfo } from "@pnp/sp/context-info"; import "@pnp/sp/context-info"; - import "@pnp/sp/files"; import { IFiles } from "@pnp/sp/files"; import { readFileSync } from "fs"; @@ -36,6 +37,11 @@ describe("Sites", function () { return expect(rootWeb).to.haveOwnProperty("_url"); }); + it("rootWeb - ensureUser", async function () { + const user: IWebEnsureUserResult = await this.pnp.sp.site.rootWeb.ensureUser(this.pnp.settings.testUser); + return expect(user.data).to.haveOwnProperty("id"); + }); + it("getContextInfo", async function () { const oContext: IContextInfo = await this.pnp.sp.site.getContextInfo(); return expect(oContext).to.haveOwnProperty("SiteFullUrl");