chore: pr feedback

This commit is contained in:
Nicolas Meienberger 2026-02-25 18:57:46 +01:00 committed by Nico
parent 2ce225f7d1
commit 19575257e8
2 changed files with 14 additions and 17 deletions

View file

@ -1,4 +1,4 @@
import { test, describe, expect } from "bun:test"; import { test, describe, expect, spyOn } from "bun:test";
import crypto from "node:crypto"; import crypto from "node:crypto";
import { createApp } from "~/server/app"; import { createApp } from "~/server/app";
import { db } from "~/server/db/db"; import { db } from "~/server/db/db";
@ -248,23 +248,23 @@ describe("repositories updates", () => {
const { restic } = await import("~/server/utils/restic"); const { restic } = await import("~/server/utils/restic");
const { ResticError } = await import("~/server/utils/errors"); const { ResticError } = await import("~/server/utils/errors");
const originalDeleteSnapshot = restic.deleteSnapshot;
// Mock it to throw an error const deleteSnapshotSpy = spyOn(restic, "deleteSnapshot").mockImplementation(async () => {
restic.deleteSnapshot = async () => {
throw new ResticError(1, "Fatal: unexpected HTTP response (403): 403 Forbidden"); throw new ResticError(1, "Fatal: unexpected HTTP response (403): 403 Forbidden");
}; });
try {
const res = await app.request(`/api/v1/repositories/${repository.shortId}/snapshots/snap123`, { const res = await app.request(`/api/v1/repositories/${repository.shortId}/snapshots/snap123`, {
method: "DELETE", method: "DELETE",
headers: getAuthHeaders(token), headers: getAuthHeaders(token),
}); });
restic.deleteSnapshot = originalDeleteSnapshot;
expect(res.status).toBe(500); expect(res.status).toBe(500);
const body = await res.json(); const body = await res.json();
expect(body.message).toContain("Command failed"); expect(body.message).toContain("Command failed");
} finally {
deleteSnapshotSpy.mockRestore();
}
}); });
}); });
}); });

View file

@ -401,8 +401,7 @@ describe("repositoriesService.deleteSnapshot", () => {
const { organizationId, user } = await createTestSession(); const { organizationId, user } = await createTestSession();
const repository = await createTestRepository(organizationId); const repository = await createTestRepository(organizationId);
const originalDeleteSnapshot = restic.deleteSnapshot; spyOn(restic, "deleteSnapshot").mockImplementation(async () => {
restic.deleteSnapshot = mock(async () => {
throw new ResticError(1, "Fatal: unexpected HTTP response (403): 403 Forbidden"); throw new ResticError(1, "Fatal: unexpected HTTP response (403): 403 Forbidden");
}); });
@ -411,7 +410,5 @@ describe("repositoriesService.deleteSnapshot", () => {
repositoriesService.deleteSnapshot(repository.shortId, "snap123"), repositoriesService.deleteSnapshot(repository.shortId, "snap123"),
), ),
).rejects.toThrow("Fatal: unexpected HTTP response"); ).rejects.toThrow("Fatal: unexpected HTTP response");
restic.deleteSnapshot = originalDeleteSnapshot;
}); });
}); });