mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-28 14:14:08 +00:00
Add all arm request related files to Matser (#373)
* “minor changes” * 'changes for unit test'
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { armRequest } from "./request";
|
||||
import fetch from "node-fetch";
|
||||
import { updateUserContext } from "../../UserContext";
|
||||
import { AuthType } from "../../AuthType";
|
||||
|
||||
interface Global {
|
||||
Headers: unknown;
|
||||
@@ -8,6 +10,11 @@ interface Global {
|
||||
((global as unknown) as Global).Headers = ((fetch as unknown) as Global).Headers;
|
||||
|
||||
describe("ARM request", () => {
|
||||
window.authType = AuthType.AAD;
|
||||
updateUserContext({
|
||||
authorizationToken: "some-token"
|
||||
});
|
||||
|
||||
it("should call window.fetch", async () => {
|
||||
window.fetch = jest.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
@@ -48,4 +55,24 @@ describe("ARM request", () => {
|
||||
).rejects.toThrow();
|
||||
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");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user