-
Notifications
You must be signed in to change notification settings - Fork 236
Large file upload task - Add UploadResult object #397
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
8 commits
Select commit
Hold shift + click to select a range
34a5436
Adding upload result, isCancelled upload session property
nikithauc b1492b4
AuthHandler check for graph url, createUploadResult static function
nikithauc 5602d6e
Adding unit test, linting
nikithauc 6c26af3
resetting files
nikithauc a14eafc
cancel task doc, conditions update
nikithauc 05e3d36
Correcting param case
nikithauc a18b0a2
Apply suggestions from code review
baywet dcf1d6c
Apply suggestions from code review
baywet 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /** | ||
| * ------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. | ||
| * See License in the project root for license information. | ||
| * ------------------------------------------------------------------------------------------- | ||
| */ | ||
|
|
||
| /** | ||
| * Class representing a successful file upload result | ||
| */ | ||
| export class UploadResult { | ||
| /** | ||
| * @private | ||
| * Location value looked up in the response header | ||
| */ | ||
| private _location: string; | ||
|
|
||
| /** | ||
| * @private | ||
| * Response body of the final raw response | ||
| */ | ||
| private _responseBody: unknown; | ||
|
|
||
| /** | ||
| * @public | ||
| * Get of the location value. | ||
| * Location value is looked up in the response header | ||
| */ | ||
| public get location(): string { | ||
| return this._location; | ||
| } | ||
|
|
||
| /** | ||
| * @public | ||
| * Set the location value | ||
| * Location value is looked up in the response header | ||
| */ | ||
| public set location(location: string) { | ||
| this._location = location; | ||
| } | ||
|
|
||
| /** | ||
| * @public | ||
| * Get The response body from the completed upload response | ||
| */ | ||
| public get responseBody() { | ||
| return this._responseBody; | ||
| } | ||
|
|
||
| /** | ||
| * @public | ||
| * Set the response body from the completed upload response | ||
| */ | ||
| public set responseBody(responseBody: unknown) { | ||
| this._responseBody = responseBody; | ||
| } | ||
|
|
||
| /** | ||
| * @public | ||
| * @param {responseBody} responsebody - The response body from the completed upload response | ||
| * @param {location} location - The location value from the headers from the completed upload response | ||
| */ | ||
| public constructor(responseBody: unknown, location: string) { | ||
| // Response body or the location parameter can be undefined. | ||
| this._location = location; | ||
| this._responseBody = responseBody; | ||
| } | ||
|
|
||
| /** | ||
| * @public | ||
| * @param {responseBody} responseBody - The response body from the completed upload response | ||
| * @param {responseHeaders} responseHeaders - The headers from the completed upload response | ||
| */ | ||
| public static CreateUploadResult(responseBody?: unknown, responseHeaders?: Headers) { | ||
| return new UploadResult(responseBody, responseHeaders.get("location")); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,9 @@ | |
| */ | ||
|
|
||
| import { assert } from "chai"; | ||
| import * as sinon from "sinon"; | ||
|
|
||
| import { UploadResult } from "../../../src/tasks/FileUploadUtil/UploadResult"; | ||
| import { LargeFileUploadTask } from "../../../src/tasks/LargeFileUploadTask"; | ||
| import { getClient } from "../../test-helper"; | ||
|
|
||
|
|
@@ -157,12 +159,66 @@ describe("LargeFileUploadTask.ts", () => { | |
| const options = { | ||
| rangeSize: 327680, | ||
| }; | ||
| const uploadTask = new LargeFileUploadTask(getClient(), fileObj, uploadSession, options); | ||
|
|
||
| it("Should return a Upload Result object after a completed task with 201 status", async () => { | ||
| const location = "TEST_URL"; | ||
| const body = { | ||
| id: "TEST_ID", | ||
| }; | ||
| const uploadTask = new LargeFileUploadTask(getClient(), fileObj, uploadSession, options); | ||
| const status201 = { | ||
| status: 200, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 201?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Otherwise this test is exactly the same as the one below. |
||
| stautsText: "OK", | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| location, | ||
| }, | ||
| }; | ||
| const rawResponse = new Response(JSON.stringify(body), status201); | ||
|
|
||
| const moq = sinon.mock(uploadTask); | ||
| moq.expects("uploadSliceGetRawResponse").resolves(rawResponse); | ||
| const result = await uploadTask.upload(); | ||
| assert.isDefined(result); | ||
| assert.instanceOf(result, UploadResult); | ||
| assert.equal(result["location"], location); | ||
| const responseBody = result["responseBody"]; | ||
| assert.isDefined(responseBody); | ||
| assert.equal(responseBody["id"], "TEST_ID"); | ||
| }); | ||
|
|
||
| it("Should return a Upload Result object after a completed task with 200 status and id", async () => { | ||
| const location = "TEST_URL"; | ||
| const body = { | ||
| id: "TEST_ID", | ||
| }; | ||
| const uploadTask = new LargeFileUploadTask(getClient(), fileObj, uploadSession, options); | ||
| const status200 = { | ||
| status: 200, | ||
| stautsText: "OK", | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| location, | ||
| }, | ||
| }; | ||
| const rawResponse = new Response(JSON.stringify(body), status200); | ||
|
|
||
| const moq = sinon.mock(uploadTask); | ||
| moq.expects("uploadSliceGetRawResponse").resolves(rawResponse); | ||
| const result = await uploadTask.upload(); | ||
| assert.isDefined(result); | ||
| assert.instanceOf(result, UploadResult); | ||
| assert.equal(result["location"], location); | ||
| const responseBody = result["responseBody"]; | ||
| assert.isDefined(responseBody); | ||
| assert.equal(responseBody["id"], "TEST_ID"); | ||
| }); | ||
| it("Should return an exception while trying to upload the file upload completed task", (done) => { | ||
| const statusResponse = { | ||
| expirationDateTime: "2018-08-06T09:05:45.195Z", | ||
| nextExpectedRanges: [], | ||
| }; | ||
| const uploadTask = new LargeFileUploadTask(getClient(), fileObj, uploadSession, options); | ||
| uploadTask["updateTaskStatus"](statusResponse); | ||
| uploadTask | ||
| .upload() | ||
|
|
||
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.