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

View file

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