diff --git a/tests/api.test.ts b/tests/api.test.ts index f8bc545..3a6d01f 100644 --- a/tests/api.test.ts +++ b/tests/api.test.ts @@ -60,15 +60,6 @@ describe('api.ts session management', () => { // Should not throw }); - test('loadSession throws on invalid JSON in credential file', async () => { - existsSyncSpy = spyOn(fs, 'existsSync').mockReturnValue(true); - readFileSyncSpy = spyOn(fs, 'readFileSync').mockReturnValue( - '{ invalid json', - ); - - await expect(loadSession()).rejects.toThrow(SyntaxError); - }); - test('loadSession throws when reading credential file fails', async () => { existsSyncSpy = spyOn(fs, 'existsSync').mockReturnValue(true); readFileSyncSpy = spyOn(fs, 'readFileSync').mockImplementation(() => { @@ -80,6 +71,19 @@ describe('api.ts session management', () => { expect.stringContaining('Failed to parse file'), ); }); + + test('loadSession throws on invalid JSON in credential file', async () => { + existsSyncSpy = spyOn(fs, 'existsSync').mockReturnValue(true); + readFileSyncSpy = spyOn(fs, 'readFileSync').mockReturnValue( + '{ invalid json', + ); + + await expect(loadSession()).rejects.toThrow(SyntaxError); + expect(console.error).toHaveBeenCalledWith( + expect.stringContaining('Failed to parse file'), + ); + }); + test('replaceSession sets session', () => { replaceSession({ token: 'new-token' }); expect(getSession()?.token).toBe('new-token');