executive-ai/test/sentry.test.ts
Peppa 56cba4cad0 EA-1: приложение — подключение календаря Google и список дел на 7 дней
Сервер на Hono, клиент Google и его мок, переводы ru/kk/en, тесты по сценариям,
проверки и деплой (Dockerfile, /healthz).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 12:29:10 +05:00

46 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, expect, it, vi } from "vitest";
const init = vi.fn();
const captureException = vi.fn();
vi.mock("@sentry/node", () => ({ init, captureException }));
describe("ошибки продукта (Bugsink)", () => {
it("без SENTRY_DSN ничего не включается и не отправляется", async () => {
const { initSentry, reportError } = await import("../src/sentry.js");
const log = vi.spyOn(console, "error").mockImplementation(() => {});
expect(initSentry({})).toBe(false);
reportError(new Error("boom"));
expect(init).not.toHaveBeenCalled();
expect(captureException).not.toHaveBeenCalled();
log.mockRestore();
});
it("с SENTRY_DSN: release и environment из окружения, персональные данные не собираются", async () => {
const { initSentry, reportError } = await import("../src/sentry.js");
expect(
initSentry({
SENTRY_DSN: "https://k@bugs.test/1",
SENTRY_RELEASE: "abc123",
SENTRY_ENVIRONMENT: "prod",
}),
).toBe(true);
expect(init).toHaveBeenCalledWith(
expect.objectContaining({
dsn: "https://k@bugs.test/1",
release: "abc123",
environment: "prod",
dataCollection: expect.objectContaining({
userInfo: false,
cookies: false,
httpHeaders: false,
httpBodies: [],
urlQueryParams: false,
}),
}),
);
const error = new Error("boom");
reportError(error);
expect(captureException).toHaveBeenCalledWith(error);
});
});