Skip to content
Open
13 changes: 6 additions & 7 deletions contract/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"openapi": "3.1.0",
"info": {
"title": "Wego API",
"description": "Wego's travel API: places, flights, hotels and fares. Please see https://docs.wego.com for more details.",
"version": "0.19.1"
"description": "Wego's travel API: places, flights, hotels and fares. Please see https://agents.wego.com for more details.",
"version": "0.19.5"
},
"tags": [
{
Expand Down Expand Up @@ -57,8 +57,8 @@
"description": "OAuth2 authorization-code flow (PKCE supported) against the Wego auth server.",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://auth.wego.com/user-auth/v2/users/oauth/authorize",
"tokenUrl": "https://auth.wego.com/user-auth/v2/users/oauth/token",
"authorizationUrl": "https://auth.example.invalid/user-auth/v2/users/oauth/authorize",
"tokenUrl": "https://auth.example.invalid/user-auth/v2/users/oauth/token",
"x-scalar-client-id": "251815b9647317f4895122fd4924b7d44541d8fcc27be528435e3ad9bbf7e1ee",
"x-usePkce": "SHA-256",
"scopes": {
Expand Down Expand Up @@ -582,7 +582,7 @@
"operationId": "getPlaces",
"tags": ["Places"],
"summary": "Resolve travel locations",
"description": "Resolves a free-text location query to canonical Wego places (cities, airports, states, districts, hotels) with codes and coordinates, for use in later flight and hotel searches. When metadata.hasAmbiguity is true, clarify with the user before proceeding.",
"description": "Resolves a free-text location query to canonical Wego places (cities, airports, states, districts, hotels) with codes and coordinates, for use in later flight and hotel searches. A numeric query also matches a city code. When metadata.hasAmbiguity is true, clarify with the user before proceeding.",
"responses": {
"200": {
"description": "Matching places plus pagination/ambiguity metadata.",
Expand Down Expand Up @@ -5006,9 +5006,8 @@
"properties": {
"cityCode": {
"type": "string",
"pattern": "^[A-Z]{3}$",
"example": "DXB",
"description": "City code to search. One destination only, see oneOf."
"description": "City code to search: a 3-letter code, or the numeric code some cities carry (Makkah is 8283). One destination only, see oneOf."
},
"hotelId": {
"type": "integer",
Expand Down
107 changes: 102 additions & 5 deletions integration/flights.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import { describe, expect, it } from "bun:test";
import { type Answer, problem } from "./harness/fake";
import { answer, readFixture, route } from "./harness/fixtures";
import { answer, placesKnowing, readFixture, route } from "./harness/fixtures";
import { useScenario } from "./harness/scenario";
import { json, signIn, writeSettings } from "./harness/wego";

Expand Down Expand Up @@ -1003,10 +1003,13 @@ describe("flights booking-link", () => {

describe("flights share", () => {
const leg = ["flights", "share", "SIN", "BKK", "2099-09-15"];
const SHARE_PLACES = placesKnowing({ SIN: "city", BKK: "city" });

it("maps positionals and every flag to the query and prints the durable URL", async () => {
signIn(s.home);
const fake = s.fake({ routes: [route("flights-search-link")] });
const fake = s.fake({
routes: [route("flights-search-link"), ...SHARE_PLACES],
});
const result = await s.run([
...leg,
"--return",
Expand Down Expand Up @@ -1052,7 +1055,9 @@ describe("flights share", () => {
it("inherits the stored currency, locale and site, over the account market", async () => {
signIn(s.home, { accessToken: "access-1", market: "AE" });
writeSettings(s.home, { currency: "SAR", locale: "ar", site: "SA" });
const fake = s.fake({ routes: [route("flights-search-link")] });
const fake = s.fake({
routes: [route("flights-search-link"), ...SHARE_PLACES],
});
expect((await s.run(leg)).code).toBe(0);
expect(query(fake.requests("getFlightSearchLink")[0])).toMatchObject({
currency: "SAR",
Expand All @@ -1064,7 +1069,9 @@ describe("flights share", () => {
it("an explicit flag beats the stored setting", async () => {
signIn(s.home);
writeSettings(s.home, { currency: "SAR", site: "SA" });
const fake = s.fake({ routes: [route("flights-search-link")] });
const fake = s.fake({
routes: [route("flights-search-link"), ...SHARE_PLACES],
});
expect(
(await s.run([...leg, "--currency", "USD", "--site", "SG"])).code,
).toBe(0);
Expand All @@ -1077,7 +1084,9 @@ describe("flights share", () => {
for (const cabin of ["economy", "premium_economy", "business", "first"]) {
it(`accepts the published cabin ${cabin}`, async () => {
signIn(s.home);
const fake = s.fake({ routes: [route("flights-search-link")] });
const fake = s.fake({
routes: [route("flights-search-link"), ...SHARE_PLACES],
});
expect((await s.run([...leg, "--cabin", cabin])).code).toBe(0);
expect(fake.requests("getFlightSearchLink")[0]?.query.get("cabin")).toBe(
cabin,
Expand Down Expand Up @@ -1123,6 +1132,94 @@ describe("flights share", () => {
expect(fake.seen).toEqual([]);
});

it("refuses a code that resolves to no city or airport: exit 6, no link built", async () => {
signIn(s.home);
const fake = s.fake({
routes: [route("flights-search-link"), ...SHARE_PLACES],
});
const result = await s.run([
"flights",
"share",
"ZZZ",
"BKK",
"2099-09-15",
]);

expect(result.code).toBe(6);
expect(result.out).toBe("");
expect(result.err).toContain(
'the from code "ZZZ" resolves to no city or airport',
);
expect(result.err).toContain("wego places <name>");
expect(result.err).not.toMatch(/retry/i);
expect(fake.requests("getFlightSearchLink")).toHaveLength(0);
expect(
fake
.requests("getPlaces")
.map((r) => r.query.get("query"))
.sort(),
).toEqual(["BKK", "ZZZ"]);
});

it("names both codes when neither resolves", async () => {
signIn(s.home);
s.fake({ routes: [route("flights-search-link"), ...SHARE_PLACES] });
const result = await s.run([
"flights",
"share",
"ZZZ",
"QQQ",
"2099-09-15",
]);

expect(result.code).toBe(6);
expect(result.err).toContain(
'the from code "ZZZ" and the to code "QQQ" resolve to no city or airport',
);
});

it("accepts an airport code Places reports", async () => {
signIn(s.home);
const fake = s.fake({
routes: [
route("flights-search-link"),
...placesKnowing({ LHR: "airport", BKK: "city" }),
],
});
const result = await s.run([
"flights",
"share",
"LHR",
"BKK",
"2099-09-15",
]);

expect(result.code).toBe(0);
expect(fake.requests("getFlightSearchLink")).toHaveLength(1);
});

it("--from-city refuses a code that is only an airport", async () => {
signIn(s.home);
const fake = s.fake({
routes: [
route("flights-search-link"),
...placesKnowing({ LHR: "airport", BKK: "city" }),
],
});
const result = await s.run([
"flights",
"share",
"LHR",
"BKK",
"2099-09-15",
"--from-city",
]);

expect(result.code).toBe(6);
expect(result.err).toContain('the from code "LHR" resolves to no city.');
expect(fake.requests("getFlightSearchLink")).toHaveLength(0);
});

it("--help prints its usage on stdout with exit 0", async () => {
const result = await s.run(["flights", "share", "--help"]);
expect(result.code).toBe(0);
Expand Down
28 changes: 27 additions & 1 deletion integration/harness/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { readdirSync, readFileSync } from "node:fs";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import type { Answer, Route } from "./fake";
import type { Answer, Route, Seen } from "./fake";

export const FIXTURES_DIR = fileURLToPath(
new URL("../fixtures/", import.meta.url),
Expand Down Expand Up @@ -59,3 +59,29 @@ export function route(
answers: answers.map((a) => (typeof a === "string" ? answer(a) : a)),
};
}

/**
* `getPlaces` routes that know exactly `known` (code to place type). A query
* for any other code finds nothing, which is how the API answers an unknown one.
*/
export function placesKnowing(known: Record<string, string>): Route[] {
const page = (results: unknown[]) =>
answer("places", () => ({
results,
metadata: {
resultCount: results.length,
totalCandidates: results.length,
hasMore: false,
hasAmbiguity: false,
},
}));
const op = readFixture("places").op;
return [
...Object.entries(known).map(([code, type], i) => ({
op,
answers: [page([{ id: i + 1, code, name: code, type, cityCode: code }])],
when: (seen: Seen) => seen.query.get("query") === code,
})),
{ op, answers: [page([])] },
];
}
Loading
Loading