Skip to content

Commit 1487b8a

Browse files
authored
Merge pull request #1435 from microsoftgraph/gkoros/merge-changes-from-main-branch
merge changes from main branch to dev
2 parents 4422892 + 1c9704b commit 1487b8a

File tree

5 files changed

+90
-36
lines changed

5 files changed

+90
-36
lines changed

.azure-pipelines/ci-build-production.yml

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ stages:
2020
vmImage: windows-latest
2121
strategy:
2222
matrix:
23+
Node 14:
24+
NODE_VERSION: '14.x'
2325
Node 16:
2426
NODE_VERSION: '16.x'
2527
Node 18:

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ test/development/secrets.ts
3333
testResult.xml
3434
test-results.xml
3535

36-
test-esm/lib/*
36+
test-esm/lib/*

src/tasks/PageIterator.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class PageIterator {
9898
* @private
9999
* Member holding the current position on the collection
100100
*/
101-
private cursor: number
101+
private cursor: number;
102102

103103
/**
104104
* @public
@@ -161,6 +161,7 @@ export class PageIterator {
161161

162162
const response: PageCollection = await graphRequest.get();
163163
this.collection = response.value;
164+
this.cursor = 0;
164165
this.nextLink = response["@odata.nextLink"];
165166
this.deltaLink = response["@odata.deltaLink"];
166167
}

test/common/tasks/PageIterator.ts

+85-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import { assert } from "chai";
99

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

@@ -134,4 +134,88 @@ describe("PageIterator.ts", () => {
134134
assert.isTrue(pageIterator.isComplete());
135135
});
136136
});
137+
describe("Test iteration using ChaosHandler", () => {
138+
it("testing with 5000 results in initial and next page", async () => {
139+
const middleware = new ChaosHandler();
140+
141+
const getPageCollection = () => {
142+
const initialPageResultValues: any[] = [];
143+
for (let i = 0; i < 5000; i++) {
144+
initialPageResultValues[i] = { event: "value" + i };
145+
}
146+
return {
147+
value: initialPageResultValues,
148+
"@odata.nextLink": "nextURL",
149+
additionalContent: "additional content",
150+
};
151+
};
152+
const clientOptions: ClientOptions = {
153+
middleware,
154+
};
155+
156+
const nextPageResultValues: any[] = [];
157+
158+
for (let i = 0; i < 5000; i++) {
159+
nextPageResultValues[i] = { event: "valueNext" + i };
160+
}
161+
const responseBody = { value: nextPageResultValues };
162+
let countNextPageResult = 0;
163+
const callback: PageIteratorCallback = (data) => {
164+
165+
if (data["event"] === "valueNext" + countNextPageResult) {
166+
countNextPageResult++;
167+
}
168+
169+
return true;
170+
};
171+
172+
const middlewareOptions = [new ChaosHandlerOptions(ChaosStrategy.MANUAL, "middleware options for pageIterator", 200, 0, JSON.stringify(responseBody), new Headers({ "Content-Type": "application/json", "content-length": "100" }))];
173+
const requestOptions = { middlewareOptions };
174+
175+
const client = Client.initWithMiddleware(clientOptions);
176+
const pageIterator = new PageIterator(client, getPageCollection(), callback, requestOptions);
177+
await pageIterator.iterate();
178+
179+
assert.equal(countNextPageResult, 5000);
180+
});
181+
182+
it("Evaluate next page result being fetched", async () => {
183+
const middleware = new ChaosHandler();
184+
const getPageCollection = () => {
185+
return {
186+
value: [{ event1: "value1" }, { event2: "value2" }],
187+
"@odata.nextLink": "nextURL",
188+
additionalContent: "additional content",
189+
};
190+
};
191+
const clientOptions: ClientOptions = {
192+
middleware,
193+
};
194+
const responseBody = { value: [{ event3: "value3" }, { event4: "value4" }] };
195+
let counter = 1;
196+
let countNextPageResult = 0;
197+
const callback: PageIteratorCallback = (data) => {
198+
assert.equal(data["event" + counter], "value" + counter);
199+
200+
if (data["event" + counter] === "value3") {
201+
countNextPageResult++;
202+
}
203+
204+
if (data["event" + counter] === "value4") {
205+
countNextPageResult++;
206+
}
207+
counter++;
208+
return true;
209+
};
210+
211+
const middlewareOptions = [new ChaosHandlerOptions(ChaosStrategy.MANUAL, "middleware options for pageIterator", 200, 0, JSON.stringify(responseBody), new Headers({ "Content-Type": "application/json", "content-length": "100" }))];
212+
const requestOptions = { middlewareOptions };
213+
214+
const client = Client.initWithMiddleware(clientOptions);
215+
const pageIterator = new PageIterator(client, getPageCollection(), callback, requestOptions);
216+
await pageIterator.iterate();
217+
218+
assert.equal(countNextPageResult, 2);
219+
});
220+
});
137221
});

test/development/workload/PageIterator.ts

-33
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
import { Event } from "@microsoft/microsoft-graph-types";
99
import { assert } from "chai";
1010

11-
import { Client, ClientOptions } from "../../../src";
12-
import { ChaosHandler } from "../../../src/middleware/ChaosHandler";
13-
import { ChaosHandlerOptions } from "../../../src/middleware/options/ChaosHandlerOptions";
14-
import { ChaosStrategy } from "../../../src/middleware/options/ChaosStrategy";
1511
import { GraphRequestOptions, PageIterator, PageIteratorCallback } from "../../../src/tasks/PageIterator";
1612
import { getClient } from "../test-helper";
1713
const client = getClient();
@@ -91,33 +87,4 @@ describe("PageIterator", () => {
9187
assert.isTrue(pageIterator.isComplete());
9288
}
9389
}).timeout(30 * 1000);
94-
95-
// TODO - Temporariliy commenting this test.
96-
it("setting middleware with pageIterator", async () => {
97-
const middleware = new ChaosHandler();
98-
const getPageCollection = () => {
99-
return {
100-
value: [],
101-
"@odata.nextLink": "nextURL",
102-
additionalContent: "additional content",
103-
};
104-
};
105-
const clientOptions: ClientOptions = {
106-
middleware,
107-
};
108-
const responseBody = { value: [{ event1: "value1" }, { event2: "value2" }] };
109-
let counter = 1;
110-
const callback: PageIteratorCallback = (data) => {
111-
assert.equal(data["event" + counter], "value" + counter);
112-
counter++;
113-
return true;
114-
};
115-
116-
const middlewareOptions = [new ChaosHandlerOptions(ChaosStrategy.MANUAL, "middleware options for pageIterator", 200, 0, JSON.stringify(responseBody), new Headers({ "Content-Type": "application/json", "content-length": "100" }))];
117-
const requestOptions = { middlewareOptions };
118-
119-
const client = Client.initWithMiddleware(clientOptions);
120-
const pageIterator = new PageIterator(client, getPageCollection(), callback, requestOptions);
121-
await pageIterator.iterate();
122-
});
12390
});

0 commit comments

Comments
 (0)