import { getAuth } from './getAuth'; import { getToken } from './state/token'; jest.mock('./state/token'); jest.mock('./log'); describe('getAuth', () => { afterEach(() => { jest.resetAllMocks(); }); describe('when a refresh token exists', () => { beforeEach(() => { (getToken as jest.Mock).mockResolvedValue('my-refresh-token'); }); it('returns the token auth object unchanged', async () => { const auth = await getAuth(); expect(auth).toEqual({ token: 'my-refresh-token' }); }); }); describe('when no refresh token exists', () => { beforeEach(() => { (getToken as jest.Mock).mockResolvedValue(undefined); }); it('throws an error directing the user to login2fa', async () => { await expect(getAuth()).rejects.toThrow(/login2fa/); }); it('throws an error directing the user to configure', async () => { await expect(getAuth()).rejects.toThrow(/configure/); }); it('rejects (no basic-auth fallback / no password prompt)', async () => { await expect(getAuth()).rejects.toThrow(); }); }); });