diff --git a/frontend/jest.setup.ts b/frontend/jest.setup.ts index a007db086..f2d3eb4c0 100644 --- a/frontend/jest.setup.ts +++ b/frontend/jest.setup.ts @@ -1,4 +1,5 @@ import '@testing-library/jest-dom' +import { Session } from 'next-auth' Element.prototype.scrollIntoView = () => {} @@ -15,3 +16,32 @@ Object.defineProperty(window, 'matchMedia', { dispatchEvent: jest.fn() })) }) + +// **Global Mocks** + +// Due to Jest transformer issues, we mock next-auth's getServerSession and the authOptions directly: +export const mockSession: Session = { + expires: new Date(Date.now() + 2 * 86400).toISOString(), + user: { + name: 'user', + id: 0, + username: 'username', + email: 'user@igalia.com', + firstName: 'user', + lastName: 'last name', + capacities: [], + roles: ['staff', 'admin'], + authorizedScopes: ['client:read'] + } +} + +jest.mock('./src/app/api/auth/[...nextauth]/route', () => { + return { authOptions: () => {} } +}) + +jest.mock('next-auth', () => { + return { + __esModule: true, + getServerSession: jest.fn(() => Promise.resolve(mockSession)) + } +})