@@ -16,13 +16,13 @@ jest.mock('@/services/supabaseClient', () => {
1616 const mockInsert = jest . fn ( ( ) => ( { single : mockSingle } ) ) ;
1717 const mockUpdate = jest . fn ( ( ) => ( { eq : mockEq } ) ) ;
1818 const mockDelete = jest . fn ( ( ) => ( { eq : mockEq } ) ) ;
19-
19+
2020 // From function returns an object with all the chainable methods
2121 const mockFrom = jest . fn ( ( ) => ( {
2222 select : mockSelect ,
2323 insert : mockInsert ,
2424 update : mockUpdate ,
25- delete : mockDelete
25+ delete : mockDelete ,
2626 } ) ) ;
2727
2828 // Return the mock client
@@ -36,14 +36,83 @@ jest.mock('@/services/supabaseClient', () => {
3636 update : mockUpdate ,
3737 delete : mockDelete ,
3838 eq : mockEq ,
39- single : mockSingle
40- }
39+ single : mockSingle ,
40+ } ,
4141 } ;
4242} ) ;
4343
4444// Get the mocks for easy access in tests
4545const mocks = ( supabase as any ) . __mocks ;
4646
47+ // Define mock data objects to resolve the errors
48+
49+ const mockRecipients = [
50+ {
51+ id : '1' ,
52+ name : 'John Doe' ,
53+ image : 'https://example.com/john.jpg' ,
54+ budget : 100 ,
55+ spent : 50 ,
56+ } ,
57+ {
58+ id : '2' ,
59+ name : 'Jane Smith' ,
60+ image : 'https://example.com/jane.jpg' ,
61+ budget : 150 ,
62+ spent : 75 ,
63+ } ,
64+ ] ;
65+
66+ const mockResult = {
67+ id : '3' ,
68+ name : 'New Person' ,
69+ image : 'https://example.com/new-person.jpg' ,
70+ budget : 200 ,
71+ spent : 0 ,
72+ createdAt : '2025-05-02T12:00:00Z' ,
73+ } ;
74+
75+ // Fixing the mock implementation to return the expected data for each test case
76+
77+ // Update the mock implementation for `fetchRecipients`
78+ mocks . select . mockImplementation ( ( ) => ( {
79+ eq : mocks . eq ,
80+ single : jest . fn ( ) . mockResolvedValueOnce ( {
81+ data : mockRecipients ,
82+ error : null ,
83+ } ) ,
84+ } ) ) ;
85+
86+ // Update the mock implementation for `addRecipient`
87+ mocks . insert . mockImplementation ( ( ) => ( {
88+ single : jest . fn ( ) . mockResolvedValueOnce ( {
89+ data : mockResult ,
90+ error : null ,
91+ } ) ,
92+ } ) ) ;
93+
94+ // Update the mock implementation for `updateRecipient`
95+ mocks . update . mockImplementation ( ( ) => ( {
96+ eq : jest . fn ( ) . mockResolvedValueOnce ( {
97+ data : mockResult ,
98+ error : null ,
99+ } ) ,
100+ } ) ) ;
101+
102+ // Update the mock implementation for `findRecipientById`
103+ mocks . select . mockImplementation ( ( ) => ( {
104+ eq : jest . fn ( ) . mockResolvedValueOnce ( {
105+ data : { name : 'John Doe' } ,
106+ error : null ,
107+ } ) ,
108+ } ) ) ;
109+
110+ // Update the mock implementation for error cases
111+ mocks . single . mockImplementation ( ( ) => ( {
112+ data : null ,
113+ error : new Error ( 'Failed to fetch recipients' ) ,
114+ } ) ) ;
115+
47116describe ( 'recipientService' , ( ) => {
48117 beforeEach ( ( ) => {
49118 jest . clearAllMocks ( ) ;
0 commit comments