fix: resolve ESLint errors for CI
- Remove unused imports (Flag, Tag, Hash, User, FolderPlus, Check, Plus, Link, cn, formatDate, getPriorityLabel) - Remove unused variable (inbox in Sidebar) - Fix empty catch block with comment - Replace any types with proper Mock/Record types in tests - Suppress set-state-in-effect for intentional form state sync - Remove unused get parameter from zustand store
This commit is contained in:
@@ -1,25 +1,23 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import type { Mock } from 'vitest';
|
||||
|
||||
// We need to test the ApiClient class, so we import the module fresh
|
||||
// The api.ts uses import.meta.env.PROD which is false in test
|
||||
// So API_BASE = '/api' and AUTH_BASE = ''
|
||||
|
||||
let ApiClient: any;
|
||||
let api: any;
|
||||
let api: Record<string, (...args: unknown[]) => unknown>;
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
vi.stubGlobal('fetch', vi.fn());
|
||||
const mod = await import('@/lib/api');
|
||||
api = mod.api;
|
||||
// Get the class from the singleton
|
||||
ApiClient = (api as any).constructor;
|
||||
api = mod.api as unknown as Record<string, (...args: unknown[]) => unknown>;
|
||||
});
|
||||
|
||||
function mockFetchResponse(data: any, ok = true, status = 200) {
|
||||
(fetch as any).mockResolvedValueOnce({
|
||||
function mockFetchResponse(data: unknown, ok = true, _status = 200) {
|
||||
(fetch as Mock).mockResolvedValueOnce({
|
||||
ok,
|
||||
status,
|
||||
status: _status,
|
||||
json: () => Promise.resolve(data),
|
||||
});
|
||||
}
|
||||
@@ -42,7 +40,7 @@ describe('ApiClient', () => {
|
||||
});
|
||||
|
||||
it('throws on failed login', async () => {
|
||||
(fetch as any).mockResolvedValueOnce({
|
||||
(fetch as Mock).mockResolvedValueOnce({
|
||||
ok: false,
|
||||
json: () => Promise.resolve({ message: 'Invalid credentials' }),
|
||||
});
|
||||
@@ -78,7 +76,7 @@ describe('ApiClient', () => {
|
||||
});
|
||||
|
||||
it('returns null when not authenticated', async () => {
|
||||
(fetch as any).mockResolvedValueOnce({
|
||||
(fetch as Mock).mockResolvedValueOnce({
|
||||
ok: false,
|
||||
json: () => Promise.resolve({}),
|
||||
});
|
||||
@@ -88,7 +86,7 @@ describe('ApiClient', () => {
|
||||
});
|
||||
|
||||
it('returns null on network error', async () => {
|
||||
(fetch as any).mockRejectedValueOnce(new Error('Network error'));
|
||||
(fetch as Mock).mockRejectedValueOnce(new Error('Network error'));
|
||||
|
||||
const result = await api.getSession();
|
||||
expect(result).toBeNull();
|
||||
@@ -165,7 +163,7 @@ describe('ApiClient', () => {
|
||||
|
||||
await api.getTasks({ projectId: 'proj1', completed: false, today: true });
|
||||
|
||||
const calledUrl = (fetch as any).mock.calls[0][0] as string;
|
||||
const calledUrl = (fetch as Mock).mock.calls[0][0] as string;
|
||||
expect(calledUrl).toContain('/api/tasks?');
|
||||
expect(calledUrl).toContain('projectId=proj1');
|
||||
expect(calledUrl).toContain('completed=false');
|
||||
@@ -259,14 +257,14 @@ describe('ApiClient', () => {
|
||||
|
||||
await api.getProjects();
|
||||
|
||||
const headers = (fetch as any).mock.calls[0][1].headers;
|
||||
const headers = (fetch as Mock).mock.calls[0][1].headers;
|
||||
expect(headers['Authorization']).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Error handling', () => {
|
||||
it('throws error with message from non-200 response', async () => {
|
||||
(fetch as any).mockResolvedValueOnce({
|
||||
(fetch as Mock).mockResolvedValueOnce({
|
||||
ok: false,
|
||||
json: () => Promise.resolve({ error: 'Not found' }),
|
||||
});
|
||||
@@ -275,7 +273,7 @@ describe('ApiClient', () => {
|
||||
});
|
||||
|
||||
it('throws "Request failed" when error body is unparseable', async () => {
|
||||
(fetch as any).mockResolvedValueOnce({
|
||||
(fetch as Mock).mockResolvedValueOnce({
|
||||
ok: false,
|
||||
json: () => Promise.reject(new Error('parse error')),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user