Adds unit tests for vcore quickstart feature code (#1618)

* Safety checkin

* Adding vcoremongo to Main

* Safety checkin

* Adding vcoremongo to Main

* Safety commit

* Safety checkin

* Adding vcoremongo to Main

* Safety commit

* Integrating mongo shell

* Safety checkin

* Adding vcoremongo to Main

* Safety commit

* Integrating mongo shell

* Safety checkin

* Safety commit

* Enable mongo shell in its own tab

* Safety checkin

* Adding vcoremongo to Main

* Safety commit

* Integrating mongo shell

* Safety checkin

* Safety commit

* Safety commit

* Integrating mongo shell

* Safety checkin

* Safety commit

* Enable mongo shell in its own tab

* Adding message

* Integrated mongo shell

* Moving Juno endpoint back to prod

* Fixed command bar unit tests

* Fixing spelling

* Adds unit tests for vcore quickstart feature code

* Fix lint
This commit is contained in:
vchske
2023-09-19 17:12:41 -07:00
committed by GitHub
parent ae5811306b
commit 754354dbf9
9 changed files with 335 additions and 12 deletions

View File

@@ -32,6 +32,20 @@ const testCassandraAccount: DataModels.DatabaseAccount = {
},
};
const testPostgresAccount: DataModels.DatabaseAccount = {
...testAccount,
properties: {
postgresqlEndpoint: "https://testPostgresEndpoint.azure.com/",
},
};
const testVCoreMongoAccount: DataModels.DatabaseAccount = {
...testAccount,
properties: {
vcoreMongoEndpoint: "https://testVCoreMongoEndpoint.azure.com/",
},
};
const testNotebookServerInfo: DataModels.NotebookWorkspaceConnectionInfo = {
authToken: "authToken",
notebookServerEndpoint: "https://testNotebookServerEndpoint.azure.com",
@@ -50,6 +64,18 @@ const testCassandraNotebookServerInfo: DataModels.NotebookWorkspaceConnectionInf
forwardingId: "Id",
};
const testPostgresNotebookServerInfo: DataModels.NotebookWorkspaceConnectionInfo = {
authToken: "authToken",
notebookServerEndpoint: "https://testNotebookServerEndpoint.azure.com/postgresql",
forwardingId: "Id",
};
const testVCoreMongoNotebookServerInfo: DataModels.NotebookWorkspaceConnectionInfo = {
authToken: "authToken",
notebookServerEndpoint: "https://testNotebookServerEndpoint.azure.com/mongovcore",
forwardingId: "Id",
};
describe("NotebookTerminalComponent", () => {
it("renders terminal", () => {
const props: NotebookTerminalComponentProps = {
@@ -94,4 +120,27 @@ describe("NotebookTerminalComponent", () => {
const wrapper = shallow(<NotebookTerminalComponent {...props} />);
expect(wrapper).toMatchSnapshot();
});
it("renders Postgres shell", () => {
const props: NotebookTerminalComponentProps = {
databaseAccount: testPostgresAccount,
notebookServerInfo: testPostgresNotebookServerInfo,
tabId: undefined,
};
const wrapper = shallow(<NotebookTerminalComponent {...props} />);
expect(wrapper).toMatchSnapshot();
});
it("renders vCore Mongo shell", () => {
const props: NotebookTerminalComponentProps = {
databaseAccount: testVCoreMongoAccount,
notebookServerInfo: testVCoreMongoNotebookServerInfo,
tabId: undefined,
username: "username",
};
const wrapper = shallow(<NotebookTerminalComponent {...props} />);
expect(wrapper).toMatchSnapshot();
});
});

View File

@@ -1,5 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`NotebookTerminalComponent renders Postgres shell 1`] = `
<div
className="notebookTerminalContainer"
>
<iframe
onLoad={[Function]}
src="terminal.html"
title="Terminal to Notebook Server"
/>
</div>
`;
exports[`NotebookTerminalComponent renders cassandra shell 1`] = `
<div
className="notebookTerminalContainer"
@@ -47,3 +59,15 @@ exports[`NotebookTerminalComponent renders terminal 1`] = `
/>
</div>
`;
exports[`NotebookTerminalComponent renders vCore Mongo shell 1`] = `
<div
className="notebookTerminalContainer"
>
<iframe
onLoad={[Function]}
src="terminal.html"
title="Terminal to Notebook Server"
/>
</div>
`;

View File

@@ -343,6 +343,31 @@ describe("CommandBarComponentButtonFactory tests", () => {
});
});
describe("Open Postgres and vCore Mongo buttons", () => {
const openPostgresShellButtonLabel = "Open PSQL shell";
const openVCoreMongoShellButtonLabel = "Open MongoDB (vcore) shell";
beforeAll(() => {
mockExplorer = {} as Explorer;
});
it("creates Postgres shell button", () => {
const buttons = CommandBarComponentButtonFactory.createPostgreButtons(mockExplorer);
const openPostgresShellButton = buttons.find(
(button) => button.commandButtonLabel === openPostgresShellButtonLabel
);
expect(openPostgresShellButton).toBeDefined();
});
it("creates vCore Mongo shell button", () => {
const buttons = CommandBarComponentButtonFactory.createVCoreMongoButtons(mockExplorer);
const openVCoreMongoShellButton = buttons.find(
(button) => button.commandButtonLabel === openVCoreMongoShellButtonLabel
);
expect(openVCoreMongoShellButton).toBeDefined();
});
});
describe("GitHub buttons", () => {
const connectToGitHubBtnLabel = "Connect to GitHub";
const manageGitHubSettingsBtnLabel = "Manage GitHub settings";

View File

@@ -0,0 +1,91 @@
import { DatabaseAccount, FirewallRule } from "Contracts/DataModels";
import { checkFirewallRules } from "Explorer/Tabs/Shared/CheckFirewallRules";
import { updateUserContext } from "UserContext";
import { mockFunction } from "Utils/JestUtils";
import { armRequest } from "Utils/arm/request";
import React from "react";
jest.mock("Utils/arm/request");
const armRequestMock = mockFunction(armRequest);
describe("CheckFirewallRule tests", () => {
const apiVersion = "2023-03-15-preview";
const rulePredicate = (rule: FirewallRule) =>
rule.properties.startIpAddress === "0.0.0.0" && rule.properties.endIpAddress === "255.255.255.255";
let isAllPublicIPAddressEnabled: boolean;
const setIsAllPublicIPAddressEnabled = jest.fn((value) => (isAllPublicIPAddressEnabled = value));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const useStateMock: any = (initState: any) => [initState, setIsAllPublicIPAddressEnabled];
jest.spyOn(React, "useState").mockImplementation(useStateMock);
beforeAll(() => {
updateUserContext({
databaseAccount: {
id: "testResourceId",
} as DatabaseAccount,
});
});
it("returns 'all public IP addresses' is enabled for account with the proper firewall rule", async () => {
armRequestMock.mockResolvedValueOnce({
value: [
{
id: "resourceId",
name: "AllowAll",
type: "Microsoft.DocumentDB/mongoClusters/firewallRules",
properties: {
provisioningState: "Succeeded",
startIpAddress: "0.0.0.0",
endIpAddress: "255.255.255.255",
},
},
],
});
await checkFirewallRules(apiVersion, rulePredicate, setIsAllPublicIPAddressEnabled);
expect(isAllPublicIPAddressEnabled).toBe(true);
});
it("returns 'all public IP addresses' is NOT enabled for account without the proper firewall rule", async () => {
armRequestMock.mockResolvedValueOnce([
{
id: "resourceId",
name: "AllowAll",
type: "Microsoft.DocumentDB/mongoClusters/firewallRules",
properties: {
provisioningState: "Succeeded",
startIpAddress: "10.10.10.10",
endIpAddress: "10.10.10.10",
},
},
]);
await checkFirewallRules(apiVersion, rulePredicate, setIsAllPublicIPAddressEnabled);
expect(isAllPublicIPAddressEnabled).toBe(false);
});
it("sets message for account without the proper firewall rule", async () => {
armRequestMock.mockResolvedValueOnce([
{
id: "resourceId",
name: "AllowAll",
type: "Microsoft.DocumentDB/mongoClusters/firewallRules",
properties: {
provisioningState: "Succeeded",
startIpAddress: "0.0.0.0",
endIpAddress: "255.255.255.255",
},
},
]);
const warningMessage = "This is a warning message";
let warningMessageResult: string;
const warningMessageFunc = (msg: string) => (warningMessageResult = msg);
await checkFirewallRules(apiVersion, rulePredicate, undefined, warningMessageFunc, warningMessage);
expect(warningMessageResult).toEqual(warningMessage);
});
});