mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-19 17:01:13 +00:00
Refactor Global state into Context Files (#128)
This commit is contained in:
@@ -3,11 +3,18 @@ jest.mock("../MessageHandler");
|
||||
import { deleteCollection } from "./deleteCollection";
|
||||
import { armRequest } from "../../Utils/arm/request";
|
||||
import { AuthType } from "../../AuthType";
|
||||
import { updateUserContext } from "../../UserContext";
|
||||
import { DatabaseAccount } from "../../Contracts/DataModels";
|
||||
import { sendCachedDataMessage } from "../MessageHandler";
|
||||
|
||||
describe("deleteCollection", () => {
|
||||
it("should call ARM if logged in with AAD", async () => {
|
||||
window.authType = AuthType.AAD;
|
||||
updateUserContext({
|
||||
databaseAccount: {
|
||||
name: "test"
|
||||
} as DatabaseAccount
|
||||
});
|
||||
(sendCachedDataMessage as jest.Mock).mockResolvedValue(undefined);
|
||||
await deleteCollection("database", "collection");
|
||||
expect(armRequest).toHaveBeenCalled();
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
import { CosmosClient } from "../CosmosClient";
|
||||
import { refreshCachedResources } from "../DataAccessUtilityBase";
|
||||
import { logConsoleProgress, logConsoleInfo, logConsoleError } from "../../Utils/NotificationConsoleUtils";
|
||||
import { AuthType } from "../../AuthType";
|
||||
import { deleteSqlContainer } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources";
|
||||
import { logConsoleError, logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils";
|
||||
import { userContext } from "../../UserContext";
|
||||
import { client } from "../CosmosClient";
|
||||
import { refreshCachedResources } from "../DataAccessUtilityBase";
|
||||
|
||||
export async function deleteCollection(databaseId: string, collectionId: string): Promise<void> {
|
||||
const clearMessage = logConsoleProgress(`Deleting container ${collectionId}`);
|
||||
try {
|
||||
if (window.authType === AuthType.AAD) {
|
||||
await deleteSqlContainer(
|
||||
CosmosClient.subscriptionId(),
|
||||
CosmosClient.resourceGroup(),
|
||||
CosmosClient.databaseAccount().name,
|
||||
userContext.subscriptionId,
|
||||
userContext.resourceGroup,
|
||||
userContext.databaseAccount.name,
|
||||
databaseId,
|
||||
collectionId
|
||||
);
|
||||
} else {
|
||||
await CosmosClient.client()
|
||||
await client()
|
||||
.database(databaseId)
|
||||
.container(collectionId)
|
||||
.delete();
|
||||
|
||||
@@ -3,11 +3,18 @@ jest.mock("../MessageHandler");
|
||||
import { deleteDatabase } from "./deleteDatabase";
|
||||
import { armRequest } from "../../Utils/arm/request";
|
||||
import { AuthType } from "../../AuthType";
|
||||
import { updateUserContext } from "../../UserContext";
|
||||
import { DatabaseAccount } from "../../Contracts/DataModels";
|
||||
import { sendCachedDataMessage } from "../MessageHandler";
|
||||
|
||||
describe("deleteDatabase", () => {
|
||||
it("should call ARM if logged in with AAD", async () => {
|
||||
window.authType = AuthType.AAD;
|
||||
updateUserContext({
|
||||
databaseAccount: {
|
||||
name: "test"
|
||||
} as DatabaseAccount
|
||||
});
|
||||
(sendCachedDataMessage as jest.Mock).mockResolvedValue(undefined);
|
||||
await deleteDatabase("database");
|
||||
expect(armRequest).toHaveBeenCalled();
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { CosmosClient } from "../CosmosClient";
|
||||
import { refreshCachedResources } from "../DataAccessUtilityBase";
|
||||
import { logConsoleProgress, logConsoleError, logConsoleInfo } from "../../Utils/NotificationConsoleUtils";
|
||||
import { deleteSqlDatabase } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources";
|
||||
import { AuthType } from "../../AuthType";
|
||||
import { deleteSqlDatabase } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources";
|
||||
import { logConsoleError, logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils";
|
||||
import { userContext } from "../../UserContext";
|
||||
import { client } from "../CosmosClient";
|
||||
import { refreshCachedResources } from "../DataAccessUtilityBase";
|
||||
import { logError } from "../Logger";
|
||||
import { sendNotificationForError } from "./sendNotificationForError";
|
||||
|
||||
@@ -12,13 +13,13 @@ export async function deleteDatabase(databaseId: string): Promise<void> {
|
||||
try {
|
||||
if (window.authType === AuthType.AAD) {
|
||||
await deleteSqlDatabase(
|
||||
CosmosClient.subscriptionId(),
|
||||
CosmosClient.resourceGroup(),
|
||||
CosmosClient.databaseAccount().name,
|
||||
userContext.subscriptionId,
|
||||
userContext.resourceGroup,
|
||||
userContext.databaseAccount.name,
|
||||
databaseId
|
||||
);
|
||||
} else {
|
||||
await CosmosClient.client()
|
||||
await client()
|
||||
.database(databaseId)
|
||||
.delete();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user