Refactor MainLayout to use new hooks for flyers and master items; consolidate error handling
Some checks failed
Deploy to Test Environment / deploy-to-test (push) Has been cancelled
Some checks failed
Deploy to Test Environment / deploy-to-test (push) Has been cancelled
Update error handling tests to ensure proper status assignment for errors
This commit is contained in:
@@ -35,19 +35,29 @@ describe('useWatchedItems Hook', () => {
|
||||
|
||||
// Provide a default implementation for useApi
|
||||
mockedUseApi
|
||||
.mockReturnValueOnce({ execute: mockAddWatchedItemApi, error: null } as any)
|
||||
.mockReturnValueOnce({ execute: mockRemoveWatchedItemApi, error: null } as any);
|
||||
.mockReturnValueOnce({ execute: mockAddWatchedItemApi, error: null, data: null, loading: false, isRefetching: false })
|
||||
.mockReturnValueOnce({ execute: mockRemoveWatchedItemApi, error: null, data: null, loading: false, isRefetching: false });
|
||||
|
||||
|
||||
// Provide a default implementation for the mocked hooks
|
||||
mockedUseAuth.mockReturnValue({
|
||||
user: mockUser,
|
||||
} as any);
|
||||
profile: null,
|
||||
authStatus: 'AUTHENTICATED',
|
||||
isLoading: false,
|
||||
login: vi.fn(),
|
||||
logout: vi.fn(),
|
||||
updateProfile: vi.fn(),
|
||||
});
|
||||
|
||||
mockedUseUserData.mockReturnValue({
|
||||
watchedItems: mockInitialItems,
|
||||
setWatchedItems: mockSetWatchedItems,
|
||||
} as any);
|
||||
shoppingLists: [],
|
||||
setShoppingLists: vi.fn(),
|
||||
isLoading: false,
|
||||
error: null,
|
||||
});
|
||||
});
|
||||
|
||||
it('should initialize with the watched items from useData', () => {
|
||||
@@ -85,7 +95,10 @@ describe('useWatchedItems Hook', () => {
|
||||
mockedUseApi.mockReturnValueOnce({
|
||||
execute: mockAddWatchedItemApi,
|
||||
error: new Error('API Error'),
|
||||
} as any);
|
||||
data: null,
|
||||
loading: false,
|
||||
isRefetching: false,
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useWatchedItems());
|
||||
|
||||
@@ -121,8 +134,8 @@ describe('useWatchedItems Hook', () => {
|
||||
|
||||
it('should set an error message if the API call fails', async () => {
|
||||
// Re-mock useApi for this specific error test case
|
||||
mockedUseApi.mockReturnValueOnce({ execute: vi.fn(), error: null } as any) // for add
|
||||
.mockReturnValueOnce({ execute: vi.fn(), error: new Error('Deletion Failed') } as any); // for remove
|
||||
mockedUseApi.mockReturnValueOnce({ execute: vi.fn(), error: null, data: null, loading: false, isRefetching: false }) // for add
|
||||
.mockReturnValueOnce({ execute: vi.fn(), error: new Error('Deletion Failed'), data: null, loading: false, isRefetching: false }); // for remove
|
||||
|
||||
const { result } = renderHook(() => useWatchedItems());
|
||||
|
||||
@@ -136,7 +149,15 @@ describe('useWatchedItems Hook', () => {
|
||||
});
|
||||
|
||||
it('should not perform actions if the user is not authenticated', async () => {
|
||||
mockedUseAuth.mockReturnValue({ user: null } as any);
|
||||
mockedUseAuth.mockReturnValue({
|
||||
user: null,
|
||||
profile: null,
|
||||
authStatus: 'SIGNED_OUT',
|
||||
isLoading: false,
|
||||
login: vi.fn(),
|
||||
logout: vi.fn(),
|
||||
updateProfile: vi.fn(),
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useWatchedItems());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user