UNPKG

matterbridge-roborock-vacuum-plugin

Version:
43 lines 1.91 kB
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { AuthenticationStateRepository } from '../../../services/authentication/AuthenticationStateRepository.js'; import { asPartial, createMockLocalStorage } from '../../helpers/testUtils.js'; describe('AuthenticationStateRepository', () => { let persist; let repo; beforeEach(() => { vi.clearAllMocks(); persist = createMockLocalStorage(); repo = new AuthenticationStateRepository(persist); }); afterEach(() => { vi.clearAllMocks(); }); describe('getAuthState', () => { it('should return the stored auth state', async () => { const state = asPartial({ email: 'user@example.com' }); vi.mocked(persist.getItem).mockResolvedValue(state); const result = await repo.getAuthState(); expect(persist.getItem).toHaveBeenCalledWith('authenticateFlowState'); expect(result).toBe(state); }); it('should return undefined when no state is stored', async () => { vi.mocked(persist.getItem).mockResolvedValue(undefined); const result = await repo.getAuthState(); expect(result).toBeUndefined(); }); }); describe('saveAuthState', () => { it('should persist the auth state with correct key', async () => { const state = asPartial({ email: 'user@example.com' }); await repo.saveAuthState(state); expect(persist.setItem).toHaveBeenCalledWith('authenticateFlowState', state); }); }); describe('clearAuthState', () => { it('should remove the persisted auth state', async () => { await repo.clearAuthState(); expect(persist.removeItem).toHaveBeenCalledWith('authenticateFlowState'); }); }); }); //# sourceMappingURL=AuthenticationStateRepository.test.js.map