cosmos-explorer/src/Common/OfferUtility.test.ts

65 lines
1.7 KiB
TypeScript
Raw Normal View History

2020-11-19 17:13:11 -08:00
import * as OfferUtility from "./OfferUtility";
import { SDKOfferDefinition, Offer } from "../Contracts/DataModels";
import { OfferResponse } from "@azure/cosmos";
describe("parseSDKOfferResponse", () => {
it("manual throughput", () => {
const mockOfferDefinition = {
content: {
offerThroughput: 500,
collectionThroughputInfo: {
minimumRUForCollection: 400,
2021-01-20 09:15:01 -06:00
numPhysicalPartitions: 1,
},
2020-11-19 17:13:11 -08:00
},
2021-01-20 09:15:01 -06:00
id: "test",
2020-11-19 17:13:11 -08:00
} as SDKOfferDefinition;
const mockResponse = {
2021-01-20 09:15:01 -06:00
resource: mockOfferDefinition,
2020-11-19 17:13:11 -08:00
} as OfferResponse;
const expectedResult: Offer = {
manualThroughput: 500,
autoscaleMaxThroughput: undefined,
minimumThroughput: 400,
id: "test",
offerDefinition: mockOfferDefinition,
2021-01-20 09:15:01 -06:00
offerReplacePending: false,
2020-11-19 17:13:11 -08:00
};
expect(OfferUtility.parseSDKOfferResponse(mockResponse)).toEqual(expectedResult);
});
it("autoscale throughput", () => {
const mockOfferDefinition = {
content: {
offerThroughput: 400,
collectionThroughputInfo: {
minimumRUForCollection: 400,
2021-01-20 09:15:01 -06:00
numPhysicalPartitions: 1,
2020-11-19 17:13:11 -08:00
},
offerAutopilotSettings: {
2021-01-20 09:15:01 -06:00
maxThroughput: 5000,
},
2020-11-19 17:13:11 -08:00
},
2021-01-20 09:15:01 -06:00
id: "test",
2020-11-19 17:13:11 -08:00
} as SDKOfferDefinition;
const mockResponse = {
2021-01-20 09:15:01 -06:00
resource: mockOfferDefinition,
2020-11-19 17:13:11 -08:00
} as OfferResponse;
const expectedResult: Offer = {
manualThroughput: undefined,
autoscaleMaxThroughput: 5000,
minimumThroughput: 400,
id: "test",
offerDefinition: mockOfferDefinition,
2021-01-20 09:15:01 -06:00
offerReplacePending: false,
2020-11-19 17:13:11 -08:00
};
expect(OfferUtility.parseSDKOfferResponse(mockResponse)).toEqual(expectedResult);
});
});