Skip to content

Commit 3048bb3

Browse files
committed
Add tests for nested conditions and mixed variable handling in extractTechnicalConstructs
1 parent 2640d1c commit 3048bb3

7 files changed

Lines changed: 26 additions & 4 deletions

File tree

apps/backend/src/services/__tests__/technical-parser.service.unit.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,26 @@ describe("extractTechnicalConstructs - comparison operators", () => {
117117
},
118118
});
119119
});
120+
121+
it("handles nested conditions with parentheses", () => {
122+
const rpyContent = "if (strength >= 5 or magic > 10):";
123+
const result = extractTechnicalConstructs(rpyContent, 0);
124+
expect(result.conditions).toBeDefined();
125+
expect(result.conditions?.stats).toEqual({
126+
strength: { value: 5, operator: ">=" },
127+
magic: { value: 10, operator: ">" },
128+
});
129+
});
130+
131+
it("extracts stats when mixed with variables", () => {
132+
const rpyContent = "if strength >= 5 and flag_luna:";
133+
const result = extractTechnicalConstructs(rpyContent, 0);
134+
expect(result.conditions).toBeDefined();
135+
expect(result.conditions?.stats).toEqual({
136+
strength: { value: 5, operator: ">=" },
137+
});
138+
expect(result.conditions?.variables).toEqual(["flag_luna"]);
139+
});
120140
});
121141

122142
describe("extractTechnicalConstructs - if/elif conditions with deltas", () => {

apps/backend/src/services/rpy-parser.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,6 +1976,7 @@ export function extractTechnicalConstructs(
19761976
.trim();
19771977

19781978
// Extract stat comparisons: e.g., "strength >= 5" or "magic < 10"
1979+
// Limitations: Does not handle variable comparisons (e.g., "strength >= max_value")
19791980
const statRegex = /([a-zA-Z_][a-zA-Z0-9_]*)\s*(>=|<=|>|<|==|!=)\s*(-?\d+)/g;
19801981
let statMatch;
19811982
while ((statMatch = statRegex.exec(conditionExpr)) !== null) {

apps/frontend/src/contexts/__tests__/ThemeContext.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const localStorageMock = (() => {
2626
};
2727
})();
2828

29-
Object.defineProperty(global, "localStorage", {
29+
Object.defineProperty(globalThis, "localStorage", {
3030
value: localStorageMock,
3131
});
3232

apps/frontend/src/lib/api/__tests__/auth.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { LoginCredentials, RegisterCredentials } from "../auth";
1010

1111
// Mock fetch globally
1212
const mockFetch = vi.fn();
13-
global.fetch = mockFetch;
13+
globalThis.fetch = mockFetch;
1414

1515
describe("Auth API", () => {
1616
beforeEach(() => {

apps/frontend/src/lib/api/__tests__/gitlab.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { gitlabApi } from "../gitlab.js";
1010

1111
// Mock fetch
1212
const mockFetch = vi.fn();
13-
global.fetch = mockFetch as unknown as typeof fetch;
13+
globalThis.fetch = mockFetch as unknown as typeof fetch;
1414

1515
describe("GitLab API Client", () => {
1616
afterEach(() => {

apps/frontend/src/lib/api/__tests__/variables.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { Variable } from "@branchforge/shared";
1111

1212
// Mock fetch globally
1313
const mockFetch = vi.fn();
14-
global.fetch = mockFetch;
14+
globalThis.fetch = mockFetch;
1515

1616
describe("Variables API", () => {
1717
const mockVariable: Variable = {

apps/frontend/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"noUnusedLocals": true,
1616
"noUnusedParameters": true,
1717
"noFallthroughCasesInSwitch": true,
18+
"types": ["vitest/globals", "@testing-library/jest-dom"],
1819
"paths": {
1920
"@/*": ["./src/*"]
2021
}

0 commit comments

Comments
 (0)