From 1207adc60021d3ab9451865a21b73aabf79aaf39 Mon Sep 17 00:00:00 2001 From: Allan Hvam Date: Thu, 25 Apr 2024 21:14:41 +0200 Subject: [PATCH] feat: added some lists.getById handlers, upgrade @pnp/sp in tests --- package-lock.json | 137 ++++++++++++++++++++-------------------- package.json | 8 +-- src/handlers.ts | 10 +++ src/tests/lists.test.ts | 17 +++-- src/tests/web.test.ts | 4 +- 5 files changed, 97 insertions(+), 79 deletions(-) diff --git a/package-lock.json b/package-lock.json index 624b019..307fe82 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,22 +1,22 @@ { "name": "msw-sp", - "version": "1.1.0", + "version": "1.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "msw-sp", - "version": "1.1.0", + "version": "1.2.0", "license": "ISC", "dependencies": { "eh-odata-parser": "^1.4.3", "msw": "^2.0.5" }, "devDependencies": { - "@pnp/sp": "^3.19.0", + "@pnp/sp": "^4.0.1", "@types/node": "^18.17.0", - "@typescript-eslint/eslint-plugin": "^7.7.0", - "@typescript-eslint/parser": "^7.7.0", + "@typescript-eslint/eslint-plugin": "^7.7.1", + "@typescript-eslint/parser": "^7.7.1", "eslint": "^8.53.0", "eslint-plugin-require-extensions": "^0.1.3", "typescript": "^5.2.2" @@ -411,15 +411,15 @@ } }, "node_modules/@pnp/core": { - "version": "3.24.0", - "resolved": "https://registry.npmjs.org/@pnp/core/-/core-3.24.0.tgz", - "integrity": "sha512-P8xVxxLrHzfl1l0qZP81p5XNVzhfSc7CVKBCJnc1UKKi24NIYeJXLcvP+m/aZFpjr2HprhznAGhQ6F4XJ/dNAw==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@pnp/core/-/core-4.0.1.tgz", + "integrity": "sha512-Z+FiQDR1BPLuzoU8IpL3rmpiPa4+kvu997uVDfTmOhXv7YWlCOgTQa0scJoqGDZZCkTUwl07KGZ8A6nT76gA5w==", "dev": true, "dependencies": { - "tslib": "2.4.1" + "tslib": "2.6.2" }, "engines": { - "node": ">=14.15.1" + "node": ">=18.12.0" }, "funding": { "type": "individual", @@ -427,16 +427,16 @@ } }, "node_modules/@pnp/queryable": { - "version": "3.24.0", - "resolved": "https://registry.npmjs.org/@pnp/queryable/-/queryable-3.24.0.tgz", - "integrity": "sha512-X9COhnGSW8WljRKY8S3cHHjYTalkUJs2Ok2wIQzlx9OK1+QjMvnFr7IBItsJMiCVVqmXoRWg1c8+Et8dXyNB3Q==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@pnp/queryable/-/queryable-4.0.1.tgz", + "integrity": "sha512-n/oq5jjjCf+IAreEUsFUQ2EjXuAjSBUxO5usQVi3tjStUca50DPDIxzJTiPTGcqnpwTiEqJiyqEmKIbZfzWSqg==", "dev": true, "dependencies": { - "@pnp/core": "3.24.0", - "tslib": "2.4.1" + "@pnp/core": "4.0.1", + "tslib": "2.6.2" }, "engines": { - "node": ">=14.15.1" + "node": ">=18.12.0" }, "funding": { "type": "individual", @@ -444,18 +444,17 @@ } }, "node_modules/@pnp/sp": { - "version": "3.24.0", - "resolved": "https://registry.npmjs.org/@pnp/sp/-/sp-3.24.0.tgz", - "integrity": "sha512-/GcbF/5NNhw903gceaSaP2YDB0UboJnbTGDtjGXIFZer2bzPl8pt3yOEP/VCl3UhmbHoEut7+grSp/D2fWnkWQ==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@pnp/sp/-/sp-4.0.1.tgz", + "integrity": "sha512-EpDfxgKoHESi+04pJKwfxSxNYPRnYfsXKEK3uDNrwf1TObM/oWXzoumaXD8A8h4rW7DlI0vIUQiXdsJT7sQUwQ==", "dev": true, - "hasInstallScript": true, "dependencies": { - "@pnp/core": "3.24.0", - "@pnp/queryable": "3.24.0", - "tslib": "2.4.1" + "@pnp/core": "4.0.1", + "@pnp/queryable": "4.0.1", + "tslib": "2.6.2" }, "engines": { - "node": ">=14.15.1" + "node": ">=18.12.0" }, "funding": { "type": "individual", @@ -506,16 +505,16 @@ "integrity": "sha512-ltIpx+kM7g/MLRZfkbL7EsCEjfzCcScLpkg37eXEtx5kmrAKBkTJwd1GIAjDSL8wTpM6Hzn5YO4pSb91BEwu1g==" }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.7.0.tgz", - "integrity": "sha512-GJWR0YnfrKnsRoluVO3PRb9r5aMZriiMMM/RHj5nnTrBy1/wIgk76XCtCKcnXGjpZQJQRFtGV9/0JJ6n30uwpQ==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.7.1.tgz", + "integrity": "sha512-KwfdWXJBOviaBVhxO3p5TJiLpNuh2iyXyjmWN0f1nU87pwyvfS0EmjC6ukQVYVFJd/K1+0NWGPDXiyEyQorn0Q==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "7.7.0", - "@typescript-eslint/type-utils": "7.7.0", - "@typescript-eslint/utils": "7.7.0", - "@typescript-eslint/visitor-keys": "7.7.0", + "@typescript-eslint/scope-manager": "7.7.1", + "@typescript-eslint/type-utils": "7.7.1", + "@typescript-eslint/utils": "7.7.1", + "@typescript-eslint/visitor-keys": "7.7.1", "debug": "^4.3.4", "graphemer": "^1.4.0", "ignore": "^5.3.1", @@ -541,15 +540,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.7.0.tgz", - "integrity": "sha512-fNcDm3wSwVM8QYL4HKVBggdIPAy9Q41vcvC/GtDobw3c4ndVT3K6cqudUmjHPw8EAp4ufax0o58/xvWaP2FmTg==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.7.1.tgz", + "integrity": "sha512-vmPzBOOtz48F6JAGVS/kZYk4EkXao6iGrD838sp1w3NQQC0W8ry/q641KU4PrG7AKNAf56NOcR8GOpH8l9FPCw==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "7.7.0", - "@typescript-eslint/types": "7.7.0", - "@typescript-eslint/typescript-estree": "7.7.0", - "@typescript-eslint/visitor-keys": "7.7.0", + "@typescript-eslint/scope-manager": "7.7.1", + "@typescript-eslint/types": "7.7.1", + "@typescript-eslint/typescript-estree": "7.7.1", + "@typescript-eslint/visitor-keys": "7.7.1", "debug": "^4.3.4" }, "engines": { @@ -569,13 +568,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.7.0.tgz", - "integrity": "sha512-/8INDn0YLInbe9Wt7dK4cXLDYp0fNHP5xKLHvZl3mOT5X17rK/YShXaiNmorl+/U4VKCVIjJnx4Ri5b0y+HClw==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.7.1.tgz", + "integrity": "sha512-PytBif2SF+9SpEUKynYn5g1RHFddJUcyynGpztX3l/ik7KmZEv19WCMhUBkHXPU9es/VWGD3/zg3wg90+Dh2rA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.7.0", - "@typescript-eslint/visitor-keys": "7.7.0" + "@typescript-eslint/types": "7.7.1", + "@typescript-eslint/visitor-keys": "7.7.1" }, "engines": { "node": "^18.18.0 || >=20.0.0" @@ -586,13 +585,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.7.0.tgz", - "integrity": "sha512-bOp3ejoRYrhAlnT/bozNQi3nio9tIgv3U5C0mVDdZC7cpcQEDZXvq8inrHYghLVwuNABRqrMW5tzAv88Vy77Sg==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.7.1.tgz", + "integrity": "sha512-ZksJLW3WF7o75zaBPScdW1Gbkwhd/lyeXGf1kQCxJaOeITscoSl0MjynVvCzuV5boUz/3fOI06Lz8La55mu29Q==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "7.7.0", - "@typescript-eslint/utils": "7.7.0", + "@typescript-eslint/typescript-estree": "7.7.1", + "@typescript-eslint/utils": "7.7.1", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -613,9 +612,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.7.0.tgz", - "integrity": "sha512-G01YPZ1Bd2hn+KPpIbrAhEWOn5lQBrjxkzHkWvP6NucMXFtfXoevK82hzQdpfuQYuhkvFDeQYbzXCjR1z9Z03w==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.7.1.tgz", + "integrity": "sha512-AmPmnGW1ZLTpWa+/2omPrPfR7BcbUU4oha5VIbSbS1a1Tv966bklvLNXxp3mrbc+P2j4MNOTfDffNsk4o0c6/w==", "dev": true, "engines": { "node": "^18.18.0 || >=20.0.0" @@ -626,13 +625,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.7.0.tgz", - "integrity": "sha512-8p71HQPE6CbxIBy2kWHqM1KGrC07pk6RJn40n0DSc6bMOBBREZxSDJ+BmRzc8B5OdaMh1ty3mkuWRg4sCFiDQQ==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.7.1.tgz", + "integrity": "sha512-CXe0JHCXru8Fa36dteXqmH2YxngKJjkQLjxzoj6LYwzZ7qZvgsLSc+eqItCrqIop8Vl2UKoAi0StVWu97FQZIQ==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.7.0", - "@typescript-eslint/visitor-keys": "7.7.0", + "@typescript-eslint/types": "7.7.1", + "@typescript-eslint/visitor-keys": "7.7.1", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -654,17 +653,17 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.7.0.tgz", - "integrity": "sha512-LKGAXMPQs8U/zMRFXDZOzmMKgFv3COlxUQ+2NMPhbqgVm6R1w+nU1i4836Pmxu9jZAuIeyySNrN/6Rc657ggig==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.7.1.tgz", + "integrity": "sha512-QUvBxPEaBXf41ZBbaidKICgVL8Hin0p6prQDu6bbetWo39BKbWJxRsErOzMNT1rXvTll+J7ChrbmMCXM9rsvOQ==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "@types/json-schema": "^7.0.15", "@types/semver": "^7.5.8", - "@typescript-eslint/scope-manager": "7.7.0", - "@typescript-eslint/types": "7.7.0", - "@typescript-eslint/typescript-estree": "7.7.0", + "@typescript-eslint/scope-manager": "7.7.1", + "@typescript-eslint/types": "7.7.1", + "@typescript-eslint/typescript-estree": "7.7.1", "semver": "^7.6.0" }, "engines": { @@ -679,12 +678,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.7.0.tgz", - "integrity": "sha512-h0WHOj8MhdhY8YWkzIF30R379y0NqyOHExI9N9KCzvmu05EgG4FumeYa3ccfKUSphyWkWQE1ybVrgz/Pbam6YA==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.7.1.tgz", + "integrity": "sha512-gBL3Eq25uADw1LQ9kVpf3hRM+DWzs0uZknHYK3hq4jcTPqVCClHGDnB6UUUV2SFeBeA4KWHWbbLqmbGcZ4FYbw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.7.0", + "@typescript-eslint/types": "7.7.1", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -2269,9 +2268,9 @@ } }, "node_modules/tslib": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz", - "integrity": "sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==", + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", "dev": true }, "node_modules/type-check": { diff --git a/package.json b/package.json index 75e2d41..32210d4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "msw-sp", - "version": "1.1.0", + "version": "1.2.0", "description": "MSW handlers for mocking SharePoint REST api.", "main": "lib/index.js", "engines": { @@ -20,10 +20,10 @@ "msw": "^2.0.5" }, "devDependencies": { - "@pnp/sp": "^3.19.0", + "@pnp/sp": "^4.0.1", "@types/node": "^18.17.0", - "@typescript-eslint/eslint-plugin": "^7.7.0", - "@typescript-eslint/parser": "^7.7.0", + "@typescript-eslint/eslint-plugin": "^7.7.1", + "@typescript-eslint/parser": "^7.7.1", "eslint": "^8.53.0", "eslint-plugin-require-extensions": "^0.1.3", "typescript": "^5.2.2" diff --git a/src/handlers.ts b/src/handlers.ts index ee86855..fa21f04 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -135,6 +135,11 @@ export const handlers = (tenant: Tenant) => { const title = info.params.title.toString(); return response(await tenantMock.sites.getSite(site).rootWeb.lists.getByTitle(title).get(), info); }), + ...get(`/_api/web/lists\\(':listId'\\)`, async (info) => { + const site = info.params.site?.toString() || "/"; + const listId = info.params.listId.toString(); + return response(await tenantMock.sites.getSite(site).rootWeb.lists.getById(listId).get(), info); + }), ...get("/_api/web/lists/getByTitle\\(':title'\\)/fields", async (info) => { const site = info.params.site?.toString() || "/"; const title = info.params.title.toString(); @@ -160,6 +165,11 @@ export const handlers = (tenant: Tenant) => { const title = info.params.title.toString(); return response(await tenantMock.sites.getSite(site).rootWeb.lists.getByTitle(title).items.get(), info); }), + ...get("/_api/web/lists\\(':listId'\\)/items", async (info) => { + const site = info.params.site?.toString() || "/"; + const listId = info.params.listId.toString(); + return response(await tenantMock.sites.getSite(site).rootWeb.lists.getById(listId).items.get(), info); + }), ...get("/_api/web/lists/getByTitle\\(':title'\\)/forms", async (info) => { const site = info.params.site?.toString() || "/"; const title = info.params.title.toString(); diff --git a/src/tests/lists.test.ts b/src/tests/lists.test.ts index 267b665..e1142bf 100644 --- a/src/tests/lists.test.ts +++ b/src/tests/lists.test.ts @@ -22,6 +22,7 @@ void describe("lists", async () => { lists: [ { title: "Empty", + id: "e3df5114-acc5-4901-8eb8-c55200d963d3", baseTemplate: 100, url: "Lists/Empty", items: [], @@ -90,10 +91,18 @@ void describe("lists", async () => { await test("empty", async () => { const sp = spfi().using(SPFx(getContext("/sites/empty"))); - const list = await sp.web.lists.getByTitle("Empty")(); - assert.equal(list.Title, "Empty"); - const items = await sp.web.lists.getByTitle("Empty").items(); - assert.equal(items.length, 0); + const emptyLists = [ + sp.web.lists.getByTitle("Empty"), + sp.web.lists.getById("e3df5114-acc5-4901-8eb8-c55200d963d3"), + ]; + + for (const emptyList of emptyLists) { + const emptyListInfo = await emptyList(); + assert.equal(emptyListInfo.Title, "Empty"); + + const items = await emptyList.items(); + assert.equal(items.length, 0); + } }); await test("events", async () => { diff --git a/src/tests/web.test.ts b/src/tests/web.test.ts index 00d1c6a..87f3517 100644 --- a/src/tests/web.test.ts +++ b/src/tests/web.test.ts @@ -63,7 +63,7 @@ void describe("web", async () => { const result = await sp.web.ensureUser("user@tenant.onmicrosoft.com"); - assert.equal(result.data.Id, 1); - assert.equal(result.data.Title, "User"); + assert.equal(result.Id, 1); + assert.equal(result.Title, "User"); }); }); \ No newline at end of file