ci: Prettier纳入两层防御体系 (#520)
CI Build & Deploy Pipeline / Staging E2E Tests (push) Failing after 2m50s
CI Build & Deploy Pipeline / Production Browser E2E (push) Failing after 1437h19m24s
CI Build & Deploy Pipeline / Build Production Web Image (push) Failing after 1437h19m26s
CI Build & Deploy Pipeline / Deploy Production (push) Failing after 1437h19m25s
CI Build & Deploy Pipeline / Build Production API Image (push) Failing after 1437h19m26s
CI/CD Pipeline / Check if frontend-only change (push) Failing after 1437h21m16s
CI Build & Deploy Pipeline / Build Staging API Image (push) Has been skipped
CI Build & Deploy Pipeline / Build Staging Web Image (push) Has been skipped
CI Build & Deploy Pipeline / Build Staging Worker Image (push) Has been skipped
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Has been skipped
CI Build & Deploy Pipeline / Staging API Integration Tests (push) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (push) Failing after 1437h51m29s
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been skipped
CI/CD Pipeline / Unit Tests (push) Has been skipped
CI/CD Pipeline / Integration Tests (push) Has been skipped
CI/CD Pipeline / Frontend Lint (push) Has been skipped

Co-authored-by: xiaoxia <dev@xiaoxiajianji.com>
Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
This commit was merged in pull request #520.
This commit is contained in:
2026-07-18 18:08:19 +08:00
committed by auto-approve-bot
parent 1ee779a566
commit 0fcb77b991
145 changed files with 10310 additions and 12869 deletions
+40 -40
View File
@@ -1,23 +1,23 @@
/**
* useAuth Hook 单元测试
*/
import { renderHook, waitFor } from "@testing-library/react";
import { describe, it, expect, vi, beforeEach } from "vitest";
import { useLogin, useRegister, useLogout } from "@/hooks/useAuth";
import * as authApi from "@/api/auth";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { BrowserRouter } from "react-router-dom";
import React from "react";
import { renderHook, waitFor } from "@testing-library/react"
import { describe, it, expect, vi, beforeEach } from "vitest"
import { useLogin, useRegister, useLogout } from "@/hooks/useAuth"
import * as authApi from "@/api/auth"
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
import { BrowserRouter } from "react-router-dom"
import React from "react"
// Mock API
vi.mock("@/api/auth");
vi.mock("@/api/auth")
vi.mock("react-router-dom", async () => {
const actual = await vi.importActual("react-router-dom");
const actual = await vi.importActual("react-router-dom")
return {
...actual,
useNavigate: () => vi.fn(),
};
});
}
})
// Test wrapper
const createWrapper = () => {
@@ -26,19 +26,19 @@ const createWrapper = () => {
queries: { retry: false },
mutations: { retry: false },
},
});
})
return ({ children }: { children: React.ReactNode }) => (
<BrowserRouter>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</BrowserRouter>
);
};
)
}
describe.skip("useAuth", () => {
beforeEach(() => {
vi.clearAllMocks();
localStorage.clear();
});
vi.clearAllMocks()
localStorage.clear()
})
it("should login successfully", async () => {
const mockResponse = {
@@ -49,26 +49,26 @@ describe.skip("useAuth", () => {
email: "test@example.com",
username: "testuser",
display_name: "Test User",
};
}
vi.mocked(authApi.login).mockResolvedValue(mockResponse);
vi.mocked(authApi.login).mockResolvedValue(mockResponse)
vi.mocked(authApi.getCurrentUser).mockResolvedValue({
id: "1",
email: "test@example.com",
username: "testuser",
display_name: "Test User",
});
})
const { result } = renderHook(() => useLogin(), {
wrapper: createWrapper(),
});
})
await waitFor(() => {
expect(result.current).toBeDefined();
});
expect(result.current).toBeDefined()
})
expect(authApi.login).toBeDefined();
});
expect(authApi.login).toBeDefined()
})
it("should register successfully", async () => {
const mockResponse = {
@@ -77,34 +77,34 @@ describe.skip("useAuth", () => {
username: "testuser",
display_name: "Test User",
message: "注册成功",
};
}
vi.mocked(authApi.register).mockResolvedValue(mockResponse);
vi.mocked(authApi.register).mockResolvedValue(mockResponse)
const { result } = renderHook(() => useRegister(), {
wrapper: createWrapper(),
});
})
await waitFor(() => {
expect(result.current).toBeDefined();
});
expect(result.current).toBeDefined()
})
expect(authApi.register).toBeDefined();
});
expect(authApi.register).toBeDefined()
})
it("should logout successfully", async () => {
localStorage.setItem("access_token", "mock-token");
localStorage.setItem("access_token", "mock-token")
vi.mocked(authApi.logout).mockResolvedValue(undefined);
vi.mocked(authApi.logout).mockResolvedValue(undefined)
const { result } = renderHook(() => useLogout(), {
wrapper: createWrapper(),
});
})
await waitFor(() => {
expect(result.current).toBeDefined();
});
expect(result.current).toBeDefined()
})
expect(authApi.logout).toBeDefined();
});
});
expect(authApi.logout).toBeDefined()
})
})