351a745ec5
CI Build & Deploy Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Production (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 12s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (pull_request) Has been skipped
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 16s
CI/CD Pipeline / Integration Tests (pull_request) Has been skipped
AI Code Review / AI Code Review (pull_request) Failing after 36s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Successful in 1m14s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m37s
Auto Approve CI PRs / Auto Approve on CI Green (pull_request) Successful in 1m49s
Auto Merge CI PRs / Auto Merge on CI Green + Approved (pull_request) Successful in 2m58s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 6s
81 lines
2.9 KiB
TypeScript
81 lines
2.9 KiB
TypeScript
import { describe, expect, it, vi, beforeEach } from "vitest"
|
|
import { getProjects, createProject, getOrCreateDefaultProject } from "@/api/projects"
|
|
|
|
const mockGet = vi.fn()
|
|
const mockPost = vi.fn()
|
|
const mockPut = vi.fn()
|
|
const mockDelete = vi.fn()
|
|
const mockPatch = vi.fn()
|
|
|
|
vi.mock("@/api/client", () => ({
|
|
default: {
|
|
get: (...args: unknown[]) => mockGet(...args),
|
|
post: (...args: unknown[]) => mockPost(...args),
|
|
put: (...args: unknown[]) => mockPut(...args),
|
|
delete: (...args: unknown[]) => mockDelete(...args),
|
|
patch: (...args: unknown[]) => mockPatch(...args),
|
|
},
|
|
}))
|
|
|
|
vi.mock("antd", () => ({ message: { error: vi.fn(), success: vi.fn() } }))
|
|
vi.mock("@/store/authStore", () => ({ useAuthStore: { getState: vi.fn(() => ({})) } }))
|
|
|
|
describe("projects API", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
mockGet.mockResolvedValue({ data: { success: true, items: [] } })
|
|
mockPost.mockResolvedValue({ data: { success: true, items: [] } })
|
|
mockPut.mockResolvedValue({ data: { success: true, items: [] } })
|
|
mockDelete.mockResolvedValue({ data: { success: true, items: [] } })
|
|
mockPatch.mockResolvedValue({ data: { success: true, items: [] } })
|
|
})
|
|
|
|
describe("getProjects", () => {
|
|
it("should resolve successfully", async () => {
|
|
await expect(getProjects()).resolves.not.toThrow()
|
|
})
|
|
|
|
it("should reject on API error", async () => {
|
|
mockGet.mockRejectedValue(new Error("Network error"))
|
|
mockPost.mockRejectedValue(new Error("Network error"))
|
|
mockPut.mockRejectedValue(new Error("Network error"))
|
|
mockDelete.mockRejectedValue(new Error("Network error"))
|
|
mockPatch.mockRejectedValue(new Error("Network error"))
|
|
|
|
await expect(getProjects()).rejects.toThrow()
|
|
})
|
|
})
|
|
|
|
describe("createProject", () => {
|
|
it("should resolve successfully", async () => {
|
|
await expect(createProject({ name: "test-item" })).resolves.not.toThrow()
|
|
})
|
|
|
|
it("should reject on API error", async () => {
|
|
mockGet.mockRejectedValue(new Error("Network error"))
|
|
mockPost.mockRejectedValue(new Error("Network error"))
|
|
mockPut.mockRejectedValue(new Error("Network error"))
|
|
mockDelete.mockRejectedValue(new Error("Network error"))
|
|
mockPatch.mockRejectedValue(new Error("Network error"))
|
|
|
|
await expect(createProject({ name: "test-item" })).rejects.toThrow()
|
|
})
|
|
})
|
|
|
|
describe("getOrCreateDefaultProject", () => {
|
|
it("should resolve successfully", async () => {
|
|
await expect(getOrCreateDefaultProject()).resolves.not.toThrow()
|
|
})
|
|
|
|
it("should reject on API error", async () => {
|
|
mockGet.mockRejectedValue(new Error("Network error"))
|
|
mockPost.mockRejectedValue(new Error("Network error"))
|
|
mockPut.mockRejectedValue(new Error("Network error"))
|
|
mockDelete.mockRejectedValue(new Error("Network error"))
|
|
mockPatch.mockRejectedValue(new Error("Network error"))
|
|
|
|
await expect(getOrCreateDefaultProject()).rejects.toThrow()
|
|
})
|
|
})
|
|
})
|