Hero gallery: the slideshow on Home doesn’t open full screen. Only portfolio images do, as you asked. Lightbox: it has no pinch-zoom. Delete: removing an image still has no confirm step, same as before. New dependency: drag-and-drop uses @dnd-kit, which I added to package.json. Touch dragging: I couldn’t test it on a real phone. Mouse and keyboard dragging work. Health test: src/app/api/health/__tests__/route.test.ts passes, but it prints unhandled rejections. Its prisma mock has no notificationDelivery, so getQueueHealth throws. That comes from the earlier “Remaining features” commit and I left it alone. It’s a quick fix if you want it.
This commit is contained in:
9 files changed
+506
-70
No files matched your search
@@ -3,8 +3,10 @@ import { GalleryPlacement } from "@/generated/prisma/enums";
|
||||
import {
|
||||
addGalleryImage,
|
||||
deleteGalleryImage,
|
||||
GALLERY_IMAGE_URL_MAX_LENGTH,
|
||||
listGalleryImages,
|
||||
reorderGalleryImages,
|
||||
replaceGalleryImage,
|
||||
updateGalleryImage,
|
||||
} from "@/services/gallery/gallery.service";
|
||||
import { cleanupTestBusiness, createTestBusiness, prisma } from "@/services/scheduling/__tests__/fixtures";
|
||||
@@ -83,4 +85,46 @@ describe("Gallery service (integration)", () => {
|
||||
expect(result.success).toBe(true);
|
||||
expect(await prisma.businessGalleryImage.findUnique({ where: { id: image.id } })).toBeNull();
|
||||
});
|
||||
|
||||
describe("replacing an image", () => {
|
||||
const add = (url: string, extra: { category?: string } = {}) =>
|
||||
addGalleryImage(prisma, { businessId: business.businessId, placement: GalleryPlacement.PORTFOLIO, imageUrl: url, ...extra });
|
||||
|
||||
it("swaps the picture but keeps its position, category, caption and visibility", async () => {
|
||||
const first = await add("/media/first.png");
|
||||
const middle = await add("/media/middle.png", { category: "Fades" });
|
||||
const last = await add("/media/last.png");
|
||||
await updateGalleryImage(prisma, { id: middle.id, businessId: business.businessId, caption: "Client X", isActive: false });
|
||||
|
||||
const result = await replaceGalleryImage(prisma, { id: middle.id, businessId: business.businessId, imageUrl: "/media/new.png" });
|
||||
|
||||
expect(result).toEqual({ success: true });
|
||||
const all = await listGalleryImages(prisma, { businessId: business.businessId, placement: GalleryPlacement.PORTFOLIO });
|
||||
expect(all.map((i) => i.id)).toEqual([first.id, middle.id, last.id]);
|
||||
expect(all[1]).toMatchObject({ imageUrl: "/media/new.png", category: "Fades", caption: "Client X", isActive: false });
|
||||
});
|
||||
|
||||
it("refuses an empty or over-long address, leaving the picture as it was", async () => {
|
||||
const image = await add("/media/keep.png");
|
||||
|
||||
for (const imageUrl of [" ", "x".repeat(GALLERY_IMAGE_URL_MAX_LENGTH + 1)]) {
|
||||
const result = await replaceGalleryImage(prisma, { id: image.id, businessId: business.businessId, imageUrl });
|
||||
expect(result.success).toBe(false);
|
||||
}
|
||||
expect((await prisma.businessGalleryImage.findUniqueOrThrow({ where: { id: image.id } })).imageUrl).toBe("/media/keep.png");
|
||||
});
|
||||
|
||||
it("can't replace another business's image", async () => {
|
||||
const otherBusiness = await createTestBusiness();
|
||||
try {
|
||||
const image = await add("/media/mine.png");
|
||||
const result = await replaceGalleryImage(prisma, { id: image.id, businessId: otherBusiness.businessId, imageUrl: "/media/hijack.png" });
|
||||
|
||||
expect(result.success).toBe(false);
|
||||
expect((await prisma.businessGalleryImage.findUniqueOrThrow({ where: { id: image.id } })).imageUrl).toBe("/media/mine.png");
|
||||
} finally {
|
||||
await cleanupTestBusiness(otherBusiness);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user