Files
Reactive-Resume/packages/api/src/features/applications/ai.test.ts
T
Amruth Pillai da2f1f8244 refactor(applications): autofill from a pasted posting instead of a URL
Fetching an arbitrary job URL server side meant owning SSRF defence, redirect
and size limits, and per-site scraping quirks. The autofill tool now takes only
pasted text, so the URL input, the fetch path and its MCP annotation are gone.

The sheet gates the call behind a tested AI provider and a minimum paste length
so a stray snippet does not spend an AI call.
2026-08-17 22:32:32 +02:00

42 lines
1.5 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
const protectedProcedureMock = vi.hoisted(() => {
const chain = {
route: vi.fn(() => chain),
input: vi.fn(() => chain),
use: vi.fn(() => chain),
output: vi.fn(() => chain),
handler: vi.fn(() => chain),
};
return chain;
});
vi.mock("ai", () => ({ generateText: vi.fn() }));
vi.mock("../../context", () => ({ protectedProcedure: protectedProcedureMock }));
vi.mock("../../middleware/rate-limit", () => ({ aiRequestRateLimit: vi.fn() }));
vi.mock("../ai/service", () => ({ getModel: vi.fn() }));
vi.mock("../ai-providers/service", () => ({ aiProvidersService: { getDefaultRunnable: vi.fn() } }));
vi.mock("../resume/service", () => ({ resumeService: { getById: vi.fn(), create: vi.fn() } }));
vi.mock("./service", () => ({
applicationService: { getById: vi.fn(), setAiResult: vi.fn(), update: vi.fn(), addNote: vi.fn() },
}));
const { autofillInputSchema } = await import("./ai");
describe("autofillInputSchema", () => {
it("rejects oversized pasted job descriptions", () => {
expect(() => autofillInputSchema.parse({ jobDescription: "x".repeat(20_001) })).toThrow();
});
it("rejects blank pasted job descriptions", () => {
expect(() => autofillInputSchema.parse({ jobDescription: " " })).toThrow();
expect(() => autofillInputSchema.parse({})).toThrow();
});
it("accepts a pasted posting", () => {
expect(autofillInputSchema.parse({ jobDescription: " Senior Engineer at Acme " }).jobDescription).toBe(
"Senior Engineer at Acme",
);
});
});