import { removeToken } from './removeToken'; import { getKeytar } from './getKeytar'; jest.mock('./getKeytar'); jest.mock('./log'); // removeToken deletes the stored refresh token on logout. It must await the // adapter's async delete so a real failure propagates to the caller (the logout // handler, which reports "Error removing token!") rather than becoming an // unhandled rejection after a false "Token removed!". A missing entry is // swallowed inside the adapter, so removeToken still resolves cleanly then. describe('removeToken', () => { beforeEach(() => { jest.resetAllMocks(); }); it('deletes the token under the alkscli/alkstoken keys', async () => { const deletePassword = jest.fn().mockResolvedValue(undefined); (getKeytar as jest.Mock).mockResolvedValue({ deletePassword, getPassword: jest.fn(), setPassword: jest.fn(), }); await removeToken(); expect(deletePassword).toHaveBeenCalledWith('alkscli', 'alkstoken'); }); it('resolves without throwing when there is no entry to delete (adapter no-op)', async () => { (getKeytar as jest.Mock).mockResolvedValue({ // The adapter swallows NoEntry, so a missing entry resolves here. deletePassword: jest.fn().mockResolvedValue(undefined), getPassword: jest.fn(), setPassword: jest.fn(), }); await expect(removeToken()).resolves.toBeUndefined(); }); it('propagates a genuine deletion failure (awaited, not a floating rejection)', async () => { (getKeytar as jest.Mock).mockResolvedValue({ deletePassword: jest .fn() .mockRejectedValue(new Error('keychain access denied')), getPassword: jest.fn(), setPassword: jest.fn(), }); await expect(removeToken()).rejects.toThrow('keychain access denied'); }); });