From 2ee4b5c389563cfd043fb1155b8085dfbdaa7c36 Mon Sep 17 00:00:00 2001 From: jackiettran <41605212+jackiettran@users.noreply.github.com> Date: Thu, 6 Nov 2025 16:56:17 -0500 Subject: [PATCH] fixed map tests --- .gitignore | 1 + backend/tests/unit/routes/maps.test.js | 81 ++++++++++++++++++++------ frontend/src/pages/Owning.tsx | 20 +++---- 3 files changed, 75 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index 6b11e04..0a12845 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ node_modules/ .env.test.local .env.production.local .mcp.json +.claude # Logs npm-debug.log* diff --git a/backend/tests/unit/routes/maps.test.js b/backend/tests/unit/routes/maps.test.js index 9ea65c1..f4a2313 100644 --- a/backend/tests/unit/routes/maps.test.js +++ b/backend/tests/unit/routes/maps.test.js @@ -1,6 +1,21 @@ const request = require('supertest'); const express = require('express'); +// Mock logger +const mockLogger = { + info: jest.fn(), + error: jest.fn(), + warn: jest.fn(), + debug: jest.fn(), + http: jest.fn(), + withRequestId: jest.fn() +}; + +// Set up withRequestId to return the same mock logger +mockLogger.withRequestId.mockReturnValue(mockLogger); + +jest.mock('../../../utils/logger', () => mockLogger); + // Mock dependencies jest.mock('../../../services/googleMapsService', () => ({ getPlacesAutocomplete: jest.fn(), @@ -136,9 +151,11 @@ describe('Maps Routes', () => { error: 'Maps service temporarily unavailable', details: 'Configuration issue' }); - expect(consoleErrorSpy).toHaveBeenCalledWith( - 'Maps service error:', - 'API key not configured' + expect(mockLogger.error).toHaveBeenCalledWith( + 'Maps service error', + expect.objectContaining({ + error: 'API key not configured' + }) ); }); @@ -216,8 +233,13 @@ describe('Maps Routes', () => { } ); - expect(consoleLogSpy).toHaveBeenCalledWith( - 'Places Autocomplete: user=1, query_length=8, results=2' + expect(mockLogger.info).toHaveBeenCalledWith( + 'Places Autocomplete request', + expect.objectContaining({ + userId: 1, + queryLength: 8, + resultsCount: 2 + }) ); }); @@ -281,8 +303,11 @@ describe('Maps Routes', () => { expect(response.status).toBe(200); // Should log with user ID - expect(consoleLogSpy).toHaveBeenCalledWith( - expect.stringContaining('user=1') + expect(mockLogger.info).toHaveBeenCalledWith( + 'Places Autocomplete request', + expect.objectContaining({ + userId: 1 + }) ); }); @@ -297,8 +322,13 @@ describe('Maps Routes', () => { expect(response.status).toBe(200); expect(response.body).toEqual({ predictions: [] }); - expect(consoleLogSpy).toHaveBeenCalledWith( - 'Places Autocomplete: user=1, query_length=17, results=0' + expect(mockLogger.info).toHaveBeenCalledWith( + 'Places Autocomplete request', + expect.objectContaining({ + userId: 1, + queryLength: 17, + resultsCount: 0 + }) ); }); @@ -313,8 +343,13 @@ describe('Maps Routes', () => { expect(response.status).toBe(200); expect(response.body).toEqual({}); - expect(consoleLogSpy).toHaveBeenCalledWith( - 'Places Autocomplete: user=1, query_length=4, results=0' + expect(mockLogger.info).toHaveBeenCalledWith( + 'Places Autocomplete request', + expect.objectContaining({ + userId: 1, + queryLength: 4, + resultsCount: 0 + }) ); }); }); @@ -351,8 +386,12 @@ describe('Maps Routes', () => { { sessionToken: 'session123' } ); - expect(consoleLogSpy).toHaveBeenCalledWith( - 'Place Details: user=1, placeId=ChIJ123abc...' + expect(mockLogger.info).toHaveBeenCalledWith( + 'Place Details request', + expect.objectContaining({ + userId: 1, + placeIdPrefix: 'ChIJ123abc...' + }) ); }); @@ -410,8 +449,12 @@ describe('Maps Routes', () => { .send({ placeId: longPlaceId }); expect(response.status).toBe(200); - expect(consoleLogSpy).toHaveBeenCalledWith( - `Place Details: user=1, placeId=${longPlaceId.substring(0, 10)}...` + expect(mockLogger.info).toHaveBeenCalledWith( + 'Place Details request', + expect.objectContaining({ + userId: 1, + placeIdPrefix: longPlaceId.substring(0, 10) + '...' + }) ); }); @@ -465,8 +508,12 @@ describe('Maps Routes', () => { { componentRestrictions: { country: 'US' } } ); - expect(consoleLogSpy).toHaveBeenCalledWith( - 'Geocoding: user=1, address_length=25' + expect(mockLogger.info).toHaveBeenCalledWith( + 'Geocoding request', + expect.objectContaining({ + userId: 1, + addressLength: 25 + }) ); }); diff --git a/frontend/src/pages/Owning.tsx b/frontend/src/pages/Owning.tsx index 57ae1d3..6b082c0 100644 --- a/frontend/src/pages/Owning.tsx +++ b/frontend/src/pages/Owning.tsx @@ -287,12 +287,7 @@ const Owning: React.FC = () => { return (