Skip to content

Commit

Permalink
Add unit test for DocUnitService.setStatus
Browse files Browse the repository at this point in the history
RISDEV-5883
  • Loading branch information
kiwikern committed Jan 17, 2025
1 parent 5fe7659 commit b3a87e7
Showing 1 changed file with 49 additions and 11 deletions.
60 changes: 49 additions & 11 deletions frontend/test/services/documentUnitService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { DuplicateRelationStatus } from "@/domain/documentUnit"
import service from "@/services/documentUnitService"
import { ServiceResponse } from "@/services/httpClient"
import HttpClient from "@/services/httpClient"

describe("documentUnitService", () => {
vi.mock("@/services/httpClient", () => {
const testResponse: ServiceResponse<string> = {
it("appends correct error message if status 500", async () => {
vi.spyOn(HttpClient, "get").mockResolvedValue({
status: 500,
data: "foo",
}
return {
default: {
get: vi.fn().mockReturnValue(testResponse),
},
}
})
})

it("appends correct error message if status 500", async () => {
const result = await service.searchByDocumentUnitSearchInput({
pg: "0",
sz: "20",
Expand All @@ -26,4 +20,48 @@ describe("documentUnitService", () => {
"Bitte versuchen Sie es später erneut.",
)
})

describe("setDuplicateRelationStatus", () => {
it("should set error flag with unsuccessful status", async () => {
const httpMock = vi.spyOn(HttpClient, "put").mockResolvedValue({
status: 400,
data: "error",
})

const response = await service.setDuplicateRelationStatus(
"123",
"abc",
DuplicateRelationStatus.IGNORED,
)

expect(response).toEqual({ error: true })

expect(httpMock).toHaveBeenCalledWith(
"caselaw/documentunits/123/duplicate-status/abc",
{},
{ status: DuplicateRelationStatus.IGNORED },
)
})

it("should set error flag to false on success", async () => {
const httpMock = vi.spyOn(HttpClient, "put").mockResolvedValue({
status: 200,
data: "success",
})

const response = await service.setDuplicateRelationStatus(
"abc",
"123",
DuplicateRelationStatus.PENDING,
)

expect(response).toEqual({ error: false })

expect(httpMock).toHaveBeenCalledWith(
"caselaw/documentunits/abc/duplicate-status/123",
{},
{ status: DuplicateRelationStatus.PENDING },
)
})
})
})

0 comments on commit b3a87e7

Please sign in to comment.