mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-20 09:20:16 +00:00
@@ -25,37 +25,37 @@ describe("PricingUtils Tests", () => {
|
||||
|
||||
describe("computeRUUsagePriceHourly()", () => {
|
||||
it("should return 0 for NaN regions default cloud", () => {
|
||||
const value = PricingUtils.computeRUUsagePriceHourly("default", false, 1, null, false);
|
||||
const value = PricingUtils.computeRUUsagePriceHourly("default", 1, null, false);
|
||||
expect(value).toBe(0);
|
||||
});
|
||||
|
||||
it("should return 0 for -1 regions", () => {
|
||||
const value = PricingUtils.computeRUUsagePriceHourly("default", false, 1, -1, false);
|
||||
const value = PricingUtils.computeRUUsagePriceHourly("default", 1, -1, false);
|
||||
expect(value).toBe(0);
|
||||
});
|
||||
|
||||
it("should return 0.00008 for default cloud, rupm disabled, 1RU, 1 region, multimaster disabled", () => {
|
||||
const value = PricingUtils.computeRUUsagePriceHourly("default", false, 1, 1, false);
|
||||
it("should return 0.00008 for default cloud, 1RU, 1 region, multimaster disabled", () => {
|
||||
const value = PricingUtils.computeRUUsagePriceHourly("default", 1, 1, false);
|
||||
expect(value).toBe(0.00008);
|
||||
});
|
||||
|
||||
it("should return 0.00051 for Mooncake cloud, rupm disabled, 1RU, 1 region, multimaster disabled", () => {
|
||||
const value = PricingUtils.computeRUUsagePriceHourly("mooncake", false, 1, 1, false);
|
||||
it("should return 0.00051 for Mooncake cloud, 1RU, 1 region, multimaster disabled", () => {
|
||||
const value = PricingUtils.computeRUUsagePriceHourly("mooncake", 1, 1, false);
|
||||
expect(value).toBe(0.00051);
|
||||
});
|
||||
|
||||
it("should return 0.00016 for default cloud, rupm disabled, 1RU, 2 regions, multimaster disabled", () => {
|
||||
const value = PricingUtils.computeRUUsagePriceHourly("default", false, 1, 2, false);
|
||||
it("should return 0.00016 for default cloud, 1RU, 2 regions, multimaster disabled", () => {
|
||||
const value = PricingUtils.computeRUUsagePriceHourly("default", 1, 2, false);
|
||||
expect(value).toBe(0.00016);
|
||||
});
|
||||
|
||||
it("should return 0.00008 for default cloud, rupm disabled, 1RU, 1 region, multimaster enabled", () => {
|
||||
const value = PricingUtils.computeRUUsagePriceHourly("default", false, 1, 1, true);
|
||||
it("should return 0.00008 for default cloud, 1RU, 1 region, multimaster enabled", () => {
|
||||
const value = PricingUtils.computeRUUsagePriceHourly("default", 1, 1, true);
|
||||
expect(value).toBe(0.00008);
|
||||
});
|
||||
|
||||
it("should return 0.00048 for default cloud, rupm disabled, 1RU, 2 region, multimaster enabled", () => {
|
||||
const value = PricingUtils.computeRUUsagePriceHourly("default", false, 1, 2, true);
|
||||
it("should return 0.00048 for default cloud, 1RU, 2 region, multimaster enabled", () => {
|
||||
const value = PricingUtils.computeRUUsagePriceHourly("default", 1, 2, true);
|
||||
expect(value).toBe(0.00048);
|
||||
});
|
||||
});
|
||||
@@ -150,18 +150,6 @@ describe("PricingUtils Tests", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("getPricePerRuPm()", () => {
|
||||
it("should return 0.000027397260273972603 for default clouds", () => {
|
||||
const value = PricingUtils.getPricePerRuPm("default");
|
||||
expect(value).toBe(0.000027397260273972603);
|
||||
});
|
||||
|
||||
it("should return 0.00027397260273972606 for mooncake", () => {
|
||||
const value = PricingUtils.getPricePerRuPm("mooncake");
|
||||
expect(value).toBe(0.00027397260273972606);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getRegionMultiplier()", () => {
|
||||
describe("without multimaster", () => {
|
||||
it("should return 0 for null", () => {
|
||||
@@ -254,52 +242,48 @@ describe("PricingUtils Tests", () => {
|
||||
});
|
||||
|
||||
describe("getEstimatedSpendHtml()", () => {
|
||||
it("should return 'Estimated cost (USD): <b>$0.000080 hourly / $0.0019 daily / $0.058 monthly </b> (1 region, 1RU/s, $0.00008/RU)' for 1RU/s on default cloud, 1 region, with multimaster, and no rupm", () => {
|
||||
it("should return 'Estimated cost (USD): <b>$0.000080 hourly / $0.0019 daily / $0.058 monthly </b> (1 region, 1RU/s, $0.00008/RU)' for 1RU/s on default cloud, 1 region, with multimaster", () => {
|
||||
const value = PricingUtils.getEstimatedSpendHtml(
|
||||
1 /*RU/s*/,
|
||||
"default" /* cloud */,
|
||||
1 /* region */,
|
||||
true /* multimaster */,
|
||||
false /* rupm */
|
||||
true /* multimaster */
|
||||
);
|
||||
expect(value).toBe(
|
||||
"Estimated cost (USD): <b>$0.000080 hourly / $0.0019 daily / $0.058 monthly </b> (1 region, 1RU/s, $0.00008/RU)"
|
||||
);
|
||||
});
|
||||
|
||||
it("should return 'Estimated cost (RMB): <b>¥0.00051 hourly / ¥0.012 daily / ¥0.37 monthly </b> (1 region, 1RU/s, ¥0.00051/RU)' for 1RU/s on mooncake, 1 region, with multimaster, and no rupm", () => {
|
||||
it("should return 'Estimated cost (RMB): <b>¥0.00051 hourly / ¥0.012 daily / ¥0.37 monthly </b> (1 region, 1RU/s, ¥0.00051/RU)' for 1RU/s on mooncake, 1 region, with multimaster", () => {
|
||||
const value = PricingUtils.getEstimatedSpendHtml(
|
||||
1 /*RU/s*/,
|
||||
"mooncake" /* cloud */,
|
||||
1 /* region */,
|
||||
true /* multimaster */,
|
||||
false /* rupm */
|
||||
true /* multimaster */
|
||||
);
|
||||
expect(value).toBe(
|
||||
"Estimated cost (RMB): <b>¥0.00051 hourly / ¥0.012 daily / ¥0.37 monthly </b> (1 region, 1RU/s, ¥0.00051/RU)"
|
||||
);
|
||||
});
|
||||
|
||||
it("should return 'Estimated cost (USD): <b>$0.13 hourly / $3.07 daily / $140.16 monthly </b> (2 regions, 400RU/s, $0.00016/RU)' for 400RU/s on default cloud, 2 region, with multimaster, and no rupm", () => {
|
||||
it("should return 'Estimated cost (USD): <b>$0.13 hourly / $3.07 daily / $140.16 monthly </b> (2 regions, 400RU/s, $0.00016/RU)' for 400RU/s on default cloud, 2 region, with multimaster", () => {
|
||||
const value = PricingUtils.getEstimatedSpendHtml(
|
||||
400 /*RU/s*/,
|
||||
"default" /* cloud */,
|
||||
2 /* region */,
|
||||
true /* multimaster */,
|
||||
false /* rupm */
|
||||
true /* multimaster */
|
||||
);
|
||||
expect(value).toBe(
|
||||
"Estimated cost (USD): <b>$0.19 hourly / $4.61 daily / $140.16 monthly </b> (2 regions, 400RU/s, $0.00016/RU)"
|
||||
);
|
||||
});
|
||||
|
||||
it("should return 'Estimated cost (USD): <b>$0.064 hourly / $1.54 daily / $46.72 monthly </b> (2 regions, 400RU/s, $0.00008/RU)' for 400RU/s on default cloud, 2 region, without multimaster, and no rupm", () => {
|
||||
it("should return 'Estimated cost (USD): <b>$0.064 hourly / $1.54 daily / $46.72 monthly </b> (2 regions, 400RU/s, $0.00008/RU)' for 400RU/s on default cloud, 2 region, without multimaster", () => {
|
||||
const value = PricingUtils.getEstimatedSpendHtml(
|
||||
400 /*RU/s*/,
|
||||
"default" /* cloud */,
|
||||
2 /* region */,
|
||||
false /* multimaster */,
|
||||
false /* rupm */
|
||||
false /* multimaster */
|
||||
);
|
||||
expect(value).toBe(
|
||||
"Estimated cost (USD): <b>$0.064 hourly / $1.54 daily / $46.72 monthly </b> (2 regions, 400RU/s, $0.00008/RU)"
|
||||
@@ -308,49 +292,45 @@ describe("PricingUtils Tests", () => {
|
||||
});
|
||||
|
||||
describe("getEstimatedSpendAcknowledgeString()", () => {
|
||||
it("should return 'I acknowledge the estimated $0.0019 daily cost for the throughput above.' for 1RU/s on default cloud, 1 region, with multimaster, and no rupm", () => {
|
||||
it("should return 'I acknowledge the estimated $0.0019 daily cost for the throughput above.' for 1RU/s on default cloud, 1 region, with multimaster", () => {
|
||||
const value = PricingUtils.getEstimatedSpendAcknowledgeString(
|
||||
1 /*RU/s*/,
|
||||
"default" /* cloud */,
|
||||
1 /* region */,
|
||||
true /* multimaster */,
|
||||
false /* rupm */,
|
||||
false
|
||||
);
|
||||
expect(value).toBe("I acknowledge the estimated $0.0019 daily cost for the throughput above.");
|
||||
});
|
||||
|
||||
it("should return 'I acknowledge the estimated ¥0.012 daily cost for the throughput above.' for 1RU/s on mooncake, 1 region, with multimaster, and no rupm", () => {
|
||||
it("should return 'I acknowledge the estimated ¥0.012 daily cost for the throughput above.' for 1RU/s on mooncake, 1 region, with multimaster", () => {
|
||||
const value = PricingUtils.getEstimatedSpendAcknowledgeString(
|
||||
1 /*RU/s*/,
|
||||
"mooncake" /* cloud */,
|
||||
1 /* region */,
|
||||
true /* multimaster */,
|
||||
false /* rupm */,
|
||||
false
|
||||
);
|
||||
expect(value).toBe("I acknowledge the estimated ¥0.012 daily cost for the throughput above.");
|
||||
});
|
||||
|
||||
it("should return 'I acknowledge the estimated $3.07 daily cost for the throughput above.' for 400RU/s on default cloud, 2 region, with multimaster, and no rupm", () => {
|
||||
it("should return 'I acknowledge the estimated $3.07 daily cost for the throughput above.' for 400RU/s on default cloud, 2 region, with multimaster", () => {
|
||||
const value = PricingUtils.getEstimatedSpendAcknowledgeString(
|
||||
400 /*RU/s*/,
|
||||
"default" /* cloud */,
|
||||
2 /* region */,
|
||||
true /* multimaster */,
|
||||
false /* rupm */,
|
||||
false
|
||||
);
|
||||
expect(value).toBe("I acknowledge the estimated $4.61 daily cost for the throughput above.");
|
||||
});
|
||||
|
||||
it("should return 'I acknowledge the estimated $1.54 daily cost for the throughput above.' for 400RU/s on default cloud, 2 region, without multimaster, and no rupm", () => {
|
||||
it("should return 'I acknowledge the estimated $1.54 daily cost for the throughput above.' for 400RU/s on default cloud, 2 region, without multimaster", () => {
|
||||
const value = PricingUtils.getEstimatedSpendAcknowledgeString(
|
||||
400 /*RU/s*/,
|
||||
"default" /* cloud */,
|
||||
2 /* region */,
|
||||
false /* multimaster */,
|
||||
false /* rupm */,
|
||||
false
|
||||
);
|
||||
expect(value).toBe("I acknowledge the estimated $1.54 daily cost for the throughput above.");
|
||||
|
||||
@@ -49,21 +49,16 @@ export function getMultimasterMultiplier(numberOfRegions: number, multimasterEna
|
||||
|
||||
export function computeRUUsagePriceHourly(
|
||||
serverId: string,
|
||||
rupmEnabled: boolean,
|
||||
requestUnits: number,
|
||||
numberOfRegions: number,
|
||||
multimasterEnabled: boolean
|
||||
): number {
|
||||
const regionMultiplier: number = getRegionMultiplier(numberOfRegions, multimasterEnabled);
|
||||
const multimasterMultiplier: number = getMultimasterMultiplier(numberOfRegions, multimasterEnabled);
|
||||
|
||||
const pricePerRu = getPricePerRu(serverId);
|
||||
const pricePerRuPm = getPricePerRuPm(serverId);
|
||||
|
||||
const ruCharge = requestUnits * pricePerRu * multimasterMultiplier * regionMultiplier;
|
||||
const rupmCharge = rupmEnabled ? requestUnits * pricePerRuPm : 0;
|
||||
|
||||
return Number((ruCharge + rupmCharge).toFixed(5));
|
||||
return Number(ruCharge.toFixed(5));
|
||||
}
|
||||
|
||||
export function getPriceCurrency(serverId: string): string {
|
||||
@@ -149,14 +144,6 @@ export function getPricePerRu(serverId: string): number {
|
||||
return Constants.OfferPricing.HourlyPricing.default.Standard.PricePerRU;
|
||||
}
|
||||
|
||||
export function getPricePerRuPm(serverId: string): number {
|
||||
if (serverId === "mooncake") {
|
||||
return Constants.OfferPricing.HourlyPricing.mooncake.Standard.PricePerRUPM;
|
||||
}
|
||||
|
||||
return Constants.OfferPricing.HourlyPricing.default.Standard.PricePerRUPM;
|
||||
}
|
||||
|
||||
export function getAutoPilotV3SpendHtml(maxAutoPilotThroughputSet: number, isDatabaseThroughput: boolean): string {
|
||||
if (!maxAutoPilotThroughputSet) {
|
||||
return "";
|
||||
@@ -214,10 +201,9 @@ export function getEstimatedSpendHtml(
|
||||
throughput: number,
|
||||
serverId: string,
|
||||
regions: number,
|
||||
multimaster: boolean,
|
||||
rupmEnabled: boolean
|
||||
multimaster: boolean
|
||||
): string {
|
||||
const hourlyPrice: number = computeRUUsagePriceHourly(serverId, rupmEnabled, throughput, regions, multimaster);
|
||||
const hourlyPrice: number = computeRUUsagePriceHourly(serverId, throughput, regions, multimaster);
|
||||
const dailyPrice: number = hourlyPrice * 24;
|
||||
const monthlyPrice: number = hourlyPrice * Constants.hoursInAMonth;
|
||||
const currency: string = getPriceCurrency(serverId);
|
||||
@@ -238,12 +224,11 @@ export function getEstimatedSpendAcknowledgeString(
|
||||
serverId: string,
|
||||
regions: number,
|
||||
multimaster: boolean,
|
||||
rupmEnabled: boolean,
|
||||
isAutoscale: boolean
|
||||
): string {
|
||||
const hourlyPrice: number = isAutoscale
|
||||
? computeAutoscaleUsagePriceHourly(serverId, throughput, regions, multimaster)
|
||||
: computeRUUsagePriceHourly(serverId, rupmEnabled, throughput, regions, multimaster);
|
||||
: computeRUUsagePriceHourly(serverId, throughput, regions, multimaster);
|
||||
const dailyPrice: number = hourlyPrice * 24;
|
||||
const monthlyPrice: number = hourlyPrice * Constants.hoursInAMonth;
|
||||
const currencySign: string = getCurrencySign(serverId);
|
||||
|
||||
Reference in New Issue
Block a user