mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-04-14 05:38:54 +01:00
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
jest.mock("../../Utils/arm/request");
|
|
jest.mock("../CosmosClient");
|
|
import { AuthType } from "../../AuthType";
|
|
import { DatabaseAccount } from "../../Contracts/DataModels";
|
|
import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType";
|
|
import { armRequest } from "../../Utils/arm/request";
|
|
import { client } from "../CosmosClient";
|
|
import { readDatabases } from "./readDatabases";
|
|
import { updateUserContext } from "../../UserContext";
|
|
|
|
describe("readDatabases", () => {
|
|
beforeAll(() => {
|
|
updateUserContext({
|
|
databaseAccount: {
|
|
name: "test",
|
|
} as DatabaseAccount,
|
|
defaultExperience: DefaultAccountExperienceType.DocumentDB,
|
|
});
|
|
});
|
|
|
|
it("should call ARM if logged in with AAD", async () => {
|
|
updateUserContext({
|
|
authType: AuthType.AAD,
|
|
});
|
|
await readDatabases();
|
|
expect(armRequest).toHaveBeenCalled();
|
|
});
|
|
|
|
it("should call SDK if not logged in with non-AAD method", async () => {
|
|
updateUserContext({
|
|
authType: AuthType.MasterKey,
|
|
});
|
|
(client as jest.Mock).mockReturnValue({
|
|
databases: {
|
|
readAll: () => {
|
|
return {
|
|
fetchAll: (): unknown => [],
|
|
};
|
|
},
|
|
},
|
|
});
|
|
await readDatabases();
|
|
expect(client).toHaveBeenCalled();
|
|
});
|
|
});
|