Files
manyangles/apps/web/src/server/location-search.test.ts
T

23 lines
1.3 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import { parseLocationResults } from "./location-search";
import { updateEventInputSchema } from "@album/contracts";
import { openStreetMapEmbedUrl } from "@/lib/maps";
describe("event locations", () => {
test("maps GeoJSON longitude/latitude correctly and deduplicates matches", () => {
const feature = { geometry: { coordinates: [-72.7, 40.9] }, properties: { name: "Raceway", city: "Riverhead" } };
expect(parseLocationResults({ features: [feature, feature] })).toEqual([
{ address: "Raceway, Riverhead", latitude: 40.9, longitude: -72.7 },
]);
});
test("rejects impossible coordinates from the provider and event input", () => {
expect(parseLocationResults({ features: [{ geometry: { coordinates: [200, 95] }, properties: { name: "Bad" } }] })).toEqual([]);
expect(updateEventInputSchema.safeParse({ eventId: "7fa618fc-3fcb-4fd4-a0af-03f14124cccc", locationCoordinates: { latitude: 95, longitude: 0 } }).success).toBe(false);
});
test("keeps zero coordinates and uses latitude first in the OSM marker", () => {
const url = new URL(openStreetMapEmbedUrl(0, 12));
expect(url.searchParams.get("marker")).toBe("0,12");
expect(url.searchParams.get("bbox")).toBe("11.992,-0.008,12.008,0.008");
});
});