mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-20 17:30:46 +00:00
Remove window.dataExplorerPlatform (#279)
More cleanup for #253 - Remove window.dataExplorerPlatform - Remove explorer factories
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import * as Constants from "../Common/Constants";
|
||||
import * as AuthorizationUtils from "./AuthorizationUtils";
|
||||
import { AuthType } from "../AuthType";
|
||||
import { PlatformType } from "../PlatformType";
|
||||
import Explorer from "../Explorer/Explorer";
|
||||
import { updateUserContext } from "../UserContext";
|
||||
import { Platform, updateConfigContext } from "../ConfigContext";
|
||||
jest.mock("../Explorer/Explorer");
|
||||
|
||||
describe("AuthorizationUtils", () => {
|
||||
@@ -65,12 +65,13 @@ describe("AuthorizationUtils", () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
window.dataExplorer = explorer;
|
||||
window.dataExplorerPlatform = PlatformType.Hosted;
|
||||
updateConfigContext({
|
||||
platform: Platform.Hosted
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
window.dataExplorer = undefined;
|
||||
window.dataExplorerPlatform = undefined;
|
||||
});
|
||||
|
||||
it("should not open token renewal prompt if status code is undefined", () => {
|
||||
@@ -89,7 +90,9 @@ describe("AuthorizationUtils", () => {
|
||||
});
|
||||
|
||||
it("should not open token renewal prompt if running on a different platform", () => {
|
||||
window.dataExplorerPlatform = PlatformType.Portal;
|
||||
updateConfigContext({
|
||||
platform: Platform.Portal
|
||||
});
|
||||
AuthorizationUtils.displayTokenRenewalPromptForStatus(Constants.HttpStatusCodes.Unauthorized);
|
||||
expect(explorer.displayGuestAccessTokenRenewalPrompt).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -3,8 +3,7 @@ import * as ViewModels from "../Contracts/ViewModels";
|
||||
import AuthHeadersUtil from "../Platform/Hosted/Authorization";
|
||||
import { AuthType } from "../AuthType";
|
||||
import * as Logger from "../Common/Logger";
|
||||
import { PlatformType } from "../PlatformType";
|
||||
import { configContext } from "../ConfigContext";
|
||||
import { configContext, Platform } from "../ConfigContext";
|
||||
import { userContext } from "../UserContext";
|
||||
|
||||
export function getAuthorizationHeader(): ViewModels.AuthorizationTokenHeaderMetadata {
|
||||
@@ -57,13 +56,12 @@ export function decryptJWTToken(token: string) {
|
||||
}
|
||||
|
||||
export function displayTokenRenewalPromptForStatus(httpStatusCode: number): void {
|
||||
const platformType = window.dataExplorerPlatform;
|
||||
const explorer = window.dataExplorer;
|
||||
|
||||
if (
|
||||
httpStatusCode == null ||
|
||||
httpStatusCode != Constants.HttpStatusCodes.Unauthorized ||
|
||||
platformType !== PlatformType.Hosted
|
||||
configContext.platform !== Platform.Hosted
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user