Jobber/shared/src/location-support.test.ts
Shaheer Sarfaraz c5c6675f04
feat: add Adzuna extractor with orchestrator integration (#177)
* feat(settings): add adzuna source fields and country compatibility

* feat(discovery): integrate adzuna extractor into pipeline

* feat(client): wire adzuna in source selection and run budgeting

* docs(extractors): add adzuna guide and configuration notes

* chore(workspaces): register adzuna extractor in lockfile

* fix(adzuna): run extractor via npm script instead of npx

* fix(adzuna): execute extractor via node+tsx without shell

* fix(adzuna): prefer npm run start without shell, fallback to tsx

* fix(docker): include adzuna extractor workspace in image

* chore(adzuna): reuse shared type-conversion utilities

* type-check adzuna

* formatting

* deeedooop

* better instructions
2026-02-17 16:49:42 +00:00

90 lines
3.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
formatCountryLabel,
getAdzunaCountryCode,
getCompatibleSourcesForCountry,
isGlassdoorCountry,
isSourceAllowedForCountry,
isUkCountry,
normalizeCountryKey,
SUPPORTED_COUNTRY_KEYS,
} from "./location-support";
describe("location-support", () => {
it("normalizes country aliases", () => {
expect(normalizeCountryKey("UK")).toBe("united kingdom");
expect(normalizeCountryKey("us")).toBe("united states");
expect(normalizeCountryKey("usa")).toBe("united states");
expect(normalizeCountryKey("czech republic")).toBe("czechia");
});
it("formats country labels", () => {
expect(formatCountryLabel("united kingdom")).toBe("United Kingdom");
expect(formatCountryLabel("usa/ca")).toBe("USA/CA");
expect(formatCountryLabel("south korea")).toBe("South Korea");
});
it("keeps supported country keys unique and canonical", () => {
expect(SUPPORTED_COUNTRY_KEYS).toContain("united kingdom");
expect(SUPPORTED_COUNTRY_KEYS).toContain("united states");
expect(SUPPORTED_COUNTRY_KEYS).toContain("worldwide");
expect(SUPPORTED_COUNTRY_KEYS).not.toContain("uk");
expect(SUPPORTED_COUNTRY_KEYS).not.toContain("us");
});
it("treats only united kingdom as UK country", () => {
expect(isUkCountry("united kingdom")).toBe(true);
expect(isUkCountry("UK")).toBe(true);
expect(isUkCountry("worldwide")).toBe(false);
expect(isUkCountry("usa/ca")).toBe(false);
expect(isUkCountry("united states")).toBe(false);
});
it("applies source compatibility rules by country", () => {
expect(isSourceAllowedForCountry("gradcracker", "united kingdom")).toBe(
true,
);
expect(isSourceAllowedForCountry("ukvisajobs", "uk")).toBe(true);
expect(isSourceAllowedForCountry("gradcracker", "united states")).toBe(
false,
);
expect(isSourceAllowedForCountry("ukvisajobs", "worldwide")).toBe(false);
expect(isSourceAllowedForCountry("indeed", "united states")).toBe(true);
expect(isSourceAllowedForCountry("linkedin", "worldwide")).toBe(true);
expect(isSourceAllowedForCountry("glassdoor", "united states")).toBe(true);
expect(isSourceAllowedForCountry("glassdoor", "japan")).toBe(false);
expect(isSourceAllowedForCountry("adzuna", "united states")).toBe(true);
expect(isSourceAllowedForCountry("adzuna", "japan")).toBe(false);
});
it("filters incompatible sources while preserving compatible order", () => {
expect(
getCompatibleSourcesForCountry(
[
"gradcracker",
"indeed",
"glassdoor",
"ukvisajobs",
"adzuna",
"linkedin",
],
"united states",
),
).toEqual(["indeed", "glassdoor", "adzuna", "linkedin"]);
});
it("supports glassdoor only in explicitly supported countries", () => {
expect(isGlassdoorCountry("united kingdom")).toBe(true);
expect(isGlassdoorCountry("uk")).toBe(true);
expect(isGlassdoorCountry("usa")).toBe(true);
expect(isGlassdoorCountry("japan")).toBe(false);
expect(isGlassdoorCountry("worldwide")).toBe(false);
});
it("maps adzuna country keys to adzuna api country codes", () => {
expect(getAdzunaCountryCode("united states")).toBe("us");
expect(getAdzunaCountryCode("UK")).toBe("gb");
expect(getAdzunaCountryCode("japan")).toBeNull();
});
});