mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-11-25 15:06:55 +00:00
Add all arm request related files to Matser (#373)
* “minor changes” * 'changes for unit test'
This commit is contained in:
parent
983c9201bb
commit
a4a367a212
@ -1,5 +1,7 @@
|
|||||||
import { armRequest } from "./request";
|
import { armRequest } from "./request";
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
|
import { updateUserContext } from "../../UserContext";
|
||||||
|
import { AuthType } from "../../AuthType";
|
||||||
|
|
||||||
interface Global {
|
interface Global {
|
||||||
Headers: unknown;
|
Headers: unknown;
|
||||||
@ -8,6 +10,11 @@ interface Global {
|
|||||||
((global as unknown) as Global).Headers = ((fetch as unknown) as Global).Headers;
|
((global as unknown) as Global).Headers = ((fetch as unknown) as Global).Headers;
|
||||||
|
|
||||||
describe("ARM request", () => {
|
describe("ARM request", () => {
|
||||||
|
window.authType = AuthType.AAD;
|
||||||
|
updateUserContext({
|
||||||
|
authorizationToken: "some-token"
|
||||||
|
});
|
||||||
|
|
||||||
it("should call window.fetch", async () => {
|
it("should call window.fetch", async () => {
|
||||||
window.fetch = jest.fn().mockResolvedValue({
|
window.fetch = jest.fn().mockResolvedValue({
|
||||||
ok: true,
|
ok: true,
|
||||||
@ -48,4 +55,24 @@ describe("ARM request", () => {
|
|||||||
).rejects.toThrow();
|
).rejects.toThrow();
|
||||||
expect(window.fetch).toHaveBeenCalledTimes(2);
|
expect(window.fetch).toHaveBeenCalledTimes(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should throw token error", async () => {
|
||||||
|
window.authType = AuthType.AAD;
|
||||||
|
updateUserContext({
|
||||||
|
authorizationToken: undefined
|
||||||
|
});
|
||||||
|
const headers = new Headers();
|
||||||
|
headers.set("location", "https://foo.com/operationStatus");
|
||||||
|
window.fetch = jest.fn().mockResolvedValue({
|
||||||
|
ok: true,
|
||||||
|
headers,
|
||||||
|
status: 200,
|
||||||
|
json: async () => {
|
||||||
|
return { status: "Failed" };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await expect(() =>
|
||||||
|
armRequest({ apiVersion: "2001-01-01", host: "https://foo.com", path: "foo", method: "GET" })
|
||||||
|
).rejects.toThrow("No authority token provided");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -30,7 +30,7 @@ export class ARMError extends Error {
|
|||||||
Object.setPrototypeOf(this, ARMError.prototype);
|
Object.setPrototypeOf(this, ARMError.prototype);
|
||||||
}
|
}
|
||||||
|
|
||||||
public code: string | number;
|
public code?: string | number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ARMQueryParams {
|
interface ARMQueryParams {
|
||||||
@ -63,6 +63,10 @@ export async function armRequest<T>({
|
|||||||
queryParams.metricNames && url.searchParams.append("metricnames", queryParams.metricNames);
|
queryParams.metricNames && url.searchParams.append("metricnames", queryParams.metricNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!userContext.authorizationToken) {
|
||||||
|
throw new Error("No authority token provided");
|
||||||
|
}
|
||||||
|
|
||||||
const response = await window.fetch(url.href, {
|
const response = await window.fetch(url.href, {
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
@ -98,6 +102,10 @@ export async function armRequest<T>({
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getOperationStatus(operationStatusUrl: string) {
|
async function getOperationStatus(operationStatusUrl: string) {
|
||||||
|
if (!userContext.authorizationToken) {
|
||||||
|
throw new Error("No authority token provided");
|
||||||
|
}
|
||||||
|
|
||||||
const response = await window.fetch(operationStatusUrl, {
|
const response = await window.fetch(operationStatusUrl, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: userContext.authorizationToken
|
Authorization: userContext.authorizationToken
|
||||||
|
@ -89,6 +89,25 @@
|
|||||||
"./src/Utils/StringUtils.ts",
|
"./src/Utils/StringUtils.ts",
|
||||||
"./src/Utils/WindowUtils.ts",
|
"./src/Utils/WindowUtils.ts",
|
||||||
"./src/Utils/arm/generatedClients/2020-04-01/types.ts",
|
"./src/Utils/arm/generatedClients/2020-04-01/types.ts",
|
||||||
|
"./src/Utils/arm/generatedClients/2020-04-01/cassandraResources.ts",
|
||||||
|
"./src/Utils/arm/generatedClients/2020-04-01/collection.ts",
|
||||||
|
"./src/Utils/arm/generatedClients/2020-04-01/collectionPartition.ts",
|
||||||
|
"./src/Utils/arm/generatedClients/2020-04-01/collectionPartitionRegion.ts",
|
||||||
|
"./src/Utils/arm/generatedClients/2020-04-01/collectionRegion.ts",
|
||||||
|
"./src/Utils/arm/generatedClients/2020-04-01/database.ts",
|
||||||
|
"./src/Utils/arm/generatedClients/2020-04-01/databaseAccountRegion.ts",
|
||||||
|
"./src/Utils/arm/generatedClients/2020-04-01/databaseAccounts.ts",
|
||||||
|
"./src/Utils/arm/generatedClients/2020-04-01/gremlinResources.ts",
|
||||||
|
"./src/Utils/arm/generatedClients/2020-04-01/mongoDBResources.ts",
|
||||||
|
"./src/Utils/arm/generatedClients/2020-04-01/operations.ts",
|
||||||
|
"./src/Utils/arm/generatedClients/2020-04-01/partitionKeyRangeId.ts",
|
||||||
|
"./src/Utils/arm/generatedClients/2020-04-01/partitionKeyRangeIdRegion.ts",
|
||||||
|
"./src/Utils/arm/generatedClients/2020-04-01/percentile.ts",
|
||||||
|
"./src/Utils/arm/generatedClients/2020-04-01/percentileSourceTarget.ts",
|
||||||
|
"./src/Utils/arm/generatedClients/2020-04-01/percentileTarget.ts",
|
||||||
|
"./src/Utils/arm/generatedClients/2020-04-01/sqlResources.ts",
|
||||||
|
"./src/Utils/arm/generatedClients/2020-04-01/tableResources.ts",
|
||||||
|
"./src/Utils/arm/request.ts",
|
||||||
"./src/quickstart.ts",
|
"./src/quickstart.ts",
|
||||||
"./src/setupTests.ts",
|
"./src/setupTests.ts",
|
||||||
"./src/workers/upload/definitions.ts"
|
"./src/workers/upload/definitions.ts"
|
||||||
|
Loading…
Reference in New Issue
Block a user