fixed map tests

This commit is contained in:
jackiettran
2025-11-06 16:56:17 -05:00
parent 2956b79f34
commit 2ee4b5c389
3 changed files with 75 additions and 27 deletions

1
.gitignore vendored
View File

@@ -18,6 +18,7 @@ node_modules/
.env.test.local
.env.production.local
.mcp.json
.claude
# Logs
npm-debug.log*

View File

@@ -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
})
);
});

View File

@@ -287,12 +287,7 @@ const Owning: React.FC = () => {
return (
<div className="container mt-4">
<div className="d-flex justify-content-between align-items-center mb-4">
<h1>Owning</h1>
<Link to="/create-item" className="btn btn-primary">
Add New Item
</Link>
</div>
<h1 className="mb-4">Owning</h1>
{error && (
<div className="alert alert-danger" role="alert">
@@ -487,10 +482,15 @@ const Owning: React.FC = () => {
</div>
)}
<h4 className="mb-3">
<div className="d-flex justify-content-between align-items-center mb-3">
<h4 className="mb-0">
<i className="bi bi-list-ul me-2"></i>
Listings
</h4>
<Link to="/create-item" className="btn btn-primary">
Add New Item
</Link>
</div>
{listings.length === 0 ? (
<div className="text-center py-5">