Sunil Kumar Yadav 531df811da
Remove userContext.defaultExperience ()
Co-authored-by: Steve Faulkner <southpolesteve@gmail.com>
2021-04-28 14:25:04 -05:00

49 lines
1.3 KiB
TypeScript

jest.mock("../../Utils/arm/request");
jest.mock("../CosmosClient");
import { AuthType } from "../../AuthType";
import { DatabaseAccount } from "../../Contracts/DataModels";
import { updateUserContext } from "../../UserContext";
import { armRequest } from "../../Utils/arm/request";
import { client } from "../CosmosClient";
import { readCollections } from "./readCollections";
describe("readCollections", () => {
beforeAll(() => {
updateUserContext({
databaseAccount: {
name: "test",
} as DatabaseAccount,
apiType: "SQL",
});
});
it("should call ARM if logged in with AAD", async () => {
updateUserContext({
authType: AuthType.AAD,
});
await readCollections("database");
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({
database: () => {
return {
containers: {
readAll: () => {
return {
fetchAll: (): unknown => [],
};
},
},
};
},
});
await readCollections("database");
expect(client).toHaveBeenCalled();
});
});