import { describe, it, expect } from "vitest"; import { commentReplyRecipient } from "../comment-notify"; const parent = { userId: "student-1", deleted: false, user: { email: "student@example.com", name: "Владимир" }, }; describe("commentReplyRecipient", () => { it("отдаёт автора родительского комментария, когда админ ответил ученику", () => { expect( commentReplyRecipient({ notifyEnabled: true, replierId: "admin-1", replierRole: "admin", parent, }) ).toEqual({ email: "student@example.com", name: "Владимир" }); }); it("работает и для куратора", () => { expect( commentReplyRecipient({ notifyEnabled: true, replierId: "curator-1", replierRole: "curator", parent, }) ).toEqual({ email: "student@example.com", name: "Владимир" }); }); it("молчит при выключенной настройке", () => { expect( commentReplyRecipient({ notifyEnabled: false, replierId: "admin-1", replierRole: "admin", parent, }) ).toBeNull(); }); it("молчит, когда отвечает не staff", () => { expect( commentReplyRecipient({ notifyEnabled: true, replierId: "student-2", replierRole: "student", parent, }) ).toBeNull(); }); it("молчит без родительского комментария — это корневая запись, а не ответ", () => { expect( commentReplyRecipient({ notifyEnabled: true, replierId: "admin-1", replierRole: "admin", parent: null, }) ).toBeNull(); }); it("молчит, если родительский комментарий удалён", () => { expect( commentReplyRecipient({ notifyEnabled: true, replierId: "admin-1", replierRole: "admin", parent: { ...parent, deleted: true }, }) ).toBeNull(); }); it("не пишет письмо самому себе", () => { expect( commentReplyRecipient({ notifyEnabled: true, replierId: "student-1", replierRole: "admin", parent, }) ).toBeNull(); }); it("молчит, когда у автора нет почты", () => { expect( commentReplyRecipient({ notifyEnabled: true, replierId: "admin-1", replierRole: "admin", parent: { ...parent, user: { email: " ", name: "Без почты" } }, }) ).toBeNull(); }); it("отдаёт пустое имя, если в карточке его нет", () => { expect( commentReplyRecipient({ notifyEnabled: true, replierId: "admin-1", replierRole: "admin", parent: { ...parent, user: { email: "student@example.com", name: "" } }, }) ).toEqual({ email: "student@example.com", name: "" }); }); });