fix(portal-clis): accept full posting URLs in jobbank, jobdanmark, and jobnet detail commands (#430)

This commit is contained in:
Abhinav
2026-09-06 10:45:44 +02:00
committed by GitHub
parent fd89eac178
commit 71674d0220
10 changed files with 204 additions and 11 deletions
@@ -0,0 +1,41 @@
import { describe, expect, test } from "bun:test"
import { normalizeJobId } from "../src/helpers.js"
import { runCLI } from "./helpers.js"
describe("jobbank-search normalizeJobId", () => {
test("accepts bare numeric ID", () => {
expect(normalizeJobId("304212")).toBe("304212")
expect(normalizeJobId(" 12345 ")).toBe("12345")
})
test("extracts ID from full URL with trailing slash", () => {
expect(normalizeJobId("https://jobbank.dk/job/304212/")).toBe("304212")
})
test("extracts ID from full URL without trailing slash", () => {
expect(normalizeJobId("https://jobbank.dk/job/304212")).toBe("304212")
})
test("extracts ID from full URL with company/role slug segments", () => {
expect(normalizeJobId("https://jobbank.dk/job/304212/acme-corp/software-developer")).toBe("304212")
expect(normalizeJobId("https://jobbank.dk/job/304212/acme-corp/software-developer/")).toBe("304212")
})
test("extracts ID from URL with query parameters and hash fragments", () => {
expect(normalizeJobId("https://jobbank.dk/job/304212?ref=search&page=1")).toBe("304212")
expect(normalizeJobId("https://jobbank.dk/job/304212#apply")).toBe("304212")
})
test("rejects invalid non-numeric strings and unrelated URLs", () => {
expect(normalizeJobId("abc")).toBeNull()
expect(normalizeJobId("https://example.com/other/12345")).toBeNull()
expect(normalizeJobId("")).toBeNull()
})
test("CLI detail command rejects invalid ID format with BAD_ID", async () => {
const result = await runCLI(["detail", "invalid-id-format"])
expect(result.exitCode).toBe(1)
const err = JSON.parse(result.stderr)
expect(err.code).toBe("BAD_ID")
})
})