@@ -16,13 +16,13 @@ jest.mock('@/services/supabaseClient', () => {
16
16
const mockInsert = jest . fn ( ( ) => ( { single : mockSingle } ) ) ;
17
17
const mockUpdate = jest . fn ( ( ) => ( { eq : mockEq } ) ) ;
18
18
const mockDelete = jest . fn ( ( ) => ( { eq : mockEq } ) ) ;
19
-
19
+
20
20
// From function returns an object with all the chainable methods
21
21
const mockFrom = jest . fn ( ( ) => ( {
22
22
select : mockSelect ,
23
23
insert : mockInsert ,
24
24
update : mockUpdate ,
25
- delete : mockDelete
25
+ delete : mockDelete ,
26
26
} ) ) ;
27
27
28
28
// Return the mock client
@@ -36,14 +36,83 @@ jest.mock('@/services/supabaseClient', () => {
36
36
update : mockUpdate ,
37
37
delete : mockDelete ,
38
38
eq : mockEq ,
39
- single : mockSingle
40
- }
39
+ single : mockSingle ,
40
+ } ,
41
41
} ;
42
42
} ) ;
43
43
44
44
// Get the mocks for easy access in tests
45
45
const mocks = ( supabase as any ) . __mocks ;
46
46
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
+
47
116
describe ( 'recipientService' , ( ) => {
48
117
beforeEach ( ( ) => {
49
118
jest . clearAllMocks ( ) ;
0 commit comments