fix(notifications): tell staff about every new comment
Only the shot's assigned artist was notified of player comments, and client-link comments and pasted WhatsApp feedback notified no one. notifyCommentsAdded now notifies all active staff plus the shot/task artist, never the author, from all three paths. A pasted round becomes one notification per version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("@/lib/db", () => ({ db: {} }));
|
||||
|
||||
import { buildCommentNotifications } from "./notifications";
|
||||
|
||||
const note = (versionId: string, shotCode: string, frameNumber: number, artistIds: (string | null)[] = []) => ({
|
||||
versionId,
|
||||
shotCode,
|
||||
frameNumber,
|
||||
artistIds,
|
||||
});
|
||||
|
||||
describe("buildCommentNotifications", () => {
|
||||
it("tells every staff member and the artist, never the author", () => {
|
||||
const out = buildCommentNotifications({
|
||||
notes: [note("v1", "DH2_010", 1012, ["artist"])],
|
||||
authorId: "sup",
|
||||
authorName: "Sam",
|
||||
staffIds: ["sup", "prod", "admin"],
|
||||
});
|
||||
expect(out.map((p) => p.userId).sort()).toEqual(["admin", "artist", "prod"]);
|
||||
expect(out[0]).toMatchObject({
|
||||
type: "FEEDBACK_ADDED",
|
||||
title: "New feedback",
|
||||
message: "Sam commented on DH2_010 at frame 1012",
|
||||
data: { versionId: "v1", shotCode: "DH2_010", frameNumber: 1012 },
|
||||
});
|
||||
});
|
||||
|
||||
it("does not notify an artist twice when they are also staff or on both shot and task", () => {
|
||||
const out = buildCommentNotifications({
|
||||
notes: [note("v1", "A", 1, ["prod", "prod", null])],
|
||||
authorId: "x",
|
||||
authorName: "X",
|
||||
staffIds: ["prod"],
|
||||
});
|
||||
expect(out.map((p) => p.userId)).toEqual(["prod"]);
|
||||
});
|
||||
|
||||
it("labels client comments", () => {
|
||||
const [p] = buildCommentNotifications({
|
||||
notes: [note("v1", "A", 5)],
|
||||
authorId: "client",
|
||||
authorName: "Netflix",
|
||||
origin: "client",
|
||||
staffIds: ["prod"],
|
||||
});
|
||||
expect(p.title).toBe("New client feedback");
|
||||
expect(p.message).toBe("Client Netflix commented on A at frame 5");
|
||||
});
|
||||
|
||||
it("groups a pasted round into one notification per version", () => {
|
||||
const out = buildCommentNotifications({
|
||||
notes: [note("v1", "A", 1, ["art1"]), note("v1", "A", 9), note("v2", "B", 3, ["art2"])],
|
||||
authorId: "prod",
|
||||
authorName: "Pat",
|
||||
origin: "whatsapp",
|
||||
staffIds: ["prod", "sup"],
|
||||
});
|
||||
const msgs = out.map((p) => `${p.userId}: ${p.message}`).sort();
|
||||
expect(msgs).toEqual([
|
||||
"art1: Client feedback (logged by Pat) left 2 notes on A",
|
||||
"art2: Client feedback (logged by Pat) commented on B at frame 3",
|
||||
"sup: Client feedback (logged by Pat) commented on B at frame 3",
|
||||
"sup: Client feedback (logged by Pat) left 2 notes on A",
|
||||
]);
|
||||
});
|
||||
|
||||
it("sends nothing for no notes", () => {
|
||||
expect(
|
||||
buildCommentNotifications({ notes: [], authorId: "a", authorName: "A", staffIds: ["b"] })
|
||||
).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user