Skip to content

Commit f1cbb17

Browse files
authored
Merge pull request #14 from DataChefHQ/bugfix/monthly-limit-range-validation
fix: monthly limit range validation
2 parents eb5dab0 + 3b877ac commit f1cbb17

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/application-cost-monitoring.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ export class ApplicationCostMonitoring extends IBudgetStrategy {
4343
*/
4444
constructor(stack: Stack, props: IApplicationCostMonitoringProps) {
4545
super(stack, props);
46+
47+
if (props.monthlyLimitInDollars < 30) {
48+
throw RangeError(
49+
"monthlyLimitInDollars must be greater than equal to 30."
50+
);
51+
}
52+
4653
this.applicationName = props.applicationName;
4754
this.otherStacks = props.otherStacksIncludedInBudget ?? [];
4855
}

test/application-cost-monitoring.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ describe("An ApplicationCostMonitoring", () => {
2525
subject = Template.fromStack(mockAppFirstStack);
2626
});
2727

28+
it("should throw range error if the monthly budget is less than $30", () => {
29+
const mockApp = new App();
30+
const mockAppFirstStack = new Stack(mockApp, "mocked-first-stack", {});
31+
32+
expect(() => {
33+
new ApplicationCostMonitoring(mockAppFirstStack, {
34+
applicationName: "mock-application",
35+
monthlyLimitInDollars: 29,
36+
defaultTopic: "mocked-topic",
37+
subscribers: ["[email protected]"],
38+
});
39+
}).toThrow(RangeError);
40+
});
41+
2842
it("should creates multiple aws budgets", () => {
2943
subject.resourceCountIs(AWSResourceType.Budget, 6);
3044
});

0 commit comments

Comments
 (0)