Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/api/useCqlLibraryServiceApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,4 +585,57 @@ describe("useCqlLibraryServiceApi", () => {
);
consoleErrorMock.mockRestore();
});

it("should delete a library", async () => {
const response = { data: { id: "lib1" } };

mockedAxios.delete.mockResolvedValueOnce(response);

const result = await cqlLibraryServiceApi.deleteLibrary(
"lib1",
"harpId123"
);

expect(mockedAxios.delete).toHaveBeenCalledWith(
`${mockBaseUrl}/cql-libraries/admin/lib1`,
{
headers: {
Authorization: `Bearer ${mockToken}`,
harpId: "harpId123",
},
}
);

expect(result).toBe(response);
});
it("should log and rethrow errors when deleteLibrary fails", async () => {
const error = new Error("delete failed");

const consoleErrorSpy = jest
.spyOn(console, "error")
.mockImplementation(() => {});

mockedAxios.delete.mockRejectedValueOnce(error);

await expect(
cqlLibraryServiceApi.deleteLibrary("lib1", "harpId123")
).rejects.toThrow("delete failed");

expect(mockedAxios.delete).toHaveBeenCalledWith(
`${mockBaseUrl}/cql-libraries/admin/lib1`,
{
headers: {
Authorization: `Bearer ${mockToken}`,
harpId: "harpId123",
},
}
);

expect(consoleErrorSpy).toHaveBeenCalledWith(
"Failed to delete library",
error
);

consoleErrorSpy.mockRestore();
});
});
18 changes: 18 additions & 0 deletions src/api/useCqlLibraryServiceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,24 @@ export class CqlLibraryServiceApi {
}
}

// admin delete
async deleteLibrary(
id: string,
harpId: string
): Promise<AxiosResponse<CqlLibrary>> {
try {
return await axios.delete(`${this.baseUrl}/cql-libraries/admin/${id}`, {
headers: {
Authorization: `Bearer ${this.getAccessToken()}`,
harpId,
},
});
} catch (err) {
console.error("Failed to delete library", err);
throw err;
}
}

async unlockLibraries(): Promise<String> {
try {
const response = await axios.delete<String>(
Expand Down
Loading