5610ef9f1a
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI Build & Deploy Pipeline / Build Production API Image (push) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (push) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (push) Has been skipped
CI Build & Deploy Pipeline / Deploy Production (push) Has been skipped
CI Build & Deploy Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 1m8s
CI Build & Deploy Pipeline / Build Staging Web Image (push) Successful in 1m31s
CI/CD Pipeline / Frontend Lint (push) Successful in 2m26s
CI/CD Pipeline / Validate Code Quality And Tests (push) Successful in 3m46s
CI/CD Pipeline / Unit Tests (push) Successful in 3m49s
CI/CD Pipeline / Integration Tests (push) Successful in 1m52s
CI Build & Deploy Pipeline / Build Staging API Image (push) Successful in 6m29s
CI Build & Deploy Pipeline / Build Staging Worker Image (push) Successful in 8m32s
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 50s
CI Build & Deploy Pipeline / Staging E2E Tests (push) Failing after 1m21s
CI Build & Deploy Pipeline / Staging API Integration Tests (push) Successful in 3m11s
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com> Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
119 lines
4.3 KiB
TypeScript
119 lines
4.3 KiB
TypeScript
import { describe, expect, it, vi, beforeEach } from "vitest"
|
|
import {
|
|
uploadForDuplication,
|
|
getDuplicationRecords,
|
|
getDuplicationDetail,
|
|
deleteDuplicationRecord,
|
|
retryDuplication,
|
|
} from "@/api/duplication"
|
|
|
|
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("duplication 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("uploadForDuplication", () => {
|
|
it("should resolve successfully", async () => {
|
|
await expect(uploadForDuplication(new File(["test"], "test.txt"))).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(uploadForDuplication(new File(["test"], "test.txt"))).rejects.toThrow()
|
|
})
|
|
})
|
|
|
|
describe("getDuplicationRecords", () => {
|
|
it("should resolve successfully", async () => {
|
|
await expect(getDuplicationRecords()).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(getDuplicationRecords()).rejects.toThrow()
|
|
})
|
|
})
|
|
|
|
describe("getDuplicationDetail", () => {
|
|
it("should resolve successfully", async () => {
|
|
await expect(getDuplicationDetail("test-recordId")).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(getDuplicationDetail("test-recordId")).rejects.toThrow()
|
|
})
|
|
})
|
|
|
|
describe("deleteDuplicationRecord", () => {
|
|
it("should resolve successfully", async () => {
|
|
await expect(deleteDuplicationRecord("test-recordId")).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(deleteDuplicationRecord("test-recordId")).rejects.toThrow()
|
|
})
|
|
})
|
|
|
|
describe("retryDuplication", () => {
|
|
it("should resolve successfully", async () => {
|
|
await expect(retryDuplication("test-recordId")).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(retryDuplication("test-recordId")).rejects.toThrow()
|
|
})
|
|
})
|
|
})
|