Skip to content

Commit

Permalink
adding tests for graph query params
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-rodgers committed Apr 4, 2024
1 parent 2435101 commit a74e071
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
9 changes: 0 additions & 9 deletions packages/graph/graphqueryable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,6 @@ export class _GraphCollection<GetType = any[]> extends _GraphQueryable<GetType>
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<number> {
// 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());
Expand Down
44 changes: 44 additions & 0 deletions test/graph/query-params.ts
Original file line number Diff line number Diff line change
@@ -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;
}));
});
2 changes: 1 addition & 1 deletion test/mocha-root-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit a74e071

Please sign in to comment.