Improve flight-finder report links and cron workflow
This commit is contained in:
@@ -4,7 +4,11 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
import fs from "node:fs";
|
||||
|
||||
import { renderFlightReportPdf, ReportValidationError } from "../src/report-pdf.js";
|
||||
import {
|
||||
describeQuoteBookingLinks,
|
||||
renderFlightReportPdf,
|
||||
ReportValidationError
|
||||
} from "../src/report-pdf.js";
|
||||
import type { FlightReportPayload } from "../src/types.js";
|
||||
import {
|
||||
DFW_BLQ_2026_PROMPT_DRAFT,
|
||||
@@ -66,6 +70,47 @@ test("renderFlightReportPdf writes a non-empty PDF", async () => {
|
||||
assert.ok(fs.statSync(outputPath).size > 0);
|
||||
});
|
||||
|
||||
test("renderFlightReportPdf embeds booking links and only includes direct-airline URLs when captured", async () => {
|
||||
const outputPath = path.join(os.tmpdir(), `flight-finder-links-${Date.now()}.pdf`);
|
||||
const payload = samplePayload();
|
||||
payload.quotes = [
|
||||
{
|
||||
...payload.quotes[0],
|
||||
bookingLink: "https://example.com/quote-1",
|
||||
directBookingUrl: null
|
||||
},
|
||||
{
|
||||
id: "quote-2",
|
||||
source: "airline-direct",
|
||||
legId: "return-pair",
|
||||
passengerGroupIds: ["pair"],
|
||||
bookingLink: "https://example.com/quote-2",
|
||||
directBookingUrl: "https://www.britishairways.com/",
|
||||
airlineName: "British Airways",
|
||||
itinerarySummary: "BLQ -> DFW via LHR",
|
||||
totalPriceUsd: 1100,
|
||||
displayPriceUsd: "$1,100"
|
||||
}
|
||||
];
|
||||
payload.rankedOptions = [
|
||||
{
|
||||
id: "primary",
|
||||
title: "Best overall itinerary",
|
||||
quoteIds: ["quote-1", "quote-2"],
|
||||
totalPriceUsd: 3947,
|
||||
rationale: "Best price-to-convenience tradeoff."
|
||||
}
|
||||
];
|
||||
|
||||
await renderFlightReportPdf(payload, outputPath);
|
||||
|
||||
const pdfContents = fs.readFileSync(outputPath, "latin1");
|
||||
assert.match(pdfContents, /https:\/\/example\.com\/quote-1/);
|
||||
assert.match(pdfContents, /https:\/\/example\.com\/quote-2/);
|
||||
assert.match(pdfContents, /https:\/\/www\.britishairways\.com\//);
|
||||
assert.doesNotMatch(pdfContents, /Direct airline booking: not captured in this run[\s\S]*https:\/\/example\.com\/quote-1/);
|
||||
});
|
||||
|
||||
test("renderFlightReportPdf rejects incomplete report payloads", async () => {
|
||||
const outputPath = path.join(os.tmpdir(), `flight-finder-incomplete-${Date.now()}.pdf`);
|
||||
await assert.rejects(
|
||||
@@ -99,3 +144,42 @@ test("renderFlightReportPdf rejects payloads that are not marked as fresh-search
|
||||
ReportValidationError
|
||||
);
|
||||
});
|
||||
|
||||
test("describeQuoteBookingLinks includes both aggregator and airline-direct links when captured", () => {
|
||||
const payload = samplePayload();
|
||||
const quote = {
|
||||
...payload.quotes[0],
|
||||
airlineName: "British Airways",
|
||||
directBookingUrl: "https://www.britishairways.com/"
|
||||
};
|
||||
|
||||
assert.deepEqual(describeQuoteBookingLinks(quote), [
|
||||
{
|
||||
label: "Search / book this fare",
|
||||
text: "Search / book this fare: $2,847 via kayak",
|
||||
url: "https://example.com/quote-1"
|
||||
},
|
||||
{
|
||||
label: "Direct airline booking",
|
||||
text: "Direct airline booking: British Airways",
|
||||
url: "https://www.britishairways.com/"
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
test("describeQuoteBookingLinks calls out missing direct-airline links explicitly", () => {
|
||||
const payload = samplePayload();
|
||||
|
||||
assert.deepEqual(describeQuoteBookingLinks(payload.quotes[0]), [
|
||||
{
|
||||
label: "Search / book this fare",
|
||||
text: "Search / book this fare: $2,847 via kayak",
|
||||
url: "https://example.com/quote-1"
|
||||
},
|
||||
{
|
||||
label: "Direct airline booking",
|
||||
text: "Direct airline booking: not captured in this run",
|
||||
url: null
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -11,6 +11,13 @@ import type { FlightReportPayload } from "../src/types.js";
|
||||
function buildPayload(): FlightReportPayload {
|
||||
return {
|
||||
request: normalizeFlightReportRequest(DFW_BLQ_2026_PROMPT_DRAFT).request,
|
||||
searchExecution: {
|
||||
freshSearch: true,
|
||||
startedAt: "2026-03-30T20:45:00Z",
|
||||
completedAt: "2026-03-30T21:00:00Z",
|
||||
artifactsRoot: "/tmp/flight-finder-report-status",
|
||||
notes: ["Fresh bounded search executed for this report."]
|
||||
},
|
||||
sourceFindings: [
|
||||
{
|
||||
source: "kayak",
|
||||
|
||||
Reference in New Issue
Block a user