Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 84ed6eb

Browse files
committed
feat: update deleteGift return type and enhance Supabase mock for testing
1 parent eb02902 commit 84ed6eb

File tree

4 files changed

+50
-35
lines changed

4 files changed

+50
-35
lines changed

src/features/gifts/giftService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ export const addGift = async (gift: CreateGiftDTO): Promise<GiftIdea> => {
1313
return data as GiftIdea;
1414
};
1515

16-
export const deleteGift = async (id: string): Promise<void> => {
16+
export const deleteGift = async (id: string): Promise<boolean> => {
1717
const { error } = await supabase.from('gifts').delete().eq('id', id);
1818
if (error) throw error;
19+
return true;
1920
};
2021

2122
export const updateGift = async (

tests/components/settings/CalendarIntegration.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import CalendarIntegration from '@/components/settings/CalendarIntegration';
55

66
describe('CalendarIntegration Component', () => {
77
it('should render the calendar integration button', () => {
8-
const { getByText } = render(<CalendarIntegration />);
8+
const mockFn = jest.fn();
9+
const { getByText } = render(<CalendarIntegration onIntegrate={mockFn} />);
910
expect(getByText('Integrate Calendar')).toBeTruthy();
1011
});
1112

tests/features/gifts/giftService.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jest.mock('@/services/supabaseClient', () => ({
1919
delete: jest.fn(() => ({
2020
eq: jest.fn(() => ({
2121
error: null,
22+
data: true, // Mocking the expected result for deleteGift
2223
})),
2324
})),
2425
update: jest.fn(() => ({

tests/features/recipients/recipientService.test.ts

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,51 @@ import {
77
} from '@/features/recipients/recipientService';
88
import supabase from '@/services/supabaseClient';
99

10-
// Mock the entire Supabase client
11-
jest.mock('@/services/supabaseClient', () => {
12-
// Mock implementation functions
13-
const mockSingle = jest.fn();
14-
const mockEq = jest.fn(() => ({ single: mockSingle }));
15-
const mockSelect = jest.fn(() => ({ eq: mockEq, single: mockSingle }));
16-
const mockInsert = jest.fn(() => ({ single: mockSingle }));
17-
const mockUpdate = jest.fn(() => ({ eq: mockEq }));
18-
const mockDelete = jest.fn(() => ({ eq: mockEq }));
19-
20-
// From function returns an object with all the chainable methods
21-
const mockFrom = jest.fn(() => ({
22-
select: mockSelect,
23-
insert: mockInsert,
24-
update: mockUpdate,
25-
delete: mockDelete,
26-
}));
27-
28-
// Return the mock client
29-
return {
30-
from: mockFrom,
31-
// Expose the internal mocks for test access
32-
__mocks: {
33-
from: mockFrom,
34-
select: mockSelect,
35-
insert: mockInsert,
36-
update: mockUpdate,
37-
delete: mockDelete,
38-
eq: mockEq,
39-
single: mockSingle,
40-
},
41-
};
42-
});
10+
// Update the mock implementation to include `delete`, `update`, `select`, and `single` methods
11+
jest.mock('@/services/supabaseClient', () => ({
12+
from: jest.fn(() => ({
13+
select: jest.fn(() => ({
14+
eq: jest.fn(() => ({
15+
single: jest.fn(() => ({
16+
data: { name: 'John Doe' },
17+
error: null,
18+
})),
19+
})),
20+
})),
21+
insert: jest.fn(() => ({
22+
single: jest.fn(() => ({
23+
data: {
24+
id: '3',
25+
name: 'New Person',
26+
image: 'https://example.com/new-person.jpg',
27+
budget: 200,
28+
spent: 0,
29+
createdAt: '2025-05-02T12:00:00Z',
30+
},
31+
error: null,
32+
})),
33+
})),
34+
delete: jest.fn(() => ({
35+
eq: jest.fn(() => ({
36+
error: null,
37+
})),
38+
})),
39+
update: jest.fn(() => ({
40+
eq: jest.fn(() => ({
41+
single: jest.fn(() => ({
42+
data: {
43+
id: '1',
44+
name: 'Updated Name',
45+
image: 'https://example.com/john.jpg',
46+
budget: 300,
47+
spent: 50,
48+
},
49+
error: null,
50+
})),
51+
})),
52+
})),
53+
})),
54+
}));
4355

4456
// Get the mocks for easy access in tests
4557
const mocks = (supabase as any).__mocks;

0 commit comments

Comments
 (0)