ensure mocks are used wherever possible, more test fixes
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 1h7m5s
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 1h7m5s
This commit is contained in:
@@ -6,6 +6,7 @@ import { http, HttpResponse } from 'msw';
|
||||
// Ensure the module under test is NOT mocked.
|
||||
vi.unmock('./aiApiClient');
|
||||
|
||||
import { createMockFlyerItem, createMockStore } from '../tests/utils/mockFactories';
|
||||
import * as aiApiClient from './aiApiClient';
|
||||
|
||||
// 1. Mock logger to keep output clean
|
||||
@@ -235,7 +236,7 @@ describe('AI API Client (Network Mocking with MSW)', () => {
|
||||
|
||||
describe('getQuickInsights', () => {
|
||||
it('should send items as JSON in the body', async () => {
|
||||
const items = [{ item: 'apple' }];
|
||||
const items = [createMockFlyerItem({ item: 'apple' })];
|
||||
await aiApiClient.getQuickInsights(items, undefined, 'test-token');
|
||||
|
||||
expect(requestSpy).toHaveBeenCalledTimes(1);
|
||||
@@ -249,7 +250,7 @@ describe('AI API Client (Network Mocking with MSW)', () => {
|
||||
|
||||
describe('getDeepDiveAnalysis', () => {
|
||||
it('should send items as JSON in the body', async () => {
|
||||
const items = [{ item: 'apple' }];
|
||||
const items = [createMockFlyerItem({ item: 'apple' })];
|
||||
await aiApiClient.getDeepDiveAnalysis(items, undefined, 'test-token');
|
||||
|
||||
expect(requestSpy).toHaveBeenCalledTimes(1);
|
||||
@@ -263,7 +264,7 @@ describe('AI API Client (Network Mocking with MSW)', () => {
|
||||
|
||||
describe('searchWeb', () => {
|
||||
it('should send items as JSON in the body', async () => {
|
||||
const items = [{ item: 'search me' }];
|
||||
const items = [createMockFlyerItem({ item: 'search me' })];
|
||||
await aiApiClient.searchWeb(items, undefined, 'test-token');
|
||||
|
||||
expect(requestSpy).toHaveBeenCalledTimes(1);
|
||||
@@ -306,20 +307,19 @@ describe('AI API Client (Network Mocking with MSW)', () => {
|
||||
describe('planTripWithMaps', () => {
|
||||
it('should send items, store, and location as JSON in the body', async () => {
|
||||
// Create a full FlyerItem object, as the function signature requires it, not a partial.
|
||||
const items: import('../types').FlyerItem[] = [{
|
||||
const items = [createMockFlyerItem({
|
||||
flyer_item_id: 1,
|
||||
flyer_id: 1,
|
||||
item: 'bread',
|
||||
price_display: '$1.99',
|
||||
price_in_cents: 199,
|
||||
quantity: '1 loaf',
|
||||
category_name: 'Bakery',
|
||||
category_name: 'Bakery', // Factory allows overrides
|
||||
view_count: 0,
|
||||
click_count: 0,
|
||||
updated_at: new Date().toISOString(),
|
||||
created_at: new Date().toISOString(),
|
||||
}];
|
||||
const store: import('../types').Store = { store_id: 1, name: 'Test Store', created_at: new Date().toISOString() };
|
||||
})];
|
||||
|
||||
const store = createMockStore({ store_id: 1, name: 'Test Store' });
|
||||
// FIX: The mock GeolocationCoordinates object must correctly serialize to JSON,
|
||||
// mimicking the behavior of the real browser API when passed to JSON.stringify.
|
||||
// The previous toJSON method returned an empty object, causing the failure.
|
||||
|
||||
Reference in New Issue
Block a user