mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-09-17 08:36:25 +00:00
The location regex required whitespace after the 4-digit postcode, but live companyAddress values frequently read "2670, Greve" - those results emitted location: null (7/30 in the review's live sample; 1/30 after this fix), leaving /scrape's geography filter nothing to act on. Extraction is now a helper with a comma fallback that requires a non-digit city start, so a 4-digit street number never wins over the real postcode, and the captured city is trimmed. Review finding F2 (2026-08-19). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
91 lines
2.5 KiB
TypeScript
91 lines
2.5 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { normalizeItem, type ApiSearchItem } from "../src/commands/search";
|
|
|
|
function item(): ApiSearchItem {
|
|
return {
|
|
title: "Softwareudvikler",
|
|
companyName: "Statens It",
|
|
companyLogo: null,
|
|
companyLogoSvgMarkup: null,
|
|
overlayColor: null,
|
|
companyAddress: "Lautruphøj 2, 2750 Ballerup",
|
|
jobTypes: ["fuldtid"],
|
|
boostJob: false,
|
|
publishedDate: "27-07-2026",
|
|
applicationDeadline: "17-08-2026",
|
|
url: "/job/softwareudvikler-til-statens-it",
|
|
coverImage: null,
|
|
silhouetteLogo: false,
|
|
};
|
|
}
|
|
|
|
describe("Jobdanmark search normalization", () => {
|
|
test("additively emits the /scrape contract fields (company, location, date, deadline)", () => {
|
|
const result = normalizeItem(item());
|
|
|
|
expect(result).toMatchObject({
|
|
company: "Statens It",
|
|
location: "Ballerup",
|
|
date: "2026-07-27",
|
|
deadline: "2026-08-17",
|
|
url: "https://jobdanmark.dk/job/softwareudvikler-til-statens-it",
|
|
});
|
|
});
|
|
|
|
test("maps a missing address zip and a null deadline to null", () => {
|
|
const result = normalizeItem({
|
|
...item(),
|
|
companyAddress: "Lautruphøj 2",
|
|
applicationDeadline: null,
|
|
});
|
|
|
|
expect(result.location).toBeNull();
|
|
expect(result.deadline).toBeNull();
|
|
expect(result.company).toBe("Statens It");
|
|
});
|
|
|
|
test("extracts the city when a comma follows the postcode (live jobdanmark shape)", () => {
|
|
const result = normalizeItem({
|
|
...item(),
|
|
companyAddress: "2670, Greve",
|
|
});
|
|
|
|
expect(result.location).toBe("Greve");
|
|
});
|
|
|
|
test("trims trailing whitespace from the extracted city", () => {
|
|
const result = normalizeItem({
|
|
...item(),
|
|
companyAddress: "7100, Vejle ",
|
|
});
|
|
|
|
expect(result.location).toBe("Vejle");
|
|
});
|
|
|
|
test("does not mistake a 4-digit street number for the postcode", () => {
|
|
const result = normalizeItem({
|
|
...item(),
|
|
companyAddress: "Vejlevej 1234, 7100 Vejle",
|
|
});
|
|
|
|
expect(result.location).toBe("Vejle");
|
|
});
|
|
|
|
test("survives a null companyAddress from the API", () => {
|
|
const result = normalizeItem({
|
|
...item(),
|
|
companyAddress: null,
|
|
});
|
|
|
|
expect(result.location).toBeNull();
|
|
expect(result.company).toBe("Statens It");
|
|
});
|
|
|
|
test("keeps native fields unchanged (additive contract)", () => {
|
|
const result = normalizeItem(item());
|
|
|
|
expect(result.companyName).toBe("Statens It");
|
|
expect(result.publishedDate).toBe("27-07-2026");
|
|
expect(result.applicationDeadline).toBe("17-08-2026");
|
|
});
|
|
}); |