-
Notifications
You must be signed in to change notification settings - Fork 231
Enhancement/#311 page iterator request options #318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a36c20a
Adding request options property to PageIterator
nikithauc fe2bf11
Adding tests for page iterator task to test passing along the headers
nikithauc 4ec6b14
using headersinit type for headers
nikithauc 2fa6bce
Specifying parameter definition
nikithauc 20dee50
using constants
nikithauc e9dfb19
Updating function documentation
nikithauc 6c879fc
remove response type, test passing fetchoptions
nikithauc 10e9c91
testing requestOptions set in pageiterator
nikithauc 4bc739f
Merge branch 'dev' into enhancement/#311-PageIterator_RequestOptions
nikithauc 8df324f
Merge branch 'dev' into enhancement/#311-PageIterator_RequestOptions
nikithauc 3cf70e3
typos, optional parameters comments
nikithauc 3cebccf
Merge branch 'enhancement/#311-PageIterator_RequestOptions' of https:…
nikithauc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/** | ||
* ------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. | ||
* See License in the project root for license information. | ||
* ------------------------------------------------------------------------------------------- | ||
*/ | ||
|
||
import { assert } from "chai"; | ||
import { Event } from "microsoft-graph"; | ||
|
||
import { PageIterator, PageIteratorCallback, GraphRequestOptions, PageCollection } from "../../../src/tasks/PageIterator"; | ||
import { getClient } from "../test-helper"; | ||
import { ChaosHandler } from "../../../src/middleware/ChaosHandler"; | ||
import { ChaosHandlerOptions } from "../../../src/middleware/options/ChaosHandlerOptions"; | ||
import { ChaosStrategy } from "../../../src/middleware/options/ChaosStrategy"; | ||
import { Client, ClientOptions } from "../../../src"; | ||
|
||
const client = getClient(); | ||
describe("PageIterator", function() { | ||
const pstHeader = { Prefer: 'outlook.timezone= "pacific standard time"' }; | ||
const utc = "UTC"; | ||
const pst = "Pacific Standard Time"; | ||
const testURL = "/me/events"; | ||
|
||
before(async function() { | ||
this.timeout(20000); | ||
|
||
const response = await client.api(testURL).get(); | ||
const numberOfEvents = 4; | ||
const existingEventsCount = response.value.length; | ||
|
||
if (existingEventsCount >= numberOfEvents) { | ||
return; | ||
} | ||
const eventSubject = '"subject": "Test event '; | ||
const eventTimeZone = '"timeZone": "UTC"'; | ||
const eventStartDateTime = '"start": { "dateTime":"' + new Date().toISOString() + '",' + eventTimeZone + "}"; | ||
const eventEndDateTime = '"end": { "dateTime":"' + new Date().toISOString() + '",' + eventTimeZone + "}"; | ||
|
||
for (let i = 1; i <= numberOfEvents - existingEventsCount; i++) { | ||
const eventBody = "{" + eventSubject + "" + 1 + '",' + eventStartDateTime + "," + eventEndDateTime + "}"; | ||
const response = await client.api(testURL).post(eventBody); | ||
if (response.error) { | ||
throw response.error; | ||
} | ||
} | ||
}); | ||
|
||
it("same headers passed with pageIterator", async () => { | ||
const response = await client | ||
.api(`${testURL}?$top=2`) | ||
.headers(pstHeader) | ||
.select("id,start,end") | ||
.get(); | ||
|
||
const callback: PageIteratorCallback = (eventResponse) => { | ||
const event = eventResponse as Event; | ||
assert.equal(event.start.timeZone, pst); | ||
return true; | ||
}; | ||
var requestOptions: GraphRequestOptions = { options: { headers: pstHeader } }; | ||
if (response["@odata.nextLink"]) { | ||
const pageIterator = new PageIterator(client, response, callback, requestOptions); | ||
await pageIterator.iterate(); | ||
assert.isTrue(pageIterator.isComplete()); | ||
} | ||
}).timeout(30 * 1000); | ||
|
||
it("different headers passed with pageIterator", async () => { | ||
const response = await client | ||
.api(`${testURL}?$top=2`) | ||
.headers({ Prefer: `outlook.timezone= "${utc}"` }) | ||
.select("id,start,end") | ||
.get(); | ||
|
||
let counter = 0; | ||
const callback: PageIteratorCallback = (eventResponse) => { | ||
const event = eventResponse as Event; | ||
if (counter < 2) { | ||
assert.equal(event.start.timeZone, utc); | ||
counter++; | ||
} else { | ||
assert.equal(event.start.timeZone, pst); | ||
ddyett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return true; | ||
}; | ||
|
||
var requestOptions = { headers: pstHeader }; | ||
if (response["@odata.nextLink"]) { | ||
const pageIterator = new PageIterator(client, response, callback, requestOptions); | ||
await pageIterator.iterate(); | ||
assert.isTrue(pageIterator.isComplete()); | ||
} | ||
}).timeout(30 * 1000); | ||
|
||
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, 200, "middleware options for pageIterator", 0, responseBody)]; | ||
const requestOptions = { middlewareOptions }; | ||
|
||
const client = Client.initWithMiddleware(clientOptions); | ||
const pageIterator = new PageIterator(client, getPageCollection(), callback, requestOptions); | ||
await pageIterator.iterate(); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.