@microsoft/kiota-http-fetchlibrary
Advanced tools
Comparing version 1.0.0-preview.7 to 1.0.0-preview.8
@@ -51,2 +51,3 @@ "use strict"; | ||
case "Date": | ||
// eslint-disable-next-line no-case-declarations | ||
const rootNode = yield this.getRootParseNode(response); | ||
@@ -143,2 +144,6 @@ if (responseType === "string") { | ||
case "ArrayBuffer": | ||
// eslint-disable-next-line no-case-declarations | ||
if (!response.body) { | ||
return undefined; | ||
} | ||
return (yield response.arrayBuffer()); | ||
@@ -149,2 +154,3 @@ case "string": | ||
case "Date": | ||
// eslint-disable-next-line no-case-declarations | ||
const rootNode = yield this.getRootParseNode(response); | ||
@@ -214,3 +220,3 @@ if (responseType === "string") { | ||
this.shouldReturnUndefined = (response) => { | ||
return response.status === 204; | ||
return response.status === 204 || !response.body; | ||
}; | ||
@@ -217,0 +223,0 @@ /** purges the response body if it hasn't been read to release the connection to the server */ |
@@ -11,2 +11,3 @@ /** | ||
export * from "./middlewares/middleware"; | ||
export * from "./middlewares/chaosHandler"; | ||
export * from "./middlewares/customFetchHandler"; | ||
@@ -16,2 +17,4 @@ export * from "./middlewares/parametersNameDecodingHandler"; | ||
export * from "./middlewares/retryHandler"; | ||
export * from "./middlewares/options/chaosHandlerOptions"; | ||
export * from "./middlewares/options/chaosStrategy"; | ||
export * from "./middlewares/options/parametersNameDecodingOptions"; | ||
@@ -18,0 +21,0 @@ export * from "./middlewares/options/redirectHandlerOptions"; |
@@ -15,2 +15,3 @@ "use strict"; | ||
tslib_1.__exportStar(require("./middlewares/middleware"), exports); | ||
tslib_1.__exportStar(require("./middlewares/chaosHandler"), exports); | ||
tslib_1.__exportStar(require("./middlewares/customFetchHandler"), exports); | ||
@@ -20,2 +21,4 @@ tslib_1.__exportStar(require("./middlewares/parametersNameDecodingHandler"), exports); | ||
tslib_1.__exportStar(require("./middlewares/retryHandler"), exports); | ||
tslib_1.__exportStar(require("./middlewares/options/chaosHandlerOptions"), exports); | ||
tslib_1.__exportStar(require("./middlewares/options/chaosStrategy"), exports); | ||
tslib_1.__exportStar(require("./middlewares/options/parametersNameDecodingOptions"), exports); | ||
@@ -22,0 +25,0 @@ tslib_1.__exportStar(require("./middlewares/options/redirectHandlerOptions"), exports); |
@@ -16,2 +16,4 @@ "use strict"; | ||
const testUtils_1 = require("../testUtils"); | ||
const mockEntity_1 = require("./mockEntity"); | ||
const mockParseNodeFactory_1 = require("./mockParseNodeFactory"); | ||
// eslint-disable-next-line no-var | ||
@@ -48,2 +50,80 @@ var Response = Response; | ||
}); | ||
describe("send stream returns stream", () => { | ||
for (const statusCode of [200, 201, 202, 203, 206]) { | ||
it(`should return stream for status code ${statusCode}`, () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const mockHttpClient = new httpClient_1.HttpClient(); | ||
mockHttpClient.executeFetch = (url, requestInit, requestOptions) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const response = new Response("", { | ||
status: statusCode, | ||
}); | ||
return Promise.resolve(response); | ||
}); | ||
const requestAdapter = new fetchRequestAdapter_1.FetchRequestAdapter(new kiota_abstractions_1.AnonymousAuthenticationProvider(), undefined, undefined, mockHttpClient); | ||
const requestInformation = new kiota_abstractions_1.RequestInformation(); | ||
requestInformation.URL = "https://www.example.com"; | ||
requestInformation.httpMethod = kiota_abstractions_1.HttpMethod.GET; | ||
const result = yield requestAdapter.sendPrimitiveAsync(requestInformation, "ArrayBuffer", undefined, undefined); | ||
chai_1.assert.isDefined(result); | ||
})); | ||
} | ||
}); | ||
describe("send stream returns null on no content", () => { | ||
for (const statusCode of [200, 201, 202, 203, 204]) { | ||
it(`should return null for status code ${statusCode}`, () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const mockHttpClient = new httpClient_1.HttpClient(); | ||
mockHttpClient.executeFetch = (url, requestInit, requestOptions) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const response = new Response(null, { | ||
status: statusCode, | ||
}); | ||
return Promise.resolve(response); | ||
}); | ||
const requestAdapter = new fetchRequestAdapter_1.FetchRequestAdapter(new kiota_abstractions_1.AnonymousAuthenticationProvider(), undefined, undefined, mockHttpClient); | ||
const requestInformation = new kiota_abstractions_1.RequestInformation(); | ||
requestInformation.URL = "https://www.example.com"; | ||
requestInformation.httpMethod = kiota_abstractions_1.HttpMethod.GET; | ||
const result = yield requestAdapter.sendPrimitiveAsync(requestInformation, "ArrayBuffer", undefined, undefined); | ||
chai_1.assert.isUndefined(result); | ||
})); | ||
} | ||
}); | ||
describe("send returns null on no content", () => { | ||
for (const statusCode of [200, 201, 202, 203, 204, 205]) { | ||
it(`should return null for status code ${statusCode}`, () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const mockHttpClient = new httpClient_1.HttpClient(); | ||
mockHttpClient.executeFetch = (url, requestInit, requestOptions) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const response = new Response(null, { | ||
status: statusCode, | ||
}); | ||
return Promise.resolve(response); | ||
}); | ||
const requestAdapter = new fetchRequestAdapter_1.FetchRequestAdapter(new kiota_abstractions_1.AnonymousAuthenticationProvider(), undefined, undefined, mockHttpClient); | ||
const requestInformation = new kiota_abstractions_1.RequestInformation(); | ||
requestInformation.URL = "https://www.example.com"; | ||
requestInformation.httpMethod = kiota_abstractions_1.HttpMethod.GET; | ||
const result = yield requestAdapter.sendAsync(requestInformation, undefined, undefined, undefined); | ||
chai_1.assert.isUndefined(result); | ||
})); | ||
} | ||
}); | ||
describe("send returns object on content", () => { | ||
for (const statusCode of [200, 201, 202, 203, 205]) { | ||
it(`should return object for status code ${statusCode}`, () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const mockHttpClient = new httpClient_1.HttpClient(); | ||
mockHttpClient.executeFetch = (url, requestInit, requestOptions) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const response = new Response("test", { | ||
status: statusCode, | ||
}); | ||
response.headers.set("Content-Type", "application/json"); | ||
return Promise.resolve(response); | ||
}); | ||
const mockFactory = new mockParseNodeFactory_1.MockParseNodeFactory(new mockParseNodeFactory_1.MockParseNode(new mockEntity_1.MockEntity())); | ||
const requestAdapter = new fetchRequestAdapter_1.FetchRequestAdapter(new kiota_abstractions_1.AnonymousAuthenticationProvider(), mockFactory, undefined, mockHttpClient); | ||
const requestInformation = new kiota_abstractions_1.RequestInformation(); | ||
requestInformation.URL = "https://www.example.com"; | ||
requestInformation.httpMethod = kiota_abstractions_1.HttpMethod.GET; | ||
const result = yield requestAdapter.sendAsync(requestInformation, mockEntity_1.CreateMockEntityFromParseNode, undefined, undefined); | ||
chai_1.assert.isDefined(result); | ||
})); | ||
} | ||
}); | ||
}); |
@@ -47,2 +47,3 @@ import { ApiError, BackingStoreFactorySingleton, enableBackingStoreForParseNodeFactory, enableBackingStoreForSerializationWriterFactory, ParseNodeFactoryRegistry, SerializationWriterFactoryRegistry } from "@microsoft/kiota-abstractions"; | ||
case "Date": | ||
// eslint-disable-next-line no-case-declarations | ||
const rootNode = await this.getRootParseNode(response); | ||
@@ -139,2 +140,6 @@ if (responseType === "string") { | ||
case "ArrayBuffer": | ||
// eslint-disable-next-line no-case-declarations | ||
if (!response.body) { | ||
return undefined; | ||
} | ||
return (await response.arrayBuffer()); | ||
@@ -145,2 +150,3 @@ case "string": | ||
case "Date": | ||
// eslint-disable-next-line no-case-declarations | ||
const rootNode = await this.getRootParseNode(response); | ||
@@ -210,3 +216,3 @@ if (responseType === "string") { | ||
this.shouldReturnUndefined = (response) => { | ||
return response.status === 204; | ||
return response.status === 204 || !response.body; | ||
}; | ||
@@ -213,0 +219,0 @@ /** purges the response body if it hasn't been read to release the connection to the server */ |
@@ -11,2 +11,3 @@ /** | ||
export * from "./middlewares/middleware"; | ||
export * from "./middlewares/chaosHandler"; | ||
export * from "./middlewares/customFetchHandler"; | ||
@@ -16,2 +17,4 @@ export * from "./middlewares/parametersNameDecodingHandler"; | ||
export * from "./middlewares/retryHandler"; | ||
export * from "./middlewares/options/chaosHandlerOptions"; | ||
export * from "./middlewares/options/chaosStrategy"; | ||
export * from "./middlewares/options/parametersNameDecodingOptions"; | ||
@@ -18,0 +21,0 @@ export * from "./middlewares/options/redirectHandlerOptions"; |
@@ -12,2 +12,3 @@ /** | ||
export * from "./middlewares/middleware"; | ||
export * from "./middlewares/chaosHandler"; | ||
export * from "./middlewares/customFetchHandler"; | ||
@@ -17,2 +18,4 @@ export * from "./middlewares/parametersNameDecodingHandler"; | ||
export * from "./middlewares/retryHandler"; | ||
export * from "./middlewares/options/chaosHandlerOptions"; | ||
export * from "./middlewares/options/chaosStrategy"; | ||
export * from "./middlewares/options/parametersNameDecodingOptions"; | ||
@@ -19,0 +22,0 @@ export * from "./middlewares/options/redirectHandlerOptions"; |
@@ -13,2 +13,4 @@ /** | ||
import { getResponse } from "../testUtils"; | ||
import { CreateMockEntityFromParseNode, MockEntity } from "./mockEntity"; | ||
import { MockParseNode, MockParseNodeFactory } from "./mockParseNodeFactory"; | ||
// eslint-disable-next-line no-var | ||
@@ -45,2 +47,80 @@ var Response = Response; | ||
}); | ||
describe("send stream returns stream", () => { | ||
for (const statusCode of [200, 201, 202, 203, 206]) { | ||
it(`should return stream for status code ${statusCode}`, async () => { | ||
const mockHttpClient = new HttpClient(); | ||
mockHttpClient.executeFetch = async (url, requestInit, requestOptions) => { | ||
const response = new Response("", { | ||
status: statusCode, | ||
}); | ||
return Promise.resolve(response); | ||
}; | ||
const requestAdapter = new FetchRequestAdapter(new AnonymousAuthenticationProvider(), undefined, undefined, mockHttpClient); | ||
const requestInformation = new RequestInformation(); | ||
requestInformation.URL = "https://www.example.com"; | ||
requestInformation.httpMethod = HttpMethod.GET; | ||
const result = await requestAdapter.sendPrimitiveAsync(requestInformation, "ArrayBuffer", undefined, undefined); | ||
assert.isDefined(result); | ||
}); | ||
} | ||
}); | ||
describe("send stream returns null on no content", () => { | ||
for (const statusCode of [200, 201, 202, 203, 204]) { | ||
it(`should return null for status code ${statusCode}`, async () => { | ||
const mockHttpClient = new HttpClient(); | ||
mockHttpClient.executeFetch = async (url, requestInit, requestOptions) => { | ||
const response = new Response(null, { | ||
status: statusCode, | ||
}); | ||
return Promise.resolve(response); | ||
}; | ||
const requestAdapter = new FetchRequestAdapter(new AnonymousAuthenticationProvider(), undefined, undefined, mockHttpClient); | ||
const requestInformation = new RequestInformation(); | ||
requestInformation.URL = "https://www.example.com"; | ||
requestInformation.httpMethod = HttpMethod.GET; | ||
const result = await requestAdapter.sendPrimitiveAsync(requestInformation, "ArrayBuffer", undefined, undefined); | ||
assert.isUndefined(result); | ||
}); | ||
} | ||
}); | ||
describe("send returns null on no content", () => { | ||
for (const statusCode of [200, 201, 202, 203, 204, 205]) { | ||
it(`should return null for status code ${statusCode}`, async () => { | ||
const mockHttpClient = new HttpClient(); | ||
mockHttpClient.executeFetch = async (url, requestInit, requestOptions) => { | ||
const response = new Response(null, { | ||
status: statusCode, | ||
}); | ||
return Promise.resolve(response); | ||
}; | ||
const requestAdapter = new FetchRequestAdapter(new AnonymousAuthenticationProvider(), undefined, undefined, mockHttpClient); | ||
const requestInformation = new RequestInformation(); | ||
requestInformation.URL = "https://www.example.com"; | ||
requestInformation.httpMethod = HttpMethod.GET; | ||
const result = await requestAdapter.sendAsync(requestInformation, undefined, undefined, undefined); | ||
assert.isUndefined(result); | ||
}); | ||
} | ||
}); | ||
describe("send returns object on content", () => { | ||
for (const statusCode of [200, 201, 202, 203, 205]) { | ||
it(`should return object for status code ${statusCode}`, async () => { | ||
const mockHttpClient = new HttpClient(); | ||
mockHttpClient.executeFetch = async (url, requestInit, requestOptions) => { | ||
const response = new Response("test", { | ||
status: statusCode, | ||
}); | ||
response.headers.set("Content-Type", "application/json"); | ||
return Promise.resolve(response); | ||
}; | ||
const mockFactory = new MockParseNodeFactory(new MockParseNode(new MockEntity())); | ||
const requestAdapter = new FetchRequestAdapter(new AnonymousAuthenticationProvider(), mockFactory, undefined, mockHttpClient); | ||
const requestInformation = new RequestInformation(); | ||
requestInformation.URL = "https://www.example.com"; | ||
requestInformation.httpMethod = HttpMethod.GET; | ||
const result = await requestAdapter.sendAsync(requestInformation, CreateMockEntityFromParseNode, undefined, undefined); | ||
assert.isDefined(result); | ||
}); | ||
} | ||
}); | ||
}); |
{ | ||
"name": "@microsoft/kiota-http-fetchlibrary", | ||
"version": "1.0.0-preview.7", | ||
"version": "1.0.0-preview.8", | ||
"description": "Kiota request adapter implementation with fetch", | ||
@@ -51,3 +51,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "de31c882a56870f10216603a245270120a31f9d0" | ||
"gitHead": "dcb807e06d70b5c893c13e1e398b67d64f06fc87" | ||
} |
@@ -55,2 +55,3 @@ import { ApiError, AuthenticationProvider, BackingStoreFactory, BackingStoreFactorySingleton, DateOnly, Duration, enableBackingStoreForParseNodeFactory, enableBackingStoreForSerializationWriterFactory, Parsable, ParsableFactory, ParseNode,ParseNodeFactory, ParseNodeFactoryRegistry, RequestAdapter, RequestInformation, ResponseHandler, SerializationWriterFactory, SerializationWriterFactoryRegistry, TimeOnly } from "@microsoft/kiota-abstractions"; | ||
case "Date": | ||
// eslint-disable-next-line no-case-declarations | ||
const rootNode = await this.getRootParseNode(response); | ||
@@ -131,2 +132,6 @@ if (responseType === "string") { | ||
case "ArrayBuffer": | ||
// eslint-disable-next-line no-case-declarations | ||
if (!response.body) { | ||
return undefined; | ||
} | ||
return (await response.arrayBuffer()) as unknown as ResponseType; | ||
@@ -137,2 +142,3 @@ case "string": | ||
case "Date": | ||
// eslint-disable-next-line no-case-declarations | ||
const rootNode = await this.getRootParseNode(response); | ||
@@ -192,3 +198,3 @@ if (responseType === "string") { | ||
private shouldReturnUndefined = (response: Response): boolean => { | ||
return response.status === 204; | ||
return response.status === 204 || !response.body; | ||
}; | ||
@@ -195,0 +201,0 @@ /** purges the response body if it hasn't been read to release the connection to the server */ |
@@ -14,2 +14,3 @@ /** | ||
export * from "./middlewares/middleware"; | ||
export * from "./middlewares/chaosHandler"; | ||
export * from "./middlewares/customFetchHandler"; | ||
@@ -19,2 +20,4 @@ export * from "./middlewares/parametersNameDecodingHandler"; | ||
export * from "./middlewares/retryHandler"; | ||
export * from "./middlewares/options/chaosHandlerOptions"; | ||
export * from "./middlewares/options/chaosStrategy"; | ||
export * from "./middlewares/options/parametersNameDecodingOptions"; | ||
@@ -21,0 +24,0 @@ export * from "./middlewares/options/redirectHandlerOptions"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1036381
279
21481