Сервер на Hono, клиент Google и его мок, переводы ru/kk/en, тесты по сценариям, проверки и деплой (Dockerfile, /healthz). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
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);
|
||
});
|
||
});
|