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);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -84,6 +84,30 @@ export async function updateGalleryImage(
|
||||
return { success: result.count > 0 };
|
||||
}
|
||||
|
||||
/** imageUrl is a VarChar(500) column. */
|
||||
export const GALLERY_IMAGE_URL_MAX_LENGTH = 500;
|
||||
|
||||
/**
|
||||
* Swaps the picture in an existing slot, keeping everything else about it: its
|
||||
* position, its category and caption, and whether it is shown. (Delete + add
|
||||
* would put the new picture at the end and lose the category.)
|
||||
*/
|
||||
export async function replaceGalleryImage(
|
||||
prisma: PrismaClient,
|
||||
params: { id: string; businessId: string; imageUrl: string },
|
||||
): Promise<{ success: boolean; error?: string }> {
|
||||
const imageUrl = params.imageUrl.trim();
|
||||
if (!imageUrl || imageUrl.length > GALLERY_IMAGE_URL_MAX_LENGTH) {
|
||||
return { success: false, error: "That image address isn't valid." };
|
||||
}
|
||||
const result = await prisma.businessGalleryImage.updateMany({
|
||||
where: { id: params.id, businessId: params.businessId },
|
||||
// The old media-library link no longer describes this picture.
|
||||
data: { imageUrl, mediaAssetId: null },
|
||||
});
|
||||
return result.count > 0 ? { success: true } : { success: false, error: "Image not found." };
|
||||
}
|
||||
|
||||
export async function deleteGalleryImage(
|
||||
prisma: PrismaClient,
|
||||
params: { id: string; businessId: string },
|
||||
|
||||
Reference in new issue
Block a user