Skip to content

Commit 6638dcb

Browse files
authored
tests: fix thresholdEdgeCases.test.ts TypeScript errors (#51)
1 parent 0490765 commit 6638dcb

2 files changed

Lines changed: 27 additions & 9 deletions

File tree

tests/thresholdEdgeCases.test.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Documents and validates contract policy for boundary MTTR inputs.
44
*/
55

6+
import { describe, it, expect } from '@jest/globals';
7+
8+
69
interface SlaConfig {
710
threshold: number; // minutes
811
penaltyBps: number;
@@ -18,13 +21,16 @@ function evaluateSla(
1821
return mttr <= config.threshold ? "met" : "violated";
1922
}
2023

21-
const CONFIGS: Record<string, SlaConfig> = {
24+
type Severity = "critical" | "high" | "medium";
25+
26+
const CANONICAL_SEVERITIES = ["critical", "high", "medium"] as const;
27+
28+
const CONFIGS: Record<Severity, SlaConfig> = {
2229
critical: { threshold: 60, penaltyBps: 500 },
2330
high: { threshold: 240, penaltyBps: 300 },
2431
medium: { threshold: 480, penaltyBps: 100 },
2532
};
26-
27-
const CANONICAL_SEVERITIES = ["critical", "high", "medium"] as const;
33+
2834

2935
describe("SC-046 Threshold Edge Cases", () => {
3036
it("zero MTTR always meets any positive threshold", () => {
@@ -57,10 +63,11 @@ describe("SC-046 Threshold Edge Cases", () => {
5763
});
5864

5965
it("MTTR one above threshold is violated", () => {
60-
for (const severity of CANONICAL_SEVERITIES) {
61-
const cfg = CONFIGS[severity];
62-
expect(evaluateSla(cfg.threshold + 1, cfg)).toBe("violated");
63-
}
66+
for (const severity of CANONICAL_SEVERITIES) {
67+
const cfg = CONFIGS[severity];
68+
expect(evaluateSla(cfg.threshold + 1, cfg)).toBe("violated");
69+
}
70+
6471
});
6572

6673
it("exact threshold does not drift into violation due to boundary math", () => {
@@ -76,7 +83,7 @@ describe("SC-046 Threshold Edge Cases", () => {
7683
});
7784

7885
it("negative MTTR is rejected as invalid", () => {
79-
expect(evaluateSla(-1, CONFIGS.critical)).toBe("invalid");
86+
expect(evaluateSla(-1, CONFIGS['critical'])).toBe("invalid");
8087
});
8188

8289
it("uses a documented canonical severity order for backend fixtures", () => {
@@ -86,6 +93,6 @@ describe("SC-046 Threshold Edge Cases", () => {
8693

8794
it("near-zero MTTR (0.001) treated as zero — rounds to met", () => {
8895
const nearZero = Math.floor(0.001); // contract uses integer minutes
89-
expect(evaluateSla(nearZero, CONFIGS.critical)).toBe("met");
96+
expect(evaluateSla(nearZero, CONFIGS['critical'])).toBe("met");
9097
});
9198
});

types/jest-globals.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
declare module '@jest/globals' {
2+
export function describe(name: string, fn: () => void): void;
3+
export function it(name: string, fn: () => void): void;
4+
export function test(name: string, fn: () => void): void;
5+
export function beforeAll(fn: () => void): void;
6+
export function afterAll(fn: () => void): void;
7+
export function beforeEach(fn: () => void): void;
8+
export function afterEach(fn: () => void): void;
9+
export function expect(actual?: any): any;
10+
export const jest: any;
11+
}

0 commit comments

Comments
 (0)