Files
Jobber/shared/src/blocked-countries.test.ts
T
ilia 84e6835b11
CI / skip-ci-check (push) Successful in 10s
CI / secret-scan (push) Successful in 14s
CI / docker-ci (push) Successful in 17s
feat: keyword sets, sponsorship signals, and extractor/profile fixes
Add per-profile keyword sets, job source settings, sponsorship signal pills,
and several ATS extractors. Fix Hiring Cafe discovery via Next.js SSR search,
profile activate for comma-separated basicAuthUser aliases, and resume path
backfill migrations. Update settings and hiring-cafe docs; localhost compose
overlay for loopback-only deploys.
2026-06-11 10:23:39 -04:00

108 lines
3.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
inferCountryKeysFromJobText,
isVagueJobLocation,
jobMatchesAllowedCountry,
jobMatchesBlockedCountries,
normalizeBlockedCountryTokens,
resolveBlockedCountriesFromStoredString,
} from "./blocked-countries.js";
describe("blocked-countries", () => {
it("normalizes country tokens to canonical keys", () => {
expect(normalizeBlockedCountryTokens(["India", "UK", "bogus"])).toEqual([
"india",
"united kingdom",
]);
});
it("parses JSON and legacy comma-separated storage", () => {
expect(
resolveBlockedCountriesFromStoredString(JSON.stringify(["India"])),
).toEqual(["india"]);
expect(resolveBlockedCountriesFromStoredString("india, Poland")).toEqual([
"india",
"poland",
]);
});
it("matches jobs whose location includes a blocked country", () => {
const blocked = resolveBlockedCountriesFromStoredString('["india"]');
expect(
jobMatchesBlockedCountries("Bangalore, Karnataka, India", blocked),
).toBe(true);
expect(jobMatchesBlockedCountries("Toronto, ON, Canada", blocked)).toBe(
false,
);
expect(jobMatchesBlockedCountries("Remote", blocked)).toBe(false);
expect(jobMatchesBlockedCountries(null, blocked)).toBe(false);
});
it("treats worldwide and remote-only locations as vague", () => {
expect(isVagueJobLocation("Worldwide")).toBe(true);
expect(isVagueJobLocation("Remote")).toBe(true);
expect(isVagueJobLocation("Toronto, Canada")).toBe(false);
});
it("finds blocked countries in description when location is worldwide", () => {
const blocked = resolveBlockedCountriesFromStoredString('["india"]');
expect(
jobMatchesBlockedCountries(
{
location: "Worldwide",
jobDescription:
"Job Location: Mumbai/Nagpur. We are hiring in India for this role.",
},
blocked,
),
).toBe(true);
expect(
jobMatchesBlockedCountries(
{
location: "Worldwide",
jobDescription: "Fully remote team across North America.",
},
blocked,
),
).toBe(false);
});
it("infers country names embedded in free text", () => {
expect(
inferCountryKeysFromJobText(
"Harrier is hiring in India. Job Location: Mumbai/Nagpur",
),
).toContain("india");
});
it("allows only jobs clearly in the selected search country", () => {
expect(jobMatchesAllowedCountry("Toronto, ON, Canada", "canada")).toBe(
true,
);
expect(jobMatchesAllowedCountry("Vancouver, BC", "canada")).toBe(true);
expect(
jobMatchesAllowedCountry("Bangalore, Karnataka, India", "canada"),
).toBe(false);
expect(jobMatchesAllowedCountry("Remote", "canada")).toBe(false);
expect(jobMatchesAllowedCountry("Worldwide", "canada")).toBe(false);
expect(
jobMatchesAllowedCountry(
{
location: "Remote",
jobDescription: "Hiring in India only.",
},
"canada",
),
).toBe(false);
expect(
jobMatchesAllowedCountry(
{
location: "Remote",
jobDescription: "Remote across Canada.",
},
"canada",
),
).toBe(true);
});
});