Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+18
-14
@@ -1,20 +1,23 @@
|
||||
import type { TFunction } from "i18next";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { db } from "~/utils/db.server";
|
||||
import { createFeedback } from "../db/feedback.db.server";
|
||||
import NotificationService from "~/modules/notifications/services/.server/NotificationService";
|
||||
import { feedbackRedactionMarkers } from "./FeedbackRedaction.server";
|
||||
import { createWidgetSupportTicket } from "@hivegrid/db/support-tickets.server";
|
||||
|
||||
vi.mock("~/utils/db.server", () => ({
|
||||
db: {
|
||||
feedback: {
|
||||
deleteMany: vi.fn(),
|
||||
},
|
||||
supportTicket: {
|
||||
count: vi.fn(),
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("../db/feedback.db.server", () => ({
|
||||
createFeedback: vi.fn(),
|
||||
vi.mock("@hivegrid/db/support-tickets.server", () => ({
|
||||
createWidgetSupportTicket: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/modules/notifications/services/.server/NotificationService", () => ({
|
||||
@@ -23,19 +26,19 @@ vi.mock("~/modules/notifications/services/.server/NotificationService", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
const countFeedbackMock = vi.mocked(db.feedback.count);
|
||||
const createFeedbackMock = vi.mocked(createFeedback);
|
||||
const countWidgetTicketsMock = vi.mocked(db.supportTicket.count);
|
||||
const createWidgetSupportTicketMock = vi.mocked(createWidgetSupportTicket);
|
||||
const sendToRolesMock = vi.mocked(NotificationService.sendToRoles);
|
||||
const t = ((key: string) => key) as TFunction;
|
||||
|
||||
describe("FeedbackServer.send", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
countFeedbackMock.mockResolvedValue(0);
|
||||
createFeedbackMock.mockResolvedValue({ id: "feedback_1" } as Awaited<ReturnType<typeof createFeedback>>);
|
||||
countWidgetTicketsMock.mockResolvedValue(0);
|
||||
createWidgetSupportTicketMock.mockResolvedValue({ ticketId: "ticket_1", tenantId: "tenant_1", subject: "Support request" });
|
||||
});
|
||||
|
||||
it("redacts sensitive message and URL values before notification and persistence", async () => {
|
||||
it("redacts sensitive message and URL values before creating a support ticket", async () => {
|
||||
const rawEmail = "owner@example.com";
|
||||
const rawBearer = "secret-token-value";
|
||||
const rawHexSecret = "abcdefabcdefabcdefabcdefabcdefabcdefabcd";
|
||||
@@ -57,24 +60,25 @@ describe("FeedbackServer.send", () => {
|
||||
expect(sendToRolesMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
notification: expect.objectContaining({
|
||||
message: expect.stringContaining(feedbackRedactionMarkers.email),
|
||||
message: expect.stringContaining("[New Support Ticket]"),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
expect(createFeedbackMock).toHaveBeenCalledWith({
|
||||
expect(createWidgetSupportTicketMock).toHaveBeenCalledWith({
|
||||
tenantId: "tenant_1",
|
||||
userId: "user_1",
|
||||
subject: undefined,
|
||||
message: expect.stringContaining(feedbackRedactionMarkers.secret),
|
||||
fromUrl: expect.stringContaining(`token=${feedbackRedactionMarkers.token}`),
|
||||
});
|
||||
|
||||
const notifiedPayload = JSON.stringify(sendToRolesMock.mock.calls[0]);
|
||||
const createdPayload = JSON.stringify(createFeedbackMock.mock.calls[0]);
|
||||
const createdPayload = JSON.stringify(createWidgetSupportTicketMock.mock.calls[0]);
|
||||
for (const rawSecret of [rawEmail, rawBearer, rawHexSecret, rawQueryToken, rawClientSecret]) {
|
||||
expect(notifiedPayload).not.toContain(rawSecret);
|
||||
expect(createdPayload).not.toContain(rawSecret);
|
||||
}
|
||||
expect(notifiedPayload).toContain(`Bearer ${feedbackRedactionMarkers.token}`);
|
||||
expect(createdPayload).toContain(`Bearer ${feedbackRedactionMarkers.token}`);
|
||||
expect(createdPayload).toContain(`client_secret=${feedbackRedactionMarkers.token}`);
|
||||
expect(createdPayload).toContain("next=/home");
|
||||
});
|
||||
@@ -93,7 +97,7 @@ describe("FeedbackServer.send", () => {
|
||||
).rejects.toThrow("Message is required");
|
||||
|
||||
expect(sendToRolesMock).not.toHaveBeenCalled();
|
||||
expect(createFeedbackMock).not.toHaveBeenCalled();
|
||||
expect(countFeedbackMock).not.toHaveBeenCalled();
|
||||
expect(createWidgetSupportTicketMock).not.toHaveBeenCalled();
|
||||
expect(countWidgetTicketsMock).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
+18
-5
@@ -1,10 +1,11 @@
|
||||
import { TFunction } from "i18next";
|
||||
import { db } from "~/utils/db.server";
|
||||
import { createFeedback } from "../db/feedback.db.server";
|
||||
import NotificationService from "~/modules/notifications/services/.server/NotificationService";
|
||||
import { redactFeedbackText } from "./FeedbackRedaction.server";
|
||||
import { createWidgetSupportTicket } from "@hivegrid/db/support-tickets.server";
|
||||
|
||||
const MAX_FEEDBACK_PER_DAY = 3;
|
||||
const FEEDBACK_RATE_LIMIT_WINDOW_HOURS = 24;
|
||||
|
||||
async function send({
|
||||
t,
|
||||
@@ -25,25 +26,37 @@ async function send({
|
||||
throw Error("Message is required");
|
||||
}
|
||||
|
||||
const createdSince = new Date(Date.now() - FEEDBACK_RATE_LIMIT_WINDOW_HOURS * 60 * 60 * 1_000);
|
||||
if (tenantId) {
|
||||
const feedbackToday = await db.feedback.count({ where: { tenantId } });
|
||||
const feedbackToday = await db.supportTicket.count({
|
||||
where: { tenantId, source: "widget", createdAt: { gte: createdSince } },
|
||||
});
|
||||
if (feedbackToday >= MAX_FEEDBACK_PER_DAY) {
|
||||
throw Error(t("feedback.limitReached"));
|
||||
}
|
||||
} else if (userId) {
|
||||
const feedbackToday = await db.feedback.count({ where: { userId } });
|
||||
const feedbackToday = await db.supportTicket.count({
|
||||
where: { userId, source: "widget", createdAt: { gte: createdSince } },
|
||||
});
|
||||
if (feedbackToday >= MAX_FEEDBACK_PER_DAY) {
|
||||
throw Error(t("feedback.limitReached"));
|
||||
}
|
||||
}
|
||||
const ticket = await createWidgetSupportTicket({
|
||||
tenantId,
|
||||
userId,
|
||||
subject: undefined,
|
||||
message: redactedMessage,
|
||||
fromUrl: redactedFromUrl,
|
||||
});
|
||||
await NotificationService.sendToRoles({
|
||||
channel: "admin-users",
|
||||
tenantId: null,
|
||||
notification: {
|
||||
message: "[New Feedback] " + redactedMessage,
|
||||
message: "[New Support Ticket] " + ticket.subject,
|
||||
},
|
||||
});
|
||||
return await createFeedback({ tenantId, userId, message: redactedMessage, fromUrl: redactedFromUrl });
|
||||
return ticket;
|
||||
}
|
||||
|
||||
async function deleteMany({ ids }: { ids: string[] }) {
|
||||
|
||||
Reference in new issue
Block a user