Skip to content

Commit

Permalink
Merge pull request #1435 from microsoftgraph/gkoros/merge-changes-fro…
Browse files Browse the repository at this point in the history
…m-main-branch

merge changes from main branch to dev
  • Loading branch information
koros authored Sep 5, 2023
2 parents 4422892 + 1c9704b commit 1487b8a
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .azure-pipelines/ci-build-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ stages:
vmImage: windows-latest
strategy:
matrix:
Node 14:
NODE_VERSION: '14.x'
Node 16:
NODE_VERSION: '16.x'
Node 18:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ test/development/secrets.ts
testResult.xml
test-results.xml

test-esm/lib/*
test-esm/lib/*
3 changes: 2 additions & 1 deletion src/tasks/PageIterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class PageIterator {
* @private
* Member holding the current position on the collection
*/
private cursor: number
private cursor: number;

/**
* @public
Expand Down Expand Up @@ -161,6 +161,7 @@ export class PageIterator {

const response: PageCollection = await graphRequest.get();
this.collection = response.value;
this.cursor = 0;
this.nextLink = response["@odata.nextLink"];
this.deltaLink = response["@odata.deltaLink"];
}
Expand Down
86 changes: 85 additions & 1 deletion test/common/tasks/PageIterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { assert } from "chai";

import { Client } from "../../../src/index";
import { ChaosHandler, ChaosHandlerOptions, ChaosStrategy, Client, ClientOptions } from "../../../src/index";
import { PageIterator, PageIteratorCallback } from "../../../src/tasks/PageIterator";
import { getClient } from "../../test-helper";

Expand Down Expand Up @@ -134,4 +134,88 @@ describe("PageIterator.ts", () => {
assert.isTrue(pageIterator.isComplete());
});
});
describe("Test iteration using ChaosHandler", () => {
it("testing with 5000 results in initial and next page", async () => {
const middleware = new ChaosHandler();

const getPageCollection = () => {
const initialPageResultValues: any[] = [];
for (let i = 0; i < 5000; i++) {
initialPageResultValues[i] = { event: "value" + i };
}
return {
value: initialPageResultValues,
"@odata.nextLink": "nextURL",
additionalContent: "additional content",
};
};
const clientOptions: ClientOptions = {
middleware,
};

const nextPageResultValues: any[] = [];

for (let i = 0; i < 5000; i++) {
nextPageResultValues[i] = { event: "valueNext" + i };
}
const responseBody = { value: nextPageResultValues };
let countNextPageResult = 0;
const callback: PageIteratorCallback = (data) => {

if (data["event"] === "valueNext" + countNextPageResult) {
countNextPageResult++;
}

return true;
};

const middlewareOptions = [new ChaosHandlerOptions(ChaosStrategy.MANUAL, "middleware options for pageIterator", 200, 0, JSON.stringify(responseBody), new Headers({ "Content-Type": "application/json", "content-length": "100" }))];
const requestOptions = { middlewareOptions };

const client = Client.initWithMiddleware(clientOptions);
const pageIterator = new PageIterator(client, getPageCollection(), callback, requestOptions);
await pageIterator.iterate();

assert.equal(countNextPageResult, 5000);
});

it("Evaluate next page result being fetched", async () => {
const middleware = new ChaosHandler();
const getPageCollection = () => {
return {
value: [{ event1: "value1" }, { event2: "value2" }],
"@odata.nextLink": "nextURL",
additionalContent: "additional content",
};
};
const clientOptions: ClientOptions = {
middleware,
};
const responseBody = { value: [{ event3: "value3" }, { event4: "value4" }] };
let counter = 1;
let countNextPageResult = 0;
const callback: PageIteratorCallback = (data) => {
assert.equal(data["event" + counter], "value" + counter);

if (data["event" + counter] === "value3") {
countNextPageResult++;
}

if (data["event" + counter] === "value4") {
countNextPageResult++;
}
counter++;
return true;
};

const middlewareOptions = [new ChaosHandlerOptions(ChaosStrategy.MANUAL, "middleware options for pageIterator", 200, 0, JSON.stringify(responseBody), new Headers({ "Content-Type": "application/json", "content-length": "100" }))];
const requestOptions = { middlewareOptions };

const client = Client.initWithMiddleware(clientOptions);
const pageIterator = new PageIterator(client, getPageCollection(), callback, requestOptions);
await pageIterator.iterate();

assert.equal(countNextPageResult, 2);
});
});
});
33 changes: 0 additions & 33 deletions test/development/workload/PageIterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
import { Event } from "@microsoft/microsoft-graph-types";
import { assert } from "chai";

import { Client, ClientOptions } from "../../../src";
import { ChaosHandler } from "../../../src/middleware/ChaosHandler";
import { ChaosHandlerOptions } from "../../../src/middleware/options/ChaosHandlerOptions";
import { ChaosStrategy } from "../../../src/middleware/options/ChaosStrategy";
import { GraphRequestOptions, PageIterator, PageIteratorCallback } from "../../../src/tasks/PageIterator";
import { getClient } from "../test-helper";
const client = getClient();
Expand Down Expand Up @@ -91,33 +87,4 @@ describe("PageIterator", () => {
assert.isTrue(pageIterator.isComplete());
}
}).timeout(30 * 1000);

// TODO - Temporariliy commenting this test.
it("setting middleware with pageIterator", async () => {
const middleware = new ChaosHandler();
const getPageCollection = () => {
return {
value: [],
"@odata.nextLink": "nextURL",
additionalContent: "additional content",
};
};
const clientOptions: ClientOptions = {
middleware,
};
const responseBody = { value: [{ event1: "value1" }, { event2: "value2" }] };
let counter = 1;
const callback: PageIteratorCallback = (data) => {
assert.equal(data["event" + counter], "value" + counter);
counter++;
return true;
};

const middlewareOptions = [new ChaosHandlerOptions(ChaosStrategy.MANUAL, "middleware options for pageIterator", 200, 0, JSON.stringify(responseBody), new Headers({ "Content-Type": "application/json", "content-length": "100" }))];
const requestOptions = { middlewareOptions };

const client = Client.initWithMiddleware(clientOptions);
const pageIterator = new PageIterator(client, getPageCollection(), callback, requestOptions);
await pageIterator.iterate();
});
});

0 comments on commit 1487b8a

Please sign in to comment.