initial commit
This commit is contained in:
52
test/naturalLanguageFlightParser.test.js
Normal file
52
test/naturalLanguageFlightParser.test.js
Normal file
@@ -0,0 +1,52 @@
|
||||
"use strict";
|
||||
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
const { parseFlightSearchRequest } = require("../src/naturalLanguageFlightParser");
|
||||
|
||||
test("parse sample Korean request into structured params", () => {
|
||||
const input =
|
||||
"11월 말부터 12월 초까지 출발하는 일정 여행 기간은 대략 12~14일, 비즈니스 2개, 프리미엄 이코노미 1개, 동일 항공편 인천 -> 마드리드 인, 바르셀로나 -> 인천 아웃 총 1회 여정 시간은 20시간 미만";
|
||||
|
||||
const parsed = parseFlightSearchRequest(input, {
|
||||
now: new Date("2026-02-19T00:00:00Z"),
|
||||
});
|
||||
|
||||
assert.equal(parsed.departureDateWindow.from, "2026-11-21");
|
||||
assert.equal(parsed.departureDateWindow.to, "2026-12-10");
|
||||
assert.deepEqual(parsed.stayDurationDays, { minDays: 12, maxDays: 14 });
|
||||
assert.equal(parsed.passengers.total, 3);
|
||||
assert.deepEqual(parsed.passengers.byCabin, {
|
||||
economy: 0,
|
||||
premium_economy: 1,
|
||||
business: 2,
|
||||
first: 0,
|
||||
});
|
||||
assert.deepEqual(parsed.segments, [
|
||||
{ from: "ICN", to: "MAD" },
|
||||
{ from: "BCN", to: "ICN" },
|
||||
]);
|
||||
assert.equal(parsed.tripType, "open_jaw");
|
||||
assert.equal(parsed.constraints.sameFlightForAllPassengers, true);
|
||||
assert.equal(parsed.constraints.itineraryCount, 1);
|
||||
assert.equal(parsed.constraints.maxStops, null);
|
||||
assert.deepEqual(parsed.constraints.maxJourneyHours, { hours: 20, operator: "<" });
|
||||
assert.equal(parsed.warnings.length, 1);
|
||||
assert.deepEqual(parsed.missingFields, []);
|
||||
});
|
||||
|
||||
test("infer next year for past month range", () => {
|
||||
const parsed = parseFlightSearchRequest("11월 말부터 12월 초까지 출발", {
|
||||
now: new Date("2026-12-20T00:00:00Z"),
|
||||
});
|
||||
|
||||
assert.equal(parsed.departureDateWindow.from, "2027-11-21");
|
||||
assert.equal(parsed.departureDateWindow.to, "2027-12-10");
|
||||
});
|
||||
|
||||
test("parse max stops when explicit layover phrase is present", () => {
|
||||
const parsed = parseFlightSearchRequest("인천->마드리드 1회 경유 20시간 이하");
|
||||
|
||||
assert.equal(parsed.constraints.maxStops, 1);
|
||||
assert.deepEqual(parsed.constraints.maxJourneyHours, { hours: 20, operator: "<=" });
|
||||
});
|
||||
Reference in New Issue
Block a user