mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-09-17 00:26:26 +00:00
fix(jobdanmark-search): emit the /scrape contract fields in search output (#340)
Adds additive normalization so jobdanmark search output carries the cross-portal contract fields: company from companyName, location as the city after the postal code in companyAddress (null-safe - a missing or null address yields null instead of crashing the search), and date/deadline converted from DD-MM-YYYY to YYYY-MM-DD with safe passthrough on unexpected formats. Native fields unchanged. Co-authored-by: oscarbol09 <80536682+oscarbol09@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
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("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");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user