From a74e0713fd0e650661bb23fc1b4c57937c6d040b Mon Sep 17 00:00:00 2001 From: Patrick Rodgers Date: Thu, 4 Apr 2024 10:19:12 -0400 Subject: [PATCH] adding tests for graph query params --- packages/graph/graphqueryable.ts | 9 ------- test/graph/query-params.ts | 44 ++++++++++++++++++++++++++++++++ test/mocha-root-hooks.ts | 2 +- 3 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 test/graph/query-params.ts diff --git a/packages/graph/graphqueryable.ts b/packages/graph/graphqueryable.ts index f2d226913..324640e83 100644 --- a/packages/graph/graphqueryable.ts +++ b/packages/graph/graphqueryable.ts @@ -165,15 +165,6 @@ export class _GraphCollection extends _GraphQueryable return this; } - /** - * Retrieves the total count of matching resources - * If the resource doesn't support count, this value will always be zero - */ - public async count(): Promise { - // TODO::do we want to do this, or just attach count to the collections that support it? we could use a decorator for countable on the few collections that support count. - return -1; - } - public [Symbol.asyncIterator]() { const q = GraphCollection(this).using(Paged(), ConsistencyLevel()); diff --git a/test/graph/query-params.ts b/test/graph/query-params.ts new file mode 100644 index 000000000..1c2b0e824 --- /dev/null +++ b/test/graph/query-params.ts @@ -0,0 +1,44 @@ +import { expect } from "chai"; +import { pnpTest } from "../pnp-test.js"; +import "@pnp/graph/groups"; +import "@pnp/graph/users"; +import { ConsistencyLevel } from "@pnp/graph/index.js"; + +describe("Graph Query Params", function () { + + before(async function () { + + if ((!this.pnp.settings.enableWebTests)) { + this.skip(); + } + }); + + it("groupTypes/any(c:c eq 'Unified')", pnpTest("158a6aa2-3d0e-4435-88e0-11a146db133e", async function () { + + return expect(this.pnp.graph.groups.filter("groupTypes/any(c:c eq 'Unified')")()).to.eventually.be.fulfilled; + })); + + it("NOT groupTypes/any(c:c eq 'Unified')", pnpTest("b26626fc-d5ee-4a46-afc1-1ae210d1a739", async function () { + + const query = this.pnp.graph.groups.using(ConsistencyLevel()).filter("NOT groupTypes/any(c:c eq 'Unified')"); + query.query.set("$count", "true"); + + return expect(query()).to.eventually.be.fulfilled; + })); + + it("companyName ne null and NOT(companyName eq 'Microsoft')", pnpTest("bbca7a4d-6fce-4c1b-904f-e295919ea25e", async function () { + + const query = this.pnp.graph.users.using(ConsistencyLevel()).filter("companyName ne null and NOT(companyName eq 'Microsoft')"); + query.query.set("$count", "true"); + + return expect(query()).to.eventually.be.fulfilled; + })); + + it("not(assignedLicenses/$count eq 0)", pnpTest("1b25afc7-771e-43be-a549-a6b2c326072b", async function () { + + const query = this.pnp.graph.users.using(ConsistencyLevel()).filter("not(assignedLicenses/$count eq 0)"); + query.query.set("$count", "true"); + + return expect(query()).to.eventually.be.fulfilled; + })); +}); diff --git a/test/mocha-root-hooks.ts b/test/mocha-root-hooks.ts index c7620536a..ba09f8ef4 100644 --- a/test/mocha-root-hooks.ts +++ b/test/mocha-root-hooks.ts @@ -70,7 +70,7 @@ export const mochaHooks = { }, }; - if (this.pnp.args.logging > LogLevel.Off) { + if (this.pnp.args.logging < LogLevel.Off) { // add a listener for logging if we are enabled at any level Logger.subscribe(ConsoleListener()); }