mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-21 01:41:31 +00:00
More ViewModel cleanup (#116)
This commit is contained in:
@@ -1,154 +0,0 @@
|
||||
import * as DataModels from "../Contracts/DataModels";
|
||||
import * as ViewModels from "../Contracts/ViewModels";
|
||||
import { DatabaseAccountUtils } from "./DatabaseAccountUtils";
|
||||
|
||||
describe("DatabaseAccountUtils Tests", () => {
|
||||
describe("mergeDatabaseAccountWithGateway", () => {
|
||||
const databaseAccountWithProperties: ViewModels.DatabaseAccount = {
|
||||
id: "test",
|
||||
kind: "GlobalDocumentDB",
|
||||
name: "test",
|
||||
location: "somewhere",
|
||||
type: "DocumentDB",
|
||||
tags: [],
|
||||
properties: {
|
||||
documentEndpoint: "",
|
||||
cassandraEndpoint: "",
|
||||
gremlinEndpoint: "",
|
||||
tableEndpoint: ""
|
||||
}
|
||||
};
|
||||
|
||||
const databaseAccountWithLocations: ViewModels.DatabaseAccount = {
|
||||
id: "test",
|
||||
kind: "GlobalDocumentDB",
|
||||
name: "test",
|
||||
location: "somewhere",
|
||||
type: "DocumentDB",
|
||||
tags: [],
|
||||
properties: {
|
||||
documentEndpoint: "",
|
||||
cassandraEndpoint: "",
|
||||
gremlinEndpoint: "",
|
||||
tableEndpoint: "",
|
||||
enableMultipleWriteLocations: false,
|
||||
readLocations: [
|
||||
{
|
||||
documentEndpoint: "https://centralus",
|
||||
failoverPriority: 0,
|
||||
id: "",
|
||||
locationId: "",
|
||||
locationName: "Central US",
|
||||
provisioningState: "Succeeded"
|
||||
}
|
||||
],
|
||||
writeLocations: [
|
||||
{
|
||||
documentEndpoint: "https://centralus",
|
||||
failoverPriority: 0,
|
||||
id: "",
|
||||
locationId: "",
|
||||
locationName: "Central US",
|
||||
provisioningState: "Succeeded"
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
const databaseAccountWithoutProperties: ViewModels.DatabaseAccount = {
|
||||
id: "test",
|
||||
kind: "GlobalDocumentDB",
|
||||
name: "test",
|
||||
location: "somewhere",
|
||||
type: "DocumentDB",
|
||||
tags: [],
|
||||
properties: null
|
||||
};
|
||||
|
||||
const gatewayDatabaseAccount: DataModels.GatewayDatabaseAccount = {
|
||||
EnableMultipleWriteLocations: true,
|
||||
CurrentMediaStorageUsageInMB: 0,
|
||||
DatabasesLink: "",
|
||||
MaxMediaStorageUsageInMB: 0,
|
||||
MediaLink: "",
|
||||
ReadableLocations: [
|
||||
{
|
||||
name: "Central US",
|
||||
documentAccountEndpoint: "https://centralus"
|
||||
},
|
||||
{
|
||||
name: "North Central US",
|
||||
documentAccountEndpoint: "https://northcentralus"
|
||||
}
|
||||
],
|
||||
WritableLocations: [
|
||||
{
|
||||
name: "Central US",
|
||||
documentAccountEndpoint: "https://centralus"
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
it("should return databaseAccount when gatewayDatabaseAccount is not defined", () => {
|
||||
expect(DatabaseAccountUtils.mergeDatabaseAccountWithGateway(databaseAccountWithoutProperties, null)).toBe(
|
||||
databaseAccountWithoutProperties
|
||||
);
|
||||
});
|
||||
|
||||
it("should return null when databaseAccount is not defined", () => {
|
||||
expect(DatabaseAccountUtils.mergeDatabaseAccountWithGateway(null, null)).toBeNull();
|
||||
});
|
||||
|
||||
it("should return merged with no properties when databaseAccount has no properties", () => {
|
||||
const merged = DatabaseAccountUtils.mergeDatabaseAccountWithGateway(
|
||||
databaseAccountWithoutProperties,
|
||||
gatewayDatabaseAccount
|
||||
);
|
||||
expect(merged).toBeDefined();
|
||||
expect(merged.properties).toBeNull();
|
||||
});
|
||||
|
||||
it("should return merged writableLocations", () => {
|
||||
const merged = DatabaseAccountUtils.mergeDatabaseAccountWithGateway(
|
||||
databaseAccountWithProperties,
|
||||
gatewayDatabaseAccount
|
||||
);
|
||||
expect(merged.properties).toBeDefined();
|
||||
expect(merged.properties.writeLocations).toBeDefined();
|
||||
expect(merged.properties.writeLocations.length).toBe(gatewayDatabaseAccount.WritableLocations.length);
|
||||
});
|
||||
|
||||
it("should return merged readableLocations", () => {
|
||||
const merged = DatabaseAccountUtils.mergeDatabaseAccountWithGateway(
|
||||
databaseAccountWithProperties,
|
||||
gatewayDatabaseAccount
|
||||
);
|
||||
expect(merged.properties).toBeDefined();
|
||||
expect(merged.properties.readLocations).toBeDefined();
|
||||
expect(merged.properties.readLocations.length).toBe(gatewayDatabaseAccount.ReadableLocations.length);
|
||||
});
|
||||
|
||||
it("should return merged enableMultipleWriteLocations", () => {
|
||||
const merged = DatabaseAccountUtils.mergeDatabaseAccountWithGateway(
|
||||
databaseAccountWithProperties,
|
||||
gatewayDatabaseAccount
|
||||
);
|
||||
expect(merged.properties).toBeDefined();
|
||||
expect(merged.properties.enableMultipleWriteLocations).toBe(gatewayDatabaseAccount.EnableMultipleWriteLocations);
|
||||
});
|
||||
|
||||
it("should not overwrite existing values", () => {
|
||||
const merged = DatabaseAccountUtils.mergeDatabaseAccountWithGateway(
|
||||
databaseAccountWithLocations,
|
||||
gatewayDatabaseAccount
|
||||
);
|
||||
expect(merged.properties.enableMultipleWriteLocations).toBe(
|
||||
databaseAccountWithLocations.properties.enableMultipleWriteLocations
|
||||
);
|
||||
expect(merged.properties.readLocations.length).toBe(databaseAccountWithLocations.properties.readLocations.length);
|
||||
expect(merged.properties.writeLocations.length).toBe(
|
||||
databaseAccountWithLocations.properties.writeLocations.length
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,53 +0,0 @@
|
||||
import * as DataModels from "../Contracts/DataModels";
|
||||
import * as ViewModels from "../Contracts/ViewModels";
|
||||
import { StringUtils } from "./StringUtils";
|
||||
|
||||
export class DatabaseAccountUtils {
|
||||
public static mergeDatabaseAccountWithGateway(
|
||||
databaseAccount: ViewModels.DatabaseAccount,
|
||||
gatewayDatabaseAccount: DataModels.GatewayDatabaseAccount
|
||||
): ViewModels.DatabaseAccount {
|
||||
if (!databaseAccount || !gatewayDatabaseAccount) {
|
||||
return databaseAccount;
|
||||
}
|
||||
|
||||
if (databaseAccount.properties && gatewayDatabaseAccount.EnableMultipleWriteLocations) {
|
||||
databaseAccount.properties.enableMultipleWriteLocations = gatewayDatabaseAccount.EnableMultipleWriteLocations;
|
||||
}
|
||||
|
||||
if (databaseAccount.properties && !databaseAccount.properties.readLocations) {
|
||||
databaseAccount.properties.readLocations = DatabaseAccountUtils._convertToDatabaseAccountResponseLocation(
|
||||
gatewayDatabaseAccount.ReadableLocations
|
||||
);
|
||||
}
|
||||
|
||||
if (databaseAccount.properties && !databaseAccount.properties.writeLocations) {
|
||||
databaseAccount.properties.writeLocations = DatabaseAccountUtils._convertToDatabaseAccountResponseLocation(
|
||||
gatewayDatabaseAccount.WritableLocations
|
||||
);
|
||||
}
|
||||
|
||||
return databaseAccount;
|
||||
}
|
||||
|
||||
private static _convertToDatabaseAccountResponseLocation(
|
||||
gatewayLocations: DataModels.RegionEndpoint[]
|
||||
): DataModels.DatabaseAccountResponseLocation[] {
|
||||
if (!gatewayLocations) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return gatewayLocations.map((gatewayLocation: DataModels.RegionEndpoint, index: number) => {
|
||||
const responseLocation: DataModels.DatabaseAccountResponseLocation = {
|
||||
documentEndpoint: gatewayLocation.documentAccountEndpoint,
|
||||
locationName: gatewayLocation.name,
|
||||
failoverPriority: index,
|
||||
locationId: StringUtils.stripSpacesFromString(gatewayLocation.name).toLowerCase(),
|
||||
provisioningState: "Succeeded",
|
||||
id: gatewayLocation.name
|
||||
};
|
||||
|
||||
return responseLocation;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,12 @@
|
||||
import * as DataModels from "../Contracts/DataModels";
|
||||
import { KernelConnectionMetadata } from "../Contracts/ViewModels";
|
||||
import * as Logger from "../Common/Logger";
|
||||
|
||||
interface KernelConnectionMetadata {
|
||||
name: string;
|
||||
configurationEndpoints: DataModels.NotebookConfigurationEndpoints;
|
||||
notebookConnectionInfo: DataModels.NotebookWorkspaceConnectionInfo;
|
||||
}
|
||||
|
||||
export class NotebookConfigurationUtils {
|
||||
private constructor() {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user