UNPKG

@authava/react-client

Version:

React client library for seamless integration with Authava's white-label authentication service

30 lines 1.21 kB
const mockAuthavaClient = jest.fn().mockImplementation((config) => { let sessionState = { status: 'valid', user: { id: '123', email: 'test@example.com' }, expiresAt: new Date(Date.now() + 60 * 60 * 1000), // Expires in 1 hour }; const listeners = []; return { // Simulate fetching session with a slight delay getSession: jest.fn().mockImplementation(() => new Promise((resolve) => { setTimeout(() => resolve(sessionState), 100); })), // Simulate subscribing to session changes onSessionChange: jest.fn().mockImplementation((callback) => { listeners.push(callback); callback(sessionState); return () => { const index = listeners.indexOf(callback); if (index !== -1) listeners.splice(index, 1); }; }), updateSession: jest.fn().mockImplementation((newState) => { sessionState = { ...sessionState, ...newState }; listeners.forEach((callback) => callback(sessionState)); }), }; }); export { mockAuthavaClient as AuthavaClient }; //# sourceMappingURL=authava-client.js.map