add tests

This commit is contained in:
Asier Isayas 2025-01-24 17:04:06 -05:00
parent 84b30accf6
commit b9146d4643
3 changed files with 31 additions and 1 deletions

View File

@ -101,6 +101,7 @@ export enum WorkloadType {
Learning = "Learning",
DevelopmentTesting = "Development/Testing",
Production = "Production",
None = "None"
}
// flight names returned from the portal are always lowercase
export class Flights {
@ -124,7 +125,7 @@ export class AfecFeatures {
export class TagNames {
public static defaultExperience: string = "defaultExperience";
public static readonly WorkloadType: string = "hidden-workload-type";
public static WorkloadType: string = "hidden-workload-type";
}
export class MongoDBAccounts {

View File

@ -0,0 +1,26 @@
import { WorkloadType } from "Common/Constants";
import { getWorkloadType } from "Common/DatabaseAccountUtility";
import { DatabaseAccount, Tags } from "Contracts/DataModels";
import { updateUserContext } from "UserContext";
describe("Database Account Utility", () => {
describe("Workload Type", () => {
it("Workload Type should return Learning", () => {
updateUserContext({
databaseAccount: {
tags: {
"hidden-workload-type": WorkloadType.Learning
} as Tags
} as DatabaseAccount
})
const workloadType: WorkloadType = getWorkloadType();
expect(workloadType).toBe(WorkloadType.Learning);
});
it("Workload Type should return None", () => {
const workloadType: WorkloadType = getWorkloadType();
expect(workloadType).toBe(WorkloadType.None);
});
})
})

View File

@ -21,5 +21,8 @@ export function isPublicInternetAccessAllowed(): boolean {
export function getWorkloadType(): WorkloadType {
const tags: Tags = userContext?.databaseAccount?.tags;
const workloadType: WorkloadType = tags && (tags[TagNames.WorkloadType] as WorkloadType);
if (!workloadType) {
return WorkloadType.None;
}
return workloadType;
}