Skip to content

Commit bd981fc

Browse files
author
divyav-aot
committed
lint errors fixed
1 parent 1ee1183 commit bd981fc

7 files changed

Lines changed: 218 additions & 164 deletions

File tree

web/src/pages/Users.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ const Users = () => {
3939
await dispatch(saveUser(formData));
4040
setMessage("User saved successfully!");
4141
dispatch(fetchUsers());
42-
} catch (_error) {
43-
setMessage("Error saving user.");
42+
} catch (error) {
43+
console.error("Error saving user:", error);
44+
setMessage(
45+
"Error saving user." +
46+
(error instanceof Error && error.message ? ` ${error.message}` : "")
47+
);
4448
}
4549
};
4650

web/src/services/statesService.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { apiRequest, apiSuccess, apiFailure } from "../store/apiSlice";
33
import { State } from "../types/state";
44
import { AppDispatch } from "../store";
55

6-
const API_URL = import.meta.env.VITE_PYTHON_API_BASE_URL;
6+
const API_URL =
7+
import.meta.env.VITE_PYTHON_API_BASE_URL || "http://localhost:8300/api/v1";
78

89
export const saveState =
910
(stateData: State) => async (dispatch: AppDispatch) => {

web/src/services/userService.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { apiRequest, apiSuccess, apiFailure } from "../store/apiSlice";
33
import { User } from "../types/user";
44
import { AppDispatch } from "../store";
55

6-
const API_URL = import.meta.env.VITE_API_BASE_URL;
6+
const API_URL = import.meta.env.VITE_API_BASE_URL || "http://localhost:5000";
77

88
export const saveUser = (userData: User) => async (dispatch: AppDispatch) => {
99
const key = "saveUser";
@@ -22,9 +22,7 @@ export const fetchUsers = () => async (dispatch: AppDispatch) => {
2222
const key = "fetchUsers";
2323
dispatch(apiRequest(key));
2424
try {
25-
const response = await axios.get(
26-
import.meta.env.VITE_API_BASE_URL + "/users/"
27-
);
25+
const response = await axios.get(API_URL + "/users/");
2826
dispatch(apiSuccess({ key, data: response.data }));
2927
} catch (error: unknown) {
3028
dispatch(apiFailure({ key, error: (error as AxiosError).message }));

web/src/tests/integration/api-integration.test.ts

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
import { describe, test, expect, beforeAll, afterAll, beforeEach } from 'vitest';
2-
import { testNodeApi, testPythonApi, setupIntegrationTestEnv, cleanupIntegrationTestEnv } from '../utils/apiTestUtils';
3-
import { createTestUser, createTestState } from '../utils/testUtils';
1+
import { describe, test, expect, beforeAll, afterAll } from "vitest";
2+
import {
3+
testNodeApi,
4+
testPythonApi,
5+
setupIntegrationTestEnv,
6+
cleanupIntegrationTestEnv,
7+
} from "../utils/apiTestUtils";
8+
import { createTestUser, createTestState } from "../utils/testUtils";
49

510
// These tests require the backends to be running
611
// Run with: npm run test:integration
7-
describe('API Integration Tests', () => {
12+
describe("API Integration Tests", () => {
813
beforeAll(() => {
914
setupIntegrationTestEnv();
1015
});
@@ -13,8 +18,8 @@ describe('API Integration Tests', () => {
1318
cleanupIntegrationTestEnv();
1419
});
1520

16-
describe('Node.js Backend API Integration', () => {
17-
test('should connect to Node.js backend health endpoint', async () => {
21+
describe("Node.js Backend API Integration", () => {
22+
test("should connect to Node.js backend health endpoint", async () => {
1823
try {
1924
const response = await testNodeApi.healthCheck();
2025
expect(response.status).toBe(200);
@@ -24,23 +29,23 @@ describe('API Integration Tests', () => {
2429
}
2530
});
2631

27-
test('should fetch users from Node.js backend', async () => {
32+
test("should fetch users from Node.js backend", async () => {
2833
try {
2934
const response = await testNodeApi.getUsers();
3035
expect(response.status).toBe(200);
31-
expect(response.data).toHaveProperty('users');
36+
expect(response.data).toHaveProperty("users");
3237
expect(Array.isArray(response.data.users)).toBe(true);
3338
} catch (error) {
3439
expect(true).toBe(true);
3540
}
3641
});
3742

38-
test('should create user via Node.js backend', async () => {
43+
test("should create user via Node.js backend", async () => {
3944
try {
4045
const testUser = createTestUser({
41-
firstName: 'Integration',
42-
lastName: 'Test',
43-
dateOfBirth: '1990-01-01',
46+
firstName: "Integration",
47+
lastName: "Test",
48+
dateOfBirth: "1990-01-01",
4449
});
4550

4651
const response = await testNodeApi.createUser(testUser);
@@ -51,11 +56,11 @@ describe('API Integration Tests', () => {
5156
}
5257
});
5358

54-
test('should handle validation errors from Node.js backend', async () => {
59+
test("should handle validation errors from Node.js backend", async () => {
5560
try {
5661
const invalidUser = createTestUser({
57-
firstName: '', // Invalid: empty first name
58-
lastName: '', // Invalid: empty last name
62+
firstName: "", // Invalid: empty first name
63+
lastName: "", // Invalid: empty last name
5964
});
6065

6166
await testNodeApi.createUser(invalidUser);
@@ -68,8 +73,8 @@ describe('API Integration Tests', () => {
6873
});
6974
});
7075

71-
describe('Python Backend API Integration', () => {
72-
test('should connect to Python backend health endpoint', async () => {
76+
describe("Python Backend API Integration", () => {
77+
test("should connect to Python backend health endpoint", async () => {
7378
try {
7479
const response = await testPythonApi.healthCheck();
7580
expect(response.status).toBe(200);
@@ -78,7 +83,7 @@ describe('API Integration Tests', () => {
7883
}
7984
});
8085

81-
test('should fetch states from Python backend', async () => {
86+
test("should fetch states from Python backend", async () => {
8287
try {
8388
const response = await testPythonApi.getStates();
8489
expect(response.status).toBe(200);
@@ -88,11 +93,11 @@ describe('API Integration Tests', () => {
8893
}
8994
});
9095

91-
test('should create state via Python backend', async () => {
96+
test("should create state via Python backend", async () => {
9297
try {
9398
const testState = createTestState({
94-
name: 'Integration Test State',
95-
description: 'Created by integration test',
99+
name: "Integration Test State",
100+
description: "Created by integration test",
96101
is_active: true,
97102
sort_order: 999,
98103
});
@@ -105,11 +110,11 @@ describe('API Integration Tests', () => {
105110
}
106111
});
107112

108-
test('should handle validation errors from Python backend', async () => {
113+
test("should handle validation errors from Python backend", async () => {
109114
try {
110115
const invalidState = createTestState({
111-
name: '', // Invalid: empty name
112-
description: '',
116+
name: "", // Invalid: empty name
117+
description: "",
113118
});
114119

115120
await testPythonApi.createState(invalidState);
@@ -122,8 +127,8 @@ describe('API Integration Tests', () => {
122127
});
123128
});
124129

125-
describe('Cross-Backend Integration', () => {
126-
test('should verify both backends are accessible', async () => {
130+
describe("Cross-Backend Integration", () => {
131+
test("should verify both backends are accessible", async () => {
127132
let nodeBackendAvailable = false;
128133
let pythonBackendAvailable = false;
129134

@@ -145,7 +150,7 @@ describe('API Integration Tests', () => {
145150
expect(nodeBackendAvailable || pythonBackendAvailable).toBe(true);
146151
});
147152

148-
test('should handle different response formats from different backends', async () => {
153+
test("should handle different response formats from different backends", async () => {
149154
let nodeResponse = null;
150155
let pythonResponse = null;
151156

@@ -166,7 +171,7 @@ describe('API Integration Tests', () => {
166171
// If both responses are available, verify they have different structures
167172
if (nodeResponse && pythonResponse) {
168173
// Node.js returns { users: [...] }
169-
expect(nodeResponse).toHaveProperty('users');
174+
expect(nodeResponse).toHaveProperty("users");
170175
// Python returns [...] directly
171176
expect(Array.isArray(pythonResponse)).toBe(true);
172177
}

0 commit comments

Comments
 (0)