diff --git a/plugins/atshosts/oracle.py b/plugins/atshosts/oracle.py new file mode 100644 index 0000000..1e44cb6 --- /dev/null +++ b/plugins/atshosts/oracle.py @@ -0,0 +1,183 @@ +"""Oracle Recruiting Cloud: `oracle:/`, for example +`oracle:fa-ewto-saasfaprod1.fa.ocs.oraclecloud.com/CX_1001`. A paged REST +listing that states its total, and a per-role resource for the description. + +The host is the tenant's Fusion pod (`fa-...ocs.oraclecloud.com`), not the +company's own domain: Nokia's `jobs.nokia.com` only redirects to it. The site +number is `CX_1001` or `CX_1` on the tenants read so far, and the site's own +name (`SinchCareer`) is taken in its place. Written from live boards on +2026-09-29 (Milestone Systems, Nokia, Danske Bank, Sinch); jobhunt-hq did not +read Oracle. +""" + +from __future__ import annotations + +import html +import json +import re +from collections.abc import Callable +from typing import Any +from urllib.parse import quote + +from desk.sources import strip_html + +from ._shared import Get, Page, Row, only, parse_dt + +NAME = "oracle" +LABEL = "Oracle Recruiting Cloud" +KEEP_CASE = True +PATTERNS = ( + # The candidate site or one role's page: `/hcmUI/CandidateExperience/en/sites/CX_1/jobs`. + r"https?://([a-z0-9-]+(?:\.[a-z0-9-]+)*\.oraclecloud\.(?:com|eu))" + r"/hcmUI/CandidateExperience/[A-Za-z_-]+/sites/([A-Za-z0-9_-]+)", + # The REST call a company's own page makes, which names the site as `siteNumber=`. + r"https?://([a-z0-9-]+(?:\.[a-z0-9-]+)*\.oraclecloud\.(?:com|eu))" + r"/hcmRestApi/resources/[a-z0-9.]+/recruitingCEJobRequisitions[^\"'\s]*?siteNumber=([A-Za-z0-9_-]+)", + # No slug: another page of a tenant's Fusion UI (its sign-in, say), which names + # the host but no candidate site. + r"oraclecloud\.(?:com|eu)/hcmUI(?!/CandidateExperience/[A-Za-z_-]+/sites/)", +) + +#: The page size asked for. 200 was answered in full by Nokia (600 roles in +#: three calls of about 360 KB, 2026-09-29); the cursor advances by what a page +#: returned, so a tenant that caps `limit` lower would not skip a role. +PAGE_SIZE = 200 + +#: A pod: `fa-ewto-saasfaprod1.fa.ocs.oraclecloud.com`. Oracle's regions also +#: use `.eu` (Danske Bank's `ejqi.fa.ocs.oraclecloud.eu`). A host name has no +#: case, so a slug written with capitals is allowed as its lowercase. +_HOST = r"[a-z0-9-]+(?:\.[a-z0-9-]+)*\.oraclecloud\.(?:com|eu)" +_SLUG = re.compile(rf"({_HOST})/([A-Za-z0-9_-]+)", re.IGNORECASE) + +#: `WorkplaceTypeCode` -> `store._remote`'s words. A role that states none +#: has an empty code, which stays unknown. +_REMOTE = {"ora_remote": "remote", "ora_hybrid": "hybrid", "ora_on_site": "onsite"} + + +def _parts(slug: str) -> tuple[str, str]: + """`(host, site number)` of a slug that passed `slug_ok`.""" + host, _, site = slug.partition("/") + return host.lower(), site + + +def slug_ok(slug: str) -> bool: + return bool(_SLUG.fullmatch(slug)) + + +def allowed(slug: str) -> Callable[[str], bool]: + return only(_parts(slug)[0]) + + +def _base(slug: str) -> str: + host, site = _parts(slug) + return f"https://{host}/hcmUI/CandidateExperience/en/sites/{site}" + + +def careers_url(slug: str) -> str: + return f"{_base(slug)}/jobs" + + +def robots_page(slug: str) -> str: + return careers_url(slug) + + +def _api(slug: str) -> str: + return f"https://{_parts(slug)[0]}/hcmRestApi/resources/latest" + + +def page(get: Get, slug: str, cursor: Any) -> Page: + """One page of `recruitingCEJobRequisitions`. The answer's outer `count`, + `hasMore` and `limit` describe the one search wrapper in `items`, so the + total (`TotalJobsCount`) and the roles (`requisitionList`) are read from + `items[0]`. Without the `expand` only the facets come back; asking for + `requisitionList.secondaryLocations` gives the roles and each one's other + locations, which the plain `requisitionList` leaves out. Past the last role + the list is empty.""" + offset = int(cursor or 0) + site = _parts(slug)[1] + data = json.loads(get( + f"{_api(slug)}/recruitingCEJobRequisitions?onlyData=true" + f"&expand=requisitionList.secondaryLocations" + f"&finder=findReqs;siteNumber={site},limit={PAGE_SIZE},offset={offset}")) + search = (data.get("items") or [{}])[0] + roles = search.get("requisitionList") or [] + # `_paged` counts `id`, which Oracle spells `Id`. + results = [{"id": str(role.get("Id") or "")} for role in roles] + return search, results, search.get("TotalJobsCount"), offset + len(roles) if roles else None + + +def parse(body: bytes, slug: str) -> list[Row]: + return rows((json.loads(body).get("items") or [{}])[0], slug) + + +def _text(value: Any) -> str: + return value.strip() if isinstance(value, str) else "" + + +def _plain(value: Any) -> str: + """Plain text from a field of HTML, entities (`&`, ` `) included.""" + return html.unescape(strip_html(_text(value))).replace("\xa0", " ").strip() + + +def rows(search: dict[str, Any], slug: str) -> list[Row]: + """The roles of one page's search wrapper. The list carries the title, the + id, `PostedDate` (a date), `PrimaryLocation` ("Copenhagen, Denmark"; a + country alone where the role names no city), `secondaryLocations`, + `WorkplaceTypeCode` and `ShortDescriptionStr`, one paragraph that Nokia + and Milestone fill for most roles. The department fields (`JobFamily`, + `Department`, `Organization`) were null on every role of all four boards + read, and are taken when a tenant fills them. The full description is in + the role's own resource, see `detail`. No pay is stated.""" + out = [] + for role in search.get("requisitionList") or []: + role_id = str(role.get("Id") or "").strip() + title = _text(role.get("Title")) + # The id goes into a URL, and a listing is external content. + if not title or not re.fullmatch(r"[A-Za-z0-9_-]+", role_id): + continue + places: list[str] = [] + for name in (_text(role.get("PrimaryLocation")), + *(_text(s.get("Name")) for s in role.get("secondaryLocations") or [] + if isinstance(s, dict))): + if name and name not in places: + places.append(name) + out.append({ + "source_id": role_id, + "title": title, + "location": "; ".join(places), + "url": f"{_base(slug)}/job/{role_id}", + "posted": parse_dt(role.get("PostedDate")), + "department": (_text(role.get("JobFamily")) or _text(role.get("JobFunction")) + or _text(role.get("Department")) or _text(role.get("Organization"))), + "description": _plain(role.get("ShortDescriptionStr")), + "remote": _REMOTE.get(_text(role.get("WorkplaceTypeCode")).lower()), + "salary_text": "", # the resource states no pay + }) + return out + + +def detail(get: Get, slug: str, row: Row) -> dict[str, Any]: + """The role's own resource (`recruitingCEJobRequisitionDetails`, found by + `Id` and site). Only here is the full text: `ExternalDescriptionStr`, with + the responsibilities and qualifications strings after it where a tenant + fills them (Milestone leaves them empty), all HTML. `ExternalPostedStartDate` + is a timestamp where the listing has a date. A role that is no longer open + answers 200 with no items, and has nothing to read.""" + site = _parts(slug)[1] + role_id = quote(str(row["source_id"]), safe="") + data = json.loads(get( + f"{_api(slug)}/recruitingCEJobRequisitionDetails?expand=all&onlyData=true" + f"&finder=ById;Id=%22{role_id}%22,siteNumber={site}")) + items = data.get("items") or [] + if not items: + return {} + role = items[0] + text = " ".join(part for key in ("ExternalDescriptionStr", "ExternalResponsibilitiesStr", + "ExternalQualificationsStr") + if (part := _plain(role.get(key)))) + out: dict[str, Any] = {} + if text: + out["description"] = text + if posted := parse_dt(role.get("ExternalPostedStartDate")): + out["posted"] = posted + return out diff --git a/plugins/atshosts/phenom.py b/plugins/atshosts/phenom.py new file mode 100644 index 0000000..260a6d4 --- /dev/null +++ b/plugins/atshosts/phenom.py @@ -0,0 +1,229 @@ +"""Phenom: `phenom://`, the career site a company runs +on its own domain, at the locale root it uses: `phenom:careers.king.com/us/en`, +`phenom:www.careers.philips.com/global/en`. A JSON search that pages by offset +and states its total. + +The listing is the `POST /widgets` call the site's own search page makes. It +answered without a cookie, an `Origin` header, a `pageId` or the site's +`refNum`, so the body carries none of them: only the locale (`lang`, +`country`, both read off the slug's path) and the paging. Nothing is taken +from the page's script. Written from live sites on 2026-09-29 (King, Just Eat +Takeaway, Philips); jobhunt-hq did not read Phenom. +""" + +from __future__ import annotations + +import html +import json +import re +from collections.abc import Callable +from typing import Any + +from desk.sources import strip_html + +from ._shared import Get, Page, Row, only, parse_dt + +NAME = "phenom" +LABEL = "Phenom" +PATTERNS = ( + # A link to the site's search page, the one URL of a Phenom site that carries + # both the host and the locale root and is named the same on every one. + r"https?://([a-z0-9-]+(?:\.[a-z0-9-]+)*\.[a-z][a-z0-9-]*)/([a-z]{2,8})/([a-z]{2})/search-results", + # No slug: a page that loads Phenom's own assets, on a site whose locale + # root discovery has not seen. The host is known, the board is not. + r"phenompeople\.com|phenom\.com/careers", +) + +#: The page size asked for. 100 is what the site's own search sends; `size` +#: 200 was answered in full by Just Eat Takeaway and 500 by Philips (of 865), +#: but a page is 340 KB at 100 roles already. +PAGE_SIZE = 100 + +#: A DNS name with a dot and a letter first in its last label, so an address +#: (`127.0.0.1`) or a single word (`localhost`) never names a site the fetch +#: could be pointed at; `ats._get` still refuses local names and every host +#: but this one, redirects included. Then the locale root: `country/lang`, +#: which every Phenom site read so far writes as `global/en`, `na/en`, `us/en`. +_SLUG = re.compile(r"[a-z0-9-]+(?:\.[a-z0-9-]+)*\.[a-z][a-z0-9-]*/[a-z]{2,8}/[a-z]{2}") + + +def _parts(slug: str) -> tuple[str, str, str]: + """`(host, country, lang)` of a slug that passed `slug_ok`.""" + host, country, lang = slug.split("/") + return host, country, lang + + +def slug_ok(slug: str) -> bool: + return bool(_SLUG.fullmatch(slug)) + + +def allowed(slug: str) -> Callable[[str], bool]: + return only(_parts(slug)[0]) + + +def _root(slug: str) -> str: + host, country, lang = _parts(slug) + return f"https://{host}/{country}/{lang}" + + +def careers_url(slug: str) -> str: + return f"{_root(slug)}/search-results" + + +def robots_page(slug: str) -> str: + return careers_url(slug) + + +def _body(slug: str, offset: int) -> dict[str, Any]: + """What the site's search page sends for a listing of every role, newest + first, less the parts that only tell the page what to draw. `lang` is + `en_global` for `/global/en` and `en_us` for `/us/en`, the site's own + spelling on the three sites read.""" + _host, country, lang = _parts(slug) + return { + "lang": f"{lang}_{country}", "deviceType": "desktop", "country": country, + "pageName": "search-results", "ddoKey": "refineSearch", "sortBy": "", + "subsearch": "", "from": offset, "jobs": True, "counts": True, "all_fetch": False, + "pageType": "landingPage", "size": PAGE_SIZE, "clearAll": False, + "jdsource": "facets", "isSliderEnable": False, "siteType": "external", + "location": "", "keywords": "", "global": True, "selected_fields": {}, + "sort": {"order": "desc", "field": "postedDate"}, "locationData": {}, + } + + +def _key(job: dict[str, Any]) -> str: + """The role's id on the board: `jobSeqNo`, which carries the site and the + language and is the one of the three ids (`jobSeqNo`, `jobId`, `reqId`) + that the site's job page takes on every site read. `reqId` is not unique + across languages.""" + return str(job.get("jobSeqNo") or job.get("jobId") or job.get("reqId") or "").strip() + + +def page(get: Get, slug: str, cursor: Any) -> Page: + offset = int(cursor or 0) + host = _parts(slug)[0] + data = json.loads(get(f"https://{host}/widgets", method="POST", + payload=_body(slug, offset))) + search = data.get("refineSearch") + if not isinstance(search, dict) or search.get("status", 200) != 200: + raise ValueError("not a Phenom search answer: no refineSearch") + jobs = (search.get("data") or {}).get("jobs") or [] + results = [{"id": _key(job)} for job in jobs] + return search, results, search.get("totalHits"), offset + len(jobs) if jobs else None + + +def parse(body: bytes, slug: str) -> list[Row]: + return rows(json.loads(body).get("refineSearch") or {}, slug) + + +def _text(value: Any) -> str: + return value.strip() if isinstance(value, str) else "" + + +def _plain(value: Any) -> str: + return html.unescape(strip_html(_text(value))).replace("\xa0", " ").strip() + + +def _slug_of(title: str) -> str: + """The decorative last part of a role's URL, its title with runs of + anything but letters and digits as one dash; it matches the site's own + (checked on all 32 roles of King's sitemap). The page is found by the id.""" + return re.sub(r"[^A-Za-z0-9]+", "-", title).strip("-") + + +def rows(search: dict[str, Any], slug: str) -> list[Row]: + """The roles of one page, `refineSearch.data.jobs`. A role has the title, + `jobSeqNo`, `postedDate` (a date at midnight), `category`, the locations + as `multi_location` (a list, one per place) beside `location` (the first), + and `descriptionTeaser`, the first paragraph of the text; the full text is + on the role's page, see `detail`. `applyUrl` points at the apply system + (Workday for Just Eat Takeaway and Philips), so the role's URL is its page + on the site. No remote flag and no pay are in the list.""" + out = [] + for job in search.get("data", {}).get("jobs") or []: + key = _key(job) + title = _text(job.get("title")) + if not title or not key: + continue + places: list[str] = [] + for place in (*(job.get("multi_location") or []), job.get("location")): + if isinstance(place, str) and place.strip() and place.strip() not in places: + places.append(place.strip()) + tail = _slug_of(title) + out.append({ + "source_id": key, + "title": title, + "location": "; ".join(places), + "url": f"{_root(slug)}/job/{key}" + (f"/{tail}" if tail else ""), + "posted": parse_dt(job.get("postedDate")), + "department": _text(job.get("category")), + "description": _plain(job.get("descriptionTeaser")), + "remote": None, # the list does not say + "salary_text": "", # nor does it state pay + }) + return out + + +#: The JSON-LD blocks of a page; a Phenom job page has one `JobPosting` and, +#: on Philips's, a `BreadcrumbList` and more. +_JSON_LD = re.compile(r"]+application/ld\+json[^>]*>(.*?)", re.S | re.I) + + +#: Where a page assigns its state, and the words its `checkRemote` says that +#: `store._remote` reads (King's pages say "On-site"; no other was seen). +_STATE = "phApp.ddo = " +_REMOTE = {"remote": "remote", "hybrid": "hybrid", "on-site": "onsite", "onsite": "onsite"} + + +def _job_posting(body: str) -> dict[str, Any]: + """The `JobPosting` among a page's JSON-LD blocks, or {}.""" + for block in _JSON_LD.findall(body): + try: + found = json.loads(block) + except ValueError: + continue + for candidate in found if isinstance(found, list) else [found]: + if isinstance(candidate, dict) and candidate.get("@type") == "JobPosting": + return candidate + return {} + + +def _page_job(body: str) -> dict[str, Any]: + """The role as the page's own state holds it, `phApp.ddo.jobDetail.data.job`, + or {}. King's pages of roles posted the same day had no `JobPosting`, and + this had the full description. Only that one object is read: the state + around it holds the site's session values, which nothing here uses.""" + start = body.find(_STATE) + if start < 0: + return {} + try: + state, _end = json.JSONDecoder().raw_decode(body, start + len(_STATE)) + job = state["jobDetail"]["data"]["job"] + except (ValueError, KeyError, TypeError): + return {} + return job if isinstance(job, dict) else {} + + +def detail(get: Get, slug: str, row: Row) -> dict[str, Any]: + """The full description from the role's page: the `JobPosting` in its + JSON-LD, whose `description` is HTML with its entities escaped (`<p>` + and `&` inside), so it is unescaped, stripped and unescaped again; or, + where the page has none, the page state's own `description`, which is + plain HTML. A page with neither raises, so the role is asked again on a + later pull instead of counting as read with no text. `datePosted` is taken + as `posted`: it can be earlier than the list's `postedDate` (Philips's list + said the day of the read for a role whose page said 2026-09-08), and a role + keeps the earliest date it ever had. King's page state says `checkRemote`.""" + body = get(row["url"], headers={"Accept": "text/html"}).decode("utf-8", "replace") + posting, job = _job_posting(body), _page_job(body) + out: dict[str, Any] = {} + if description := (_plain(html.unescape(_text(posting.get("description")))) + or _plain(job.get("description"))): + out["description"] = description + else: + raise ValueError("no description on the role's page") + if posted := parse_dt(posting.get("datePosted")): + out["posted"] = posted + if remote := _REMOTE.get(_text(job.get("checkRemote")).lower()): + out["remote"] = remote + return out diff --git a/tests/fixtures/ats/oracle-detail.json b/tests/fixtures/ats/oracle-detail.json new file mode 100644 index 0000000..0365d0a --- /dev/null +++ b/tests/fixtures/ats/oracle-detail.json @@ -0,0 +1,107 @@ +{ + "items": [ + { + "Id": "24594", + "Title": "Support Professional", + "Category": "Customer Support", + "RequisitionType": "Full time Permanent", + "JobGrade": null, + "RequisitionId": 300000164708671, + "ExternalPostedStartDate": "2026-09-28T15:09:24+00:00", + "JobLevel": null, + "JobSchedule": null, + "JobShift": null, + "StudyLevel": null, + "InternationalTravelRequired": null, + "ExternalContactName": null, + "ExternalContactEmail": null, + "ContractType": null, + "ExternalPostedEndDate": null, + "JobFamilyId": 300000004434468, + "GeographyId": 100000037181451, + "GeographyNodeId": 100000092726195, + "ExternalDescriptionStr": "

Be the key in unlocking business opportunities in the convergent world of Open Platform IP Video Management Systems! Join Milestone!

Milestone Systems, Inc. is looking for a skilled Support Professional to work in a hybrid position (Tuesday through Thursday) at our US Headquarters located in beautiful Lake Oswego, Oregon. The shift for this role is 6:00 a.m. to 3:00 p.m. Relocation assistance is not provided for this position, and minimum pay is $70,000 per year and can go up depending on experience. 

We are looking for someone who enjoys working with cutting edge technology and helping individuals use it effectively. If you are a believer in the use of technology to enhance daily living, then this is the place for you. The Technical Support Professional is typically a first point of contact with Milestone customers and therefore has a key role in helping Milestone achieve its mission goal of delivering excellent customer experiences. The SP delivers responsive and reliable solutions to Milestone Partners through application of knowledge of Milestone organization, services, and products. This position will report to our Manager, Technical Support.

As a Technical Support Professional, you have a key role in helping Milestone to achieve its mission goal of delivering great customer and partner experience. 

As part of an international support team, you will operate in a fast-paced dynamic environment united in one common passion \u2013 to be the ...", + "CorporateDescriptionStr": "", + "OrganizationDescriptionStr": "", + "ShortDescriptionStr": "", + "ContentLocale": "en", + "PrimaryLocation": "Lake Oswego, OR, United States", + "PrimaryLocationCountry": "US", + "ObjectVerNumberProfile": null, + "ApplyWhenNotPostedFlag": null, + "ExternalQualificationsStr": "", + "InternalQualificationsStr": "", + "InternalResponsibilitiesStr": "", + "ExternalResponsibilitiesStr": "", + "JobFunctionCode": null, + "HotJobFlag": false, + "TrendingFlag": false, + "BeFirstToApplyFlag": false, + "WorkplaceTypeCode": null, + "WorkplaceType": "", + "OtherRequisitionTitle": null, + "NumberOfOpenings": null, + "HiringManager": null, + "Organization": null, + "BusinessUnitId": 300000004214148, + "LegalEmployerId": 300000004310622, + "OrganizationId": 1, + "WorkerType": null, + "JobType": null, + "WorkMonths": null, + "WorkYears": null, + "WorkHours": null, + "WorkDays": null, + "LegalEmployer": null, + "BusinessUnit": null, + "Department": null, + "DomesticTravelRequired": null, + "JobFunction": null, + "secondaryLocations": [], + "media": [], + "workLocation": [ + { + "LocationId": 300000004214036, + "LocationName": "Portland", + "AddressLine1": "5300 Meadows Rd, Suite 400", + "AddressLine2": null, + "AddressLine3": null, + "AddressLine4": null, + "Building": null, + "TownOrCity": "Lake Oswego", + "PostalCode": "OR 97035", + "Country": "US", + "Region1": null, + "Region2": null, + "Region3": null, + "Longitude": "-122.72792", + "Latitude": "45.41083" + } + ], + "otherWorkLocations": [], + "requisitionFlexFields": [], + "primaryLocationCoordinates": [ + { + "GeographyNodeId": 100000092726195, + "GeographyId": 100000037181451, + "Latitude": "45.38764", + "Longitude": "-122.74389", + "CountryCode": "US" + } + ], + "skills": [] + } + ], + "count": 1, + "hasMore": false, + "limit": 499, + "offset": 0, + "links": [ + { + "rel": "self", + "href": "https://fa-ewto-saasfaprod1.fa.ocs.oraclecloud.com:443/hcmRestApi/resources/11.13.18.05/recruitingCEJobRequisitionDetails", + "name": "recruitingCEJobRequisitionDetails", + "kind": "collection" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ats/oracle.json b/tests/fixtures/ats/oracle.json new file mode 100644 index 0000000..3350995 --- /dev/null +++ b/tests/fixtures/ats/oracle.json @@ -0,0 +1,302 @@ +{ + "items": [ + { + "SearchId": 1, + "Keyword": null, + "CorrectedKeyword": null, + "UseExactKeywordFlag": false, + "SuggestedKeyword": null, + "ExecuteSpellCheckFlag": true, + "Location": null, + "LocationId": null, + "Radius": 0, + "RadiusUnit": "MI", + "Facets": "TITLES;LOCATIONS;LOCATION_LEVEL1;LOCATION_LEVEL2;LOCATION_LEVEL3;CATEGORIES;POSTING_DATES;WORK_LOCATIONS;FLEX_FIELDS;ORGANIZATIONS;WORKPLACE_TYPES", + "Offset": 0, + "Limit": 5, + "SortBy": "RELEVANCY", + "TotalJobsCount": 600, + "Latitude": null, + "Longitude": null, + "SiteNumber": "CX_1", + "JobFamilyId": null, + "PostingStartDate": null, + "PostingEndDate": null, + "RequisitionId": null, + "CandidateNumber": null, + "WorkLocationZipCode": null, + "WorkLocationCountryCode": null, + "SelectedFlexFieldsFacets": null, + "OrganizationId": null, + "UserTargetFacetName": null, + "UserTargetFacetInputTerm": null, + "HotJobFlag": null, + "WorkplaceType": null, + "BotQRShortCode": null, + "requisitionList": [ + { + "Id": "39905", + "Title": "Supply Chain Program Manager", + "PostedDate": "2026-09-28", + "PostingEndDate": null, + "Language": "US", + "PrimaryLocationCountry": "TH", + "GeographyId": 300000000480081, + "HotJobFlag": true, + "WorkplaceTypeCode": "ORA_HYBRID", + "JobFamily": null, + "JobFunction": null, + "WorkerType": null, + "ContractType": null, + "ManagerLevel": null, + "JobSchedule": null, + "JobShift": null, + "JobType": null, + "StudyLevel": null, + "DomesticTravelRequired": null, + "InternationalTravelRequired": null, + "WorkDurationYears": null, + "WorkDurationMonths": null, + "WorkHours": null, + "WorkDays": null, + "LegalEmployer": null, + "BusinessUnit": null, + "Department": null, + "Organization": null, + "BusinessUnitId": 300000006664259, + "LegalEmployerId": 300000006365816, + "OrganizationId": 10003297, + "MediaThumbURL": null, + "ShortDescriptionStr": "Nokia is searching for a Supply Chain Program Management Leader to support our local contract manufacturers in SE Asia across multiple Subsystems products. This person will be accountable to work in a cross functional team with local Nokia teams and our ...", + "PrimaryLocation": "Thailand", + "Distance": 15, + "TrendingFlag": false, + "BeFirstToApplyFlag": false, + "Relevancy": 15, + "WorkplaceType": "Hybrid", + "ExternalQualificationsStr": null, + "ExternalResponsibilitiesStr": null, + "secondaryLocations": [ + { + "RequisitionLocationId": 300002190470822, + "GeographyNodeId": 100002145190119, + "GeographyId": 300000000471904, + "Name": "Malaysia", + "CountryCode": "MY", + "Latitude": 4.38933, + "Longitude": 102.08986 + } + ] + }, + { + "Id": "37189", + "Title": "IP NPI Specialist", + "PostedDate": "2026-09-24", + "PostingEndDate": null, + "Language": "US", + "PrimaryLocationCountry": "MY", + "GeographyId": 300000000471904, + "HotJobFlag": true, + "WorkplaceTypeCode": "ORA_HYBRID", + "JobFamily": null, + "JobFunction": null, + "WorkerType": null, + "ContractType": null, + "ManagerLevel": null, + "JobSchedule": null, + "JobShift": null, + "JobType": null, + "StudyLevel": null, + "DomesticTravelRequired": null, + "InternationalTravelRequired": null, + "WorkDurationYears": null, + "WorkDurationMonths": null, + "WorkHours": null, + "WorkDays": null, + "LegalEmployer": null, + "BusinessUnit": null, + "Department": null, + "Organization": null, + "BusinessUnitId": 300000006664259, + "LegalEmployerId": 300000006365205, + "OrganizationId": 53235948, + "MediaThumbURL": null, + "ShortDescriptionStr": "The New Product Introduction Specialist defines and execute demos, proof of concept, type approvals tests, field trials, and in general any New Product Introduction (NPI) related activities with our customer for any new product or solution. Accountable from ...", + "PrimaryLocation": "Malaysia", + "Distance": 13, + "TrendingFlag": false, + "BeFirstToApplyFlag": false, + "Relevancy": 13, + "WorkplaceType": "Hybrid", + "ExternalQualificationsStr": null, + "ExternalResponsibilitiesStr": null, + "secondaryLocations": [ + { + "RequisitionLocationId": 300001975383156, + "GeographyNodeId": 100002145190018, + "GeographyId": 300000000471961, + "Name": "Philippines", + "CountryCode": "PH", + "Latitude": 17.20662, + "Longitude": 121.6106 + }, + { + "RequisitionLocationId": 300002107689780, + "GeographyNodeId": 100002145190100, + "GeographyId": 300000000471733, + "Name": "Indonesia", + "CountryCode": "ID", + "Latitude": 2.82116, + "Longitude": 99.61807 + }, + { + "RequisitionLocationId": 300002107689781, + "GeographyNodeId": 100002145190039, + "GeographyId": 300000000480081, + "Name": "Thailand", + "CountryCode": "TH", + "Latitude": 13.75336, + "Longitude": 100.50483 + } + ] + }, + { + "Id": "40316", + "Title": "Safety Manager 3", + "PostedDate": "2026-09-28", + "PostingEndDate": null, + "Language": "US", + "PrimaryLocationCountry": "IN", + "GeographyId": 300000000471745, + "HotJobFlag": true, + "WorkplaceTypeCode": "ORA_ON_SITE", + "JobFamily": null, + "JobFunction": null, + "WorkerType": null, + "ContractType": null, + "ManagerLevel": null, + "JobSchedule": null, + "JobShift": null, + "JobType": null, + "StudyLevel": null, + "DomesticTravelRequired": null, + "InternationalTravelRequired": null, + "WorkDurationYears": null, + "WorkDurationMonths": null, + "WorkHours": null, + "WorkDays": null, + "LegalEmployer": null, + "BusinessUnit": null, + "Department": null, + "Organization": null, + "BusinessUnitId": 300000006664246, + "LegalEmployerId": 300000006387938, + "OrganizationId": 10008015, + "MediaThumbURL": null, + "ShortDescriptionStr": "The Safety Manager is responsible for leading Health, Safety, and Environment (HSE) operations at the Nokia Repair Factory in Gurgaon. This role ensures a safe, healthy, and compliant workplace by driving risk management initiatives, regulatory compliance, ...", + "PrimaryLocation": "India", + "Distance": 15, + "TrendingFlag": true, + "BeFirstToApplyFlag": false, + "Relevancy": 15, + "WorkplaceType": "Onsite", + "ExternalQualificationsStr": null, + "ExternalResponsibilitiesStr": null, + "secondaryLocations": [] + }, + { + "Id": "40975", + "Title": "High-Speed Converters Test and Validation Engineer", + "PostedDate": "2026-09-28", + "PostingEndDate": null, + "Language": "US", + "PrimaryLocationCountry": "DE", + "GeographyId": 300000000471601, + "HotJobFlag": false, + "WorkplaceTypeCode": null, + "JobFamily": null, + "JobFunction": null, + "WorkerType": null, + "ContractType": null, + "ManagerLevel": null, + "JobSchedule": null, + "JobShift": null, + "JobType": null, + "StudyLevel": null, + "DomesticTravelRequired": null, + "InternationalTravelRequired": null, + "WorkDurationYears": null, + "WorkDurationMonths": null, + "WorkHours": null, + "WorkDays": null, + "LegalEmployer": null, + "BusinessUnit": null, + "Department": null, + "Organization": null, + "BusinessUnitId": 300000006664259, + "LegalEmployerId": 300001149364006, + "OrganizationId": 300000806569044, + "MediaThumbURL": null, + "ShortDescriptionStr": "We are looking for a High-Speed ADC/DAC Test Engineer with strong hands-on laboratory experience. This is a practical, lab-focused engineering position for someone who is comfortable working directly with high-frequency test and measurement equipment and has ...", + "PrimaryLocation": "Germany", + "Distance": 9, + "TrendingFlag": false, + "BeFirstToApplyFlag": false, + "Relevancy": 9, + "WorkplaceType": "", + "ExternalQualificationsStr": null, + "ExternalResponsibilitiesStr": null, + "secondaryLocations": [] + }, + { + "Id": "31680", + "Title": "Sr. Director of Application Engineering", + "PostedDate": "2026-07-15", + "PostingEndDate": null, + "Language": "US", + "PrimaryLocationCountry": "US", + "GeographyId": 300000000480126, + "HotJobFlag": true, + "WorkplaceTypeCode": "ORA_REMOTE", + "JobFamily": null, + "JobFunction": null, + "WorkerType": null, + "ContractType": null, + "ManagerLevel": null, + "JobSchedule": null, + "JobShift": null, + "JobType": null, + "StudyLevel": null, + "DomesticTravelRequired": null, + "InternationalTravelRequired": null, + "WorkDurationYears": null, + "WorkDurationMonths": null, + "WorkHours": null, + "WorkDays": null, + "LegalEmployer": null, + "BusinessUnit": null, + "Department": null, + "Organization": null, + "BusinessUnitId": 300000006664259, + "LegalEmployerId": 300001149319675, + "OrganizationId": 300000806569328, + "MediaThumbURL": null, + "ShortDescriptionStr": "As the Sr. Director of Applications Engineering for Photonic Component Solutions at Nokia, you will be at the forefront of integrating advanced photonics technology into the Hyperscaler and optical module markets. Your core mission is to connect innovative ...", + "PrimaryLocation": "United States", + "Distance": 7, + "TrendingFlag": true, + "BeFirstToApplyFlag": false, + "Relevancy": 7, + "WorkplaceType": "Remote", + "ExternalQualificationsStr": null, + "ExternalResponsibilitiesStr": null, + "secondaryLocations": [] + } + ] + } + ], + "count": 1, + "hasMore": false, + "limit": 5, + "offset": 0 +} \ No newline at end of file diff --git a/tests/fixtures/ats/phenom-detail-2.html b/tests/fixtures/ats/phenom-detail-2.html new file mode 100644 index 0000000..0c2b862 --- /dev/null +++ b/tests/fixtures/ats/phenom-detail-2.html @@ -0,0 +1,7 @@ + + +Zone Business Leader Imaging Nordics job in Denmark - Remote Based, Denmark, Denmark | Sales jobs at Philips + + + + diff --git a/tests/fixtures/ats/phenom-detail-3.html b/tests/fixtures/ats/phenom-detail-3.html new file mode 100644 index 0000000..991245c --- /dev/null +++ b/tests/fixtures/ats/phenom-detail-3.html @@ -0,0 +1,6 @@ + + +Principal Economy Designer | New Games in Barcelona, Spain | Games Design & Production at King + + + diff --git a/tests/fixtures/ats/phenom-detail.html b/tests/fixtures/ats/phenom-detail.html new file mode 100644 index 0000000..7ad025c --- /dev/null +++ b/tests/fixtures/ats/phenom-detail.html @@ -0,0 +1,6 @@ + + +Product Analyst in Stockholm, Stockholm County, Sweden | Data, Analytics & Strategy at King + + + diff --git a/tests/fixtures/ats/phenom.json b/tests/fixtures/ats/phenom.json new file mode 100644 index 0000000..73887e0 --- /dev/null +++ b/tests/fixtures/ats/phenom.json @@ -0,0 +1,322 @@ +{ + "refineSearch": { + "status": 200, + "hits": 5, + "totalHits": 32, + "data": { + "jobs": [ + { + "type": "Regular", + "descriptionTeaser": "Become part of our team and help shape the economic and systemic foundations of an unannounced Merge 2 game. Take ownership of the game\u2019s economy, ensuring a clear, sustainable player journey. Ideal for a senior designer with proven ...", + "state": "", + "siteType": "external", + "multi_category": [ + "Games Design & Production" + ], + "reqId": "R028168", + "city": "Barcelona", + "latitude": "41.38879", + "multi_location": [ + "Barcelona, Spain", + "London, London, United Kingdom", + "Stockholm, Stockholm County, Sweden" + ], + "address": "Carrer Ciutat de Granada, 150, Floor 16th Floor, 08018 Barcelona, Spain", + "applyUrl": "https://xboxgaming.wd1.myworkdayjobs.com/King_External_Careers/job/Barcelona---King---PG/Principal-Economy-Designer---New-Games_R028168/apply", + "externalApply": false, + "cityState": "Barcelona", + "country": "Spain", + "visibilityType": "External", + "longitude": "2.15899", + "jobId": "R028168", + "locale": "en_US", + "title": "Principal Economy Designer | New Games", + "jobSeqNo": "ACMKDSUSR028168EXTERNALENUS", + "postedDate": "2026-09-29T00:00:00.000+0000", + "dateCreated": "2026-09-29T09:59:51.253+0000", + "cityStateCountry": "Barcelona, Spain", + "jobVisibility": [ + "external" + ], + "location": "Barcelona, Spain", + "category": "Games Design & Production", + "isMultiLocation": true, + "multi_location_array": [ + { + "latlong": { + "lon": 2.15899, + "lat": 41.38879 + }, + "location": "Barcelona, Spain" + }, + { + "latlong": { + "lon": -0.12574, + "lat": 51.50853 + }, + "location": "London, London, United Kingdom" + }, + { + "latlong": { + "lon": 18.06871, + "lat": 59.32938 + }, + "location": "Stockholm, Stockholm County, Sweden" + } + ], + "isMultiCategory": false, + "multi_category_array": [ + { + "category": "Games Design & Production" + } + ], + "badge": "" + }, + { + "type": "Regular", + "descriptionTeaser": "Take on the role of Senior Data Visualisation Engineer to develop and maintain dashboards and analytical tools for business intelligence. Collaborate with cross-functional teams to deliver insightful visualisations and support high-volume ...", + "state": "Stockholm County", + "siteType": "external", + "multi_category": [ + "Technology & Development" + ], + "reqId": "R027656", + "city": "Stockholm", + "latitude": "59.32938", + "multi_location": [ + "Stockholm, Stockholm County, Sweden" + ], + "address": "Malmskillnadsgatan 19, 111 57 Stockholm, Sweden", + "applyUrl": "https://xboxgaming.wd1.myworkdayjobs.com/King_External_Careers/job/Stockholm---King---Malmskillnadsgatan/Senior-Data-Visualisation-Engineer--12mth-FTC-_R027656-1/apply", + "externalApply": false, + "cityState": "Stockholm, Stockholm County", + "country": "Sweden", + "visibilityType": "External", + "longitude": "18.06871", + "jobId": "R027656", + "locale": "en_US", + "title": "Senior Data Visualisation Engineer (12mth FTC)", + "jobSeqNo": "ACMKDSUSR027656EXTERNALENUS", + "postedDate": "2026-09-28T00:00:00.000+0000", + "dateCreated": "2026-06-15T17:02:06.245+0000", + "cityStateCountry": "Stockholm, Stockholm County, Sweden", + "jobVisibility": [ + "external" + ], + "location": "Stockholm, Stockholm County, Sweden", + "category": "Technology & Development", + "isMultiLocation": true, + "multi_location_array": [ + { + "latlong": { + "lon": 18.06871, + "lat": 59.32938 + }, + "location": "Stockholm, Stockholm County, Sweden" + } + ], + "isMultiCategory": false, + "multi_category_array": [ + { + "category": "Technology & Development" + } + ], + "badge": "" + }, + { + "type": "Regular", + "descriptionTeaser": "We are looking for a Technical Artist to shape the visual direction of new games, collaborating with artists, designers, and engineers to deliver polished, in-engine experiences. This senior role focuses on building shaders, materials, and ...", + "state": "London", + "siteType": "external", + "multi_category": [ + "Other" + ], + "reqId": "R028172", + "city": "London", + "latitude": "51.50853", + "multi_location": [ + "London, London, United Kingdom", + "Barcelona, Spain", + "Stockholm, Stockholm County, Sweden" + ], + "address": "The Ampersand Building, 178 Wardour Street, London, London, W1F 8FY, United Kingdom", + "applyUrl": "https://xboxgaming.wd1.myworkdayjobs.com/King_External_Careers/job/London---King---Ampersand/Technical-Artist---New-Games_R028172-1/apply", + "externalApply": false, + "cityState": "London, London", + "country": "United Kingdom", + "visibilityType": "External", + "longitude": "-0.12574", + "jobId": "R028172", + "locale": "en_US", + "title": "Technical Artist | New Games", + "jobSeqNo": "ACMKDSUSR028172EXTERNALENUS", + "postedDate": "2026-09-28T00:00:00.000+0000", + "dateCreated": "2026-09-28T13:01:25.961+0000", + "cityStateCountry": "London, London, United Kingdom", + "jobVisibility": [ + "external" + ], + "location": "London, London, United Kingdom", + "category": "Other", + "isMultiLocation": true, + "multi_location_array": [ + { + "latlong": { + "lon": -0.12574, + "lat": 51.50853 + }, + "location": "London, London, United Kingdom" + }, + { + "latlong": { + "lon": 2.15899, + "lat": 41.38879 + }, + "location": "Barcelona, Spain" + }, + { + "latlong": { + "lon": 18.06871, + "lat": 59.32938 + }, + "location": "Stockholm, Stockholm County, Sweden" + } + ], + "isMultiCategory": false, + "multi_category_array": [ + { + "category": "Other" + } + ], + "badge": "" + }, + { + "type": "Regular", + "descriptionTeaser": "We are currently hiring an Engineering Manager to lead the development and evolution of shared platforms supporting King\u2019s games. Drive high-performing teams, foster innovation, and ensure impactful delivery. Ideal for experienced leaders ...", + "state": "Stockholm County", + "siteType": "external", + "multi_category": [ + "Technology & Development" + ], + "reqId": "R028147", + "city": "Stockholm", + "latitude": "59.32938", + "multi_location": [ + "Stockholm, Stockholm County, Sweden", + "Barcelona, Spain" + ], + "address": "Malmskillnadsgatan 19, 111 57 Stockholm, Sweden", + "applyUrl": "https://xboxgaming.wd1.myworkdayjobs.com/King_External_Careers/job/Stockholm---King---Malmskillnadsgatan/Engineering-Manager---Shared-Tech_R028147/apply", + "externalApply": false, + "cityState": "Stockholm, Stockholm County", + "country": "Sweden", + "visibilityType": "External", + "longitude": "18.06871", + "jobId": "R028147", + "locale": "en_US", + "title": "Engineering Manager | Shared Tech", + "jobSeqNo": "ACMKDSUSR028147EXTERNALENUS", + "postedDate": "2026-09-28T00:00:00.000+0000", + "dateCreated": "2026-09-22T13:01:36.026+0000", + "cityStateCountry": "Stockholm, Stockholm County, Sweden", + "jobVisibility": [ + "external" + ], + "location": "Stockholm, Stockholm County, Sweden", + "category": "Technology & Development", + "isMultiLocation": true, + "multi_location_array": [ + { + "latlong": { + "lon": 18.06871, + "lat": 59.32938 + }, + "location": "Stockholm, Stockholm County, Sweden" + }, + { + "latlong": { + "lon": 2.15899, + "lat": 41.38879 + }, + "location": "Barcelona, Spain" + } + ], + "isMultiCategory": false, + "multi_category_array": [ + { + "category": "Technology & Development" + } + ], + "badge": "" + }, + { + "type": "Regular", + "descriptionTeaser": "Join us as a Principal Game Designer to shape the core gameplay of a new King casual puzzle game. Lead the design and evolution of engaging, challenging levels and interaction systems, collaborating with multidisciplinary teams. Ideal for ...", + "state": "London", + "siteType": "external", + "multi_category": [ + "Other" + ], + "reqId": "R028167", + "city": "London", + "latitude": "51.50853", + "multi_location": [ + "London, London, United Kingdom", + "Barcelona, Spain", + "Stockholm, Stockholm County, Sweden" + ], + "address": "The Ampersand Building, 178 Wardour Street, London, London, W1F 8FY, United Kingdom", + "applyUrl": "https://xboxgaming.wd1.myworkdayjobs.com/King_External_Careers/job/London---King---Ampersand/Principal-Game-Designer---New-Games_R028167/apply", + "externalApply": false, + "cityState": "London, London", + "country": "United Kingdom", + "visibilityType": "External", + "longitude": "-0.12574", + "jobId": "R028167", + "locale": "en_US", + "title": "Principal Game Designer | New Games", + "jobSeqNo": "ACMKDSUSR028167EXTERNALENUS", + "postedDate": "2026-09-25T00:00:00.000+0000", + "dateCreated": "2026-09-25T13:14:11.065+0000", + "cityStateCountry": "London, London, United Kingdom", + "jobVisibility": [ + "external" + ], + "location": "London, London, United Kingdom", + "category": "Other", + "isMultiLocation": true, + "multi_location_array": [ + { + "latlong": { + "lon": -0.12574, + "lat": 51.50853 + }, + "location": "London, London, United Kingdom" + }, + { + "latlong": { + "lon": 2.15899, + "lat": 41.38879 + }, + "location": "Barcelona, Spain" + }, + { + "latlong": { + "lon": 18.06871, + "lat": 59.32938 + }, + "location": "Stockholm, Stockholm County, Sweden" + } + ], + "isMultiCategory": false, + "multi_category_array": [ + { + "category": "Other" + } + ], + "badge": "" + } + ] + } + } +} \ No newline at end of file diff --git a/tests/test_ats_oracle.py b/tests/test_ats_oracle.py new file mode 100644 index 0000000..6a3591e --- /dev/null +++ b/tests/test_ats_oracle.py @@ -0,0 +1,284 @@ +"""Oracle Recruiting Cloud: the listing's rows from a saved page (Nokia's, +trimmed), paging and completeness against a fake `get`, the role's own resource +for the description (Milestone's, trimmed), the slug, and discovery's patterns. +No network.""" + +from __future__ import annotations + +import copy +import json +import sys +from pathlib import Path +from typing import Any + +import httpx +import pytest + +ROOT = Path(__file__).resolve().parents[1] +if str(ROOT) not in sys.path: + sys.path.insert(0, str(ROOT)) + +from app.jobs.discover import boards_in # noqa: E402 +from plugins import ats # noqa: E402 +from plugins.atshosts import oracle # noqa: E402 +from plugins.atshosts._shared import is_web_url # noqa: E402 + +FIXTURES = ROOT / "tests" / "fixtures" / "ats" +HOST = "fa-evmr-saasfaprod1.fa.ocs.oraclecloud.com" +SLUG = f"{HOST}/CX_1" +API = f"https://{HOST}/hcmRestApi/resources/latest" + + +def _listing() -> dict[str, Any]: + return json.loads((FIXTURES / "oracle.json").read_bytes()) + + +def _rows() -> list[ats.Row]: + return oracle.parse((FIXTURES / "oracle.json").read_bytes(), SLUG) + + +# ------------------------------------------------------------------- rows + +def test_rows_carry_the_listing_fields() -> None: + rows = _rows() + assert [r["source_id"] for r in rows] == ["39905", "37189", "40316", "40975", "31680"] + first = rows[0] + assert first["title"] == "Supply Chain Program Manager" + assert first["url"] == f"https://{HOST}/hcmUI/CandidateExperience/en/sites/CX_1/job/39905" + assert first["posted"] is not None and first["posted"].isoformat() == "2026-09-28T00:00:00+00:00" + assert first["description"].startswith("Nokia is searching for a Supply Chain Program") + assert first["salary_text"] == "" and "salary_min" not in first + assert all(is_web_url(r["url"]) for r in rows) + + +def test_the_locations_are_the_primary_and_the_secondary_ones() -> None: + rows = _rows() + assert rows[0]["location"] == "Thailand; Malaysia" + assert rows[1]["location"] == "Malaysia; Philippines; Indonesia; Thailand" + assert rows[2]["location"] == "India" + + +def test_remote_follows_the_workplace_type_code() -> None: + assert [r["remote"] for r in _rows()] == ["hybrid", "hybrid", "onsite", None, "remote"] + + +def test_a_department_is_taken_where_a_tenant_fills_one() -> None: + """All four boards read left the department fields null.""" + assert {r["department"] for r in _rows()} == {""} + data = _listing() + data["items"][0]["requisitionList"][0]["JobFamily"] = " Supply Chain " + data["items"][0]["requisitionList"][1]["Department"] = "Finance" + rows = oracle.parse(json.dumps(data).encode(), SLUG) + assert [r["department"] for r in rows[:3]] == ["Supply Chain", "Finance", ""] + + +def test_a_role_without_a_title_or_with_an_id_that_is_no_id_is_left_out() -> None: + data = _listing() + roles = data["items"][0]["requisitionList"] + roles[0]["Title"] = " " + roles[1]["Id"] = "1/../../x" + roles[2]["Id"] = "" + assert [r["source_id"] for r in oracle.parse(json.dumps(data).encode(), SLUG)] == \ + ["40975", "31680"] + + +def test_a_listing_without_the_expand_has_no_roles() -> None: + """Without `expand=requisitionList` the answer is the facets only.""" + data = _listing() + del data["items"][0]["requisitionList"] + assert oracle.parse(json.dumps(data).encode(), SLUG) == [] + + +# ----------------------------------------------------------------- paging + +@pytest.fixture +def no_delay(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setattr(ats, "PAGE_DELAY", 0) + + +def _fake(monkeypatch: pytest.MonkeyPatch, total: int | None = None) -> list[str]: + """`ats._get` answering the listing from the saved roles, `limit` and + `offset` honoured as Oracle does, and a page past the end empty.""" + asked: list[str] = [] + every = _listing()["items"][0]["requisitionList"] + + def fake_get(client, url, host, slug, *, method="GET", payload=None, headers=None, + www_twin=False): + asked.append(url) + limit = int(url.split("limit=")[1].split(",")[0]) + offset = int(url.split("offset=")[1]) + data = _listing() + data["items"][0]["requisitionList"] = every[offset:offset + limit] + data["items"][0]["TotalJobsCount"] = len(every) if total is None else total + return json.dumps(data).encode() + + monkeypatch.setattr(ats, "_get", fake_get) + return asked + + +def test_the_listing_is_paged_by_limit_and_offset_to_the_stated_total( + monkeypatch: pytest.MonkeyPatch, no_delay: None) -> None: + asked = _fake(monkeypatch) + monkeypatch.setattr(oracle, "PAGE_SIZE", 2) + rows, complete = ats._fetch_rows(object(), f"oracle:{SLUG}") # type: ignore[arg-type] + find = "onlyData=true&expand=requisitionList.secondaryLocations&finder=findReqs;siteNumber=CX_1" + assert asked == [f"{API}/recruitingCEJobRequisitions?{find},limit=2,offset=0", + f"{API}/recruitingCEJobRequisitions?{find},limit=2,offset=2", + f"{API}/recruitingCEJobRequisitions?{find},limit=2,offset=4"] + assert [r["source_id"] for r in rows] == ["39905", "37189", "40316", "40975", "31680"] + assert complete + + +def test_a_board_that_ends_short_of_its_total_is_incomplete( + monkeypatch: pytest.MonkeyPatch, no_delay: None) -> None: + """The total says 7 and the page past the fifth role is empty.""" + _fake(monkeypatch, total=7) + monkeypatch.setattr(oracle, "PAGE_SIZE", 2) + rows, complete = ats._fetch_rows(object(), f"oracle:{SLUG}") # type: ignore[arg-type] + assert (len(rows), complete) == (5, False) + + +def test_a_small_board_is_one_page(monkeypatch: pytest.MonkeyPatch, no_delay: None) -> None: + asked = _fake(monkeypatch) + rows, complete = ats._fetch_rows(object(), f"oracle:{SLUG}") # type: ignore[arg-type] + assert len(asked) == 1 and f"limit={oracle.PAGE_SIZE},offset=0" in asked[0] + assert (len(rows), complete) == (5, True) + + +def test_an_empty_board_is_complete(monkeypatch: pytest.MonkeyPatch, no_delay: None) -> None: + data = _listing() + data["items"][0]["requisitionList"] = [] + data["items"][0]["TotalJobsCount"] = 0 + monkeypatch.setattr(ats, "_get", lambda *a, **k: json.dumps(data).encode()) + assert ats._fetch_rows(object(), f"oracle:{SLUG}") == ([], True) # type: ignore[arg-type] + + +# ----------------------------------------------------------------- detail + +def _detail_get(body: bytes, asked: list[str]) -> Any: + def get(url: str, *, method: str = "GET", payload: Any = None, headers: Any = None) -> bytes: + asked.append(url) + return body + return get + + +def test_detail_reads_the_description_and_the_posting_time() -> None: + asked: list[str] = [] + row = {"source_id": "24594"} + got = oracle.detail(_detail_get((FIXTURES / "oracle-detail.json").read_bytes(), asked), + "fa-ewto-saasfaprod1.fa.ocs.oraclecloud.com/CX_1001", row) + assert asked == [ + "https://fa-ewto-saasfaprod1.fa.ocs.oraclecloud.com/hcmRestApi/resources/latest/" + "recruitingCEJobRequisitionDetails?expand=all&onlyData=true" + "&finder=ById;Id=%2224594%22,siteNumber=CX_1001"] + assert got["description"].startswith("Be the key in unlocking business opportunities") + assert "<" not in got["description"] and " " not in got["description"] + assert "&" not in got["description"] and "\xa0" not in got["description"] + assert got["posted"].isoformat() == "2026-09-28T15:09:24+00:00" + assert set(got) <= set(ats.DETAIL_FIELDS) + + +def test_detail_appends_the_responsibilities_and_qualifications_where_filled() -> None: + data = json.loads((FIXTURES / "oracle-detail.json").read_bytes()) + data["items"][0]["ExternalResponsibilitiesStr"] = "

  • Run the desk
" + data["items"][0]["ExternalQualificationsStr"] = "

Five years & more

" + got = oracle.detail(_detail_get(json.dumps(data).encode(), []), SLUG, {"source_id": "24594"}) + assert got["description"].endswith(" Run the desk Five years & more") + + +def test_detail_of_a_role_no_longer_open_has_nothing_to_read() -> None: + data = copy.deepcopy(json.loads((FIXTURES / "oracle-detail.json").read_bytes())) + data["items"] = [] + assert oracle.detail(_detail_get(json.dumps(data).encode(), []), SLUG, + {"source_id": "1"}) == {} + + +def test_a_role_id_cannot_add_to_the_detail_url() -> None: + asked: list[str] = [] + oracle.detail(_detail_get(b'{"items": []}', asked), SLUG, {"source_id": '1"&x=/../'}) + assert asked[0].endswith("finder=ById;Id=%221%22%26x%3D%2F..%2F%22,siteNumber=CX_1") + + +# ----------------------------------------------------------- slug and URLs + +@pytest.mark.parametrize("slug", [ + "fa-ewto-saasfaprod1.fa.ocs.oraclecloud.com/CX_1001", + "iaings.fa.ocs.oraclecloud.com/SinchCareer", + "ejqi.fa.ocs.oraclecloud.eu/CX_1001", + "a.oraclecloud.com/CX", +]) +def test_a_pod_and_a_site_number_are_a_slug(slug: str) -> None: + assert oracle.slug_ok(slug) and ats.is_known_target(f"oracle:{slug}") + + +@pytest.mark.parametrize("slug", [ + "", "CX_1", "/CX_1", f"{HOST}", f"{HOST}/", f"{HOST}/CX_1/", f"{HOST}/CX_1/jobs", + f"{HOST}/a b", f" {HOST}/CX_1", f"{HOST} /CX_1", f"{HOST}/CX_1\n", f"{HOST}/CX_1 ", + f"{HOST}\n/CX_1", f"{HOST}/CX_1\r\n", + f"{HOST}@evil.com/CX_1", f"evil.com@{HOST}/CX_1", f"{HOST}#x/CX_1", f"{HOST}?x=1/CX_1", + f"{HOST}/CX_1?x=1", f"{HOST}/CX_1#x", f"{HOST}/CX%2f1", f"{HOST}/..", f"{HOST}/.", + f"..{HOST}/CX_1", "../CX_1", f"{HOST}:8443/CX_1", f"{HOST}:443/CX_1", + "localhost/CX_1", "127.0.0.1/CX_1", "[::1]/CX_1", "2130706433/CX_1", + "oraclecloud.com/CX_1", ".oraclecloud.com/CX_1", "evil.com/CX_1", + "fa.oraclecloud.com.evil.com/CX_1", "fa.oraclecloud.com.internal/CX_1", + "fa.oraclecloud.org/CX_1", "fa.oraclecloud.com/a/b", "fa.oraclecloud.com\\CX_1", +]) +def test_a_hostile_slug_is_refused(slug: str) -> None: + assert not oracle.slug_ok(slug) + assert not ats.is_known_target(f"oracle:{slug}") + + +def test_only_the_pod_named_by_the_slug_is_allowed() -> None: + allow = oracle.allowed(SLUG) + assert allow(HOST) and allow(HOST.upper()) + assert not allow("fa-ewto-saasfaprod1.fa.ocs.oraclecloud.com.evil.com") + assert not allow("jobs.nokia.com") and not allow("oraclecloud.com") + assert not allow("fa-evmr-saasfaprod2.fa.ocs.oraclecloud.com") + assert ats._allowed_host("oracle", SLUG)(HOST) + + +def test_the_careers_page_is_the_candidate_site_and_robots_reads_it() -> None: + url = f"https://{HOST}/hcmUI/CandidateExperience/en/sites/CX_1/jobs" + assert oracle.careers_url(SLUG) == ats.careers_url(f"oracle:{SLUG}") == url + assert oracle.robots_page(SLUG) == url + assert oracle.allowed(SLUG)(httpx.URL(oracle.robots_page(SLUG)).host) + + +def test_a_slug_written_with_capitals_names_the_same_pod() -> None: + slug = f"{HOST.upper()}/CX_1" + assert oracle.slug_ok(slug) and oracle.allowed(slug)(HOST) + assert oracle.careers_url(slug).startswith(f"https://{HOST}/") + + +# -------------------------------------------------------------- discovery + +def test_discovery_finds_the_pod_and_the_site_in_a_candidate_site_link() -> None: + page = f'Role' + assert [(h, s) for h, s, _ in boards_in(page)] == [("oracle", SLUG)] + + +def test_discovery_keeps_the_case_of_a_site_name() -> None: + page = "https://iaings.fa.ocs.oraclecloud.com/hcmUI/CandidateExperience/en/sites/SinchCareer/jobs" + assert [(h, s) for h, s, _ in boards_in(page)] == [("oracle", "iaings.fa.ocs.oraclecloud.com/SinchCareer")] + + +def test_discovery_reads_the_site_off_the_rest_call() -> None: + page = ("fetch('https://ejqi.fa.ocs.oraclecloud.eu/hcmRestApi/resources/latest/" + "recruitingCEJobRequisitions?onlyData=true&finder=findReqs;siteNumber=CX_1001,limit=25')") + assert [(h, s) for h, s, _ in boards_in(page)] == [("oracle", "ejqi.fa.ocs.oraclecloud.eu/CX_1001")] + + +def test_discovery_names_a_pod_it_has_no_site_for() -> None: + page = f"https://{HOST}/hcmUI/faces/AtkHomePageWelcome" + assert [(h, s) for h, s, _ in boards_in(page)] == [("oracle", "")] + # A company's own domain, which only redirects to the pod, names nothing. + assert boards_in("https://jobs.nokia.com/en/sites/CX_1") == [] + + +def test_every_slug_discovery_finds_is_a_slug() -> None: + pages = [f"https://{HOST}/hcmUI/CandidateExperience/en/sites/CX_1/jobs", + "https://a.fa.us2.oraclecloud.com/hcmUI/CandidateExperience/fr/sites/CX_1001/job/1", + "https://a.oraclecloud.eu/hcmUI/CandidateExperience/en/sites/X?lang=en"] + for page in pages: + found = boards_in(page) + assert found and all(oracle.slug_ok(slug) for _h, slug, _ in found), page diff --git a/tests/test_ats_phenom.py b/tests/test_ats_phenom.py new file mode 100644 index 0000000..a5ce596 --- /dev/null +++ b/tests/test_ats_phenom.py @@ -0,0 +1,307 @@ +"""Phenom: the listing's rows from a saved `POST /widgets` answer (King's, +trimmed), the request body, paging and completeness against a fake `get`, the +description from a saved job page's JSON-LD (King's and Philips's, trimmed), +the slug, and discovery's patterns. No network.""" + +from __future__ import annotations + +import json +import sys +from pathlib import Path +from typing import Any + +import httpx +import pytest + +ROOT = Path(__file__).resolve().parents[1] +if str(ROOT) not in sys.path: + sys.path.insert(0, str(ROOT)) + +from app.jobs.discover import boards_in # noqa: E402 +from plugins import ats # noqa: E402 +from plugins.atshosts import phenom # noqa: E402 +from plugins.atshosts._shared import is_web_url # noqa: E402 + +FIXTURES = ROOT / "tests" / "fixtures" / "ats" +SLUG = "careers.king.com/us/en" +IDS = ["ACMKDSUSR028168EXTERNALENUS", "ACMKDSUSR027656EXTERNALENUS", + "ACMKDSUSR028172EXTERNALENUS", "ACMKDSUSR028147EXTERNALENUS", + "ACMKDSUSR028167EXTERNALENUS"] + + +def _answer() -> dict[str, Any]: + return json.loads((FIXTURES / "phenom.json").read_bytes()) + + +def _rows() -> list[ats.Row]: + return phenom.parse((FIXTURES / "phenom.json").read_bytes(), SLUG) + + +# ------------------------------------------------------------------- rows + +def test_rows_carry_the_listing_fields() -> None: + rows = _rows() + assert [r["source_id"] for r in rows] == IDS + first = rows[0] + assert first["title"] == "Principal Economy Designer | New Games" + assert first["department"] == "Games Design & Production" + assert first["posted"] is not None and first["posted"].isoformat() == "2026-09-29T00:00:00+00:00" + assert first["description"].startswith("Become part of our team and help shape the economic") + assert first["remote"] is None and first["salary_text"] == "" + assert all(is_web_url(r["url"]) for r in rows) + + +def test_the_url_is_the_role_page_on_the_site_not_the_apply_system() -> None: + """`applyUrl` points at Workday; the role's page is `/job//`.""" + assert _answer()["refineSearch"]["data"]["jobs"][0]["applyUrl"].startswith("https://xboxgaming.") + assert _rows()[0]["url"] == ("https://careers.king.com/us/en/job/ACMKDSUSR028168EXTERNALENUS" + "/Principal-Economy-Designer-New-Games") + assert _rows()[1]["url"].endswith("/Senior-Data-Visualisation-Engineer-12mth-FTC") + + +def test_the_locations_are_every_place_the_role_names() -> None: + rows = _rows() + assert rows[0]["location"] == ("Barcelona, Spain; London, London, United Kingdom; " + "Stockholm, Stockholm County, Sweden") + assert rows[1]["location"] == "Stockholm, Stockholm County, Sweden" + + +def test_a_role_with_one_place_only_uses_location() -> None: + data = _answer() + job = data["refineSearch"]["data"]["jobs"][0] + job["multi_location"], job["isMultiLocation"] = [], False + assert phenom.parse(json.dumps(data).encode(), SLUG)[0]["location"] == "Barcelona, Spain" + + +def test_a_title_with_nothing_to_make_a_slug_of_has_a_page_by_id_alone() -> None: + data = _answer() + data["refineSearch"]["data"]["jobs"][0]["title"] = "?!" + assert phenom.parse(json.dumps(data).encode(), SLUG)[0]["url"] == \ + "https://careers.king.com/us/en/job/ACMKDSUSR028168EXTERNALENUS" + + +def test_a_role_without_title_or_id_is_left_out() -> None: + data = _answer() + jobs = data["refineSearch"]["data"]["jobs"] + jobs[0]["title"] = "" + for key in ("jobSeqNo", "jobId", "reqId"): + jobs[1].pop(key, None) + assert [r["source_id"] for r in phenom.parse(json.dumps(data).encode(), SLUG)] == IDS[2:] + + +# ---------------------------------------------------------- the request + +def test_the_body_names_the_locale_and_the_page_and_nothing_secret() -> None: + body = phenom._body("www.careers.philips.com/global/en", 200) + assert (body["lang"], body["country"], body["from"], body["size"]) == \ + ("en_global", "global", 200, 100) + assert body["ddoKey"] == "refineSearch" and body["jobs"] is True + assert phenom._body(SLUG, 0)["lang"] == "en_us" + assert not {"refNum", "pageId", "token", "key"} & set(body) + + +# ----------------------------------------------------------------- paging + +@pytest.fixture +def no_delay(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setattr(ats, "PAGE_DELAY", 0) + + +def _fake(monkeypatch: pytest.MonkeyPatch, total: int | None = None + ) -> list[tuple[str, str, dict[str, Any] | None]]: + """`ats._get` answering the search from the saved roles, `from` and `size` + honoured, and a page past the end empty.""" + asked: list[tuple[str, str, dict[str, Any] | None]] = [] + every = _answer()["refineSearch"]["data"]["jobs"] + + def fake_get(client, url, host, slug, *, method="GET", payload=None, headers=None, + www_twin=False): + asked.append((url, method, payload)) + assert payload is not None + data = _answer() + jobs = every[payload["from"]:payload["from"] + payload["size"]] + data["refineSearch"]["data"]["jobs"] = jobs + data["refineSearch"]["hits"] = len(jobs) + data["refineSearch"]["totalHits"] = len(every) if total is None else total + return json.dumps(data).encode() + + monkeypatch.setattr(ats, "_get", fake_get) + return asked + + +def test_the_listing_is_posted_page_by_page_to_the_stated_total( + monkeypatch: pytest.MonkeyPatch, no_delay: None) -> None: + asked = _fake(monkeypatch) + monkeypatch.setattr(phenom, "PAGE_SIZE", 2) + rows, complete = ats._fetch_rows(object(), f"phenom:{SLUG}") # type: ignore[arg-type] + assert [(url, method, (payload or {})["from"], (payload or {})["size"]) for url, method, payload in asked] == [ + ("https://careers.king.com/widgets", "POST", offset, 2) for offset in (0, 2, 4)] + assert [r["source_id"] for r in rows] == IDS + assert complete + + +def test_a_board_that_ends_short_of_its_total_is_incomplete( + monkeypatch: pytest.MonkeyPatch, no_delay: None) -> None: + _fake(monkeypatch, total=7) + monkeypatch.setattr(phenom, "PAGE_SIZE", 2) + rows, complete = ats._fetch_rows(object(), f"phenom:{SLUG}") # type: ignore[arg-type] + assert (len(rows), complete) == (5, False) + + +def test_a_small_board_is_one_page(monkeypatch: pytest.MonkeyPatch, no_delay: None) -> None: + asked = _fake(monkeypatch) + rows, complete = ats._fetch_rows(object(), f"phenom:{SLUG}") # type: ignore[arg-type] + assert len(asked) == 1 + assert (len(rows), complete) == (5, True) + + +def test_an_empty_board_is_complete(monkeypatch: pytest.MonkeyPatch, no_delay: None) -> None: + empty = {"refineSearch": {"status": 200, "hits": 0, "totalHits": 0, "data": {"jobs": []}}} + monkeypatch.setattr(ats, "_get", lambda *a, **k: json.dumps(empty).encode()) + assert ats._fetch_rows(object(), f"phenom:{SLUG}") == ([], True) # type: ignore[arg-type] + + +def test_an_answer_that_is_not_a_search_fails_the_board( + monkeypatch: pytest.MonkeyPatch, no_delay: None) -> None: + monkeypatch.setattr(ats, "_get", lambda *a, **k: b'{"error": "no such page"}') + with pytest.raises(ValueError, match="refineSearch"): + ats._fetch_rows(object(), f"phenom:{SLUG}") # type: ignore[arg-type] + + +# ----------------------------------------------------------------- detail + +def _get_of(name: str, asked: list[tuple[str, dict[str, str] | None]]) -> Any: + body = (FIXTURES / name).read_bytes() + + def get(url: str, *, method: str = "GET", payload: Any = None, headers: Any = None) -> bytes: + asked.append((url, headers)) + return body + return get + + +def test_detail_reads_the_description_from_the_json_ld() -> None: + asked: list[tuple[str, dict[str, str] | None]] = [] + row = _rows()[0] + got = phenom.detail(_get_of("phenom-detail.html", asked), SLUG, row) + assert asked == [(row["url"], {"Accept": "text/html"})] + assert got["description"].startswith("Craft: Data, Analytics & Strategy") + assert "<" not in got["description"] and "<" not in got["description"] + assert "&" not in got["description"] + assert got["posted"].isoformat() == "2026-09-28T00:00:00+00:00" + assert set(got) <= set(ats.DETAIL_FIELDS) + + +def test_detail_finds_the_job_posting_among_other_blocks_and_takes_its_date() -> None: + got = phenom.detail(_get_of("phenom-detail-2.html", []), "www.careers.philips.com/global/en", + {"url": "https://www.careers.philips.com/global/en/job/1/x"}) + assert got["description"].startswith("Job Title Zone Business Leader Imaging Nordics") + assert got["posted"].isoformat() == "2026-09-08T00:00:00+00:00" + + +def test_detail_falls_back_to_the_page_state_where_there_is_no_job_posting() -> None: + """King's pages of roles posted that day had no `JobPosting` block, only a + `WebPage` one, and the role in the state the page assigns to `phApp.ddo`.""" + row = _rows()[0] + got = phenom.detail(_get_of("phenom-detail-3.html", []), SLUG, row) + assert got["description"].startswith("Craft: Games Design & Production Job Description:") + assert "<" not in got["description"] and "&" not in got["description"] + assert got["remote"] == "onsite" + assert "posted" not in got and set(got) <= set(ats.DETAIL_FIELDS) + + +def test_detail_of_a_page_with_no_description_fails_so_that_it_is_asked_again() -> None: + def get(url: str, **kwargs: Any) -> bytes: + return (b'<html><script type="application/ld+json">{"@type": "BreadcrumbList"}</script>' + b'<script type="application/ld+json">{broken</script>' + b'<script>phApp.ddo = {"jobDetail": {"data": {"job": {"title": "x"}}}};</script></html>') + with pytest.raises(ValueError, match="no description"): + phenom.detail(get, SLUG, {"url": "https://careers.king.com/us/en/job/1"}) + + +@pytest.mark.parametrize("state", ["", "phApp.ddo = {broken", 'phApp.ddo = {"jobDetail": []};', + 'phApp.ddo = {"siteConfig": {}};']) +def test_a_page_state_that_is_not_a_role_is_no_description(state: str) -> None: + def get(url: str, **kwargs: Any) -> bytes: + return f"<html><script>{state}</script></html>".encode() + with pytest.raises(ValueError, match="no description"): + phenom.detail(get, SLUG, {"url": "https://careers.king.com/us/en/job/1"}) + + +# ----------------------------------------------------------- slug and URLs + +@pytest.mark.parametrize("slug", [ + "careers.king.com/us/en", "www.careers.philips.com/global/en", + "careers.justeattakeaway.com/global/en", "jobs.example.co.uk/na/en", "a-b.example.de/de/de", +]) +def test_a_host_and_a_locale_root_are_a_slug(slug: str) -> None: + assert phenom.slug_ok(slug) and ats.is_known_target(f"phenom:{slug}") + + +@pytest.mark.parametrize("slug", [ + "", "careers.king.com", "careers.king.com/", "careers.king.com/us", "careers.king.com/us/", + "careers.king.com/us/en/", "careers.king.com/us/en/x", "careers.king.com//en", + "careers.king.com/us/en\n", "careers.king.com/us/en ", " careers.king.com/us/en", + "careers.king.com /us/en", "careers.king.com\n/us/en", "careers.king.com/us/en\r\n", + "careers.king.com@evil.com/us/en", "evil.com@careers.king.com/us/en", + "careers.king.com#x/us/en", "careers.king.com?x=1/us/en", "careers.king.com/us/en?x=1", + "careers.king.com/us/en#x", "careers.king.com/us/%2fen", "careers.king.com/../en", + "careers.king.com/us/..", "careers.king.com:8443/us/en", "careers.king.com:443/us/en", + "localhost/us/en", "127.0.0.1/us/en", "[::1]/us/en", "2130706433/us/en", "10.0.0.1/us/en", + "king/us/en", "careers.king.com./us/en", ".king.com/us/en", "careers..king.com/us/en", + "CAREERS.KING.COM/us/en", "careers.king.com/US/en", "careers.king.com/us/EN", + "careers.king.com\\us/en", "careers.king.com/u/en", "careers.king.com/us/eng", +]) +def test_a_hostile_slug_is_refused(slug: str) -> None: + assert not phenom.slug_ok(slug) + assert not ats.is_known_target(f"phenom:{slug}") + + +def test_only_the_site_named_by_the_slug_is_allowed() -> None: + allow = phenom.allowed(SLUG) + assert allow("careers.king.com") and allow("CAREERS.KING.COM") + assert not allow("king.com") and not allow("careers.king.com.evil.com") + assert not allow("xboxgaming.wd1.myworkdayjobs.com") and not allow("127.0.0.1") + assert ats._allowed_host("phenom", SLUG)("careers.king.com") + + +def test_the_careers_page_is_the_search_page_and_robots_reads_it() -> None: + url = "https://careers.king.com/us/en/search-results" + assert phenom.careers_url(SLUG) == ats.careers_url(f"phenom:{SLUG}") == url + assert phenom.robots_page(SLUG) == url + assert phenom.allowed(SLUG)(httpx.URL(phenom.robots_page(SLUG)).host) + assert phenom.careers_url("www.careers.philips.com/global/en") == \ + "https://www.careers.philips.com/global/en/search-results" + + +# -------------------------------------------------------------- discovery + +def test_discovery_finds_the_site_and_the_locale_in_a_link_to_its_search_page() -> None: + page = ('<a href="https://careers.king.com/us/en/search-results">Jobs</a>' + '<a href="https://www.careers.philips.com/global/en/search-results?q=1">More</a>') + assert [(h, s) for h, s, _ in boards_in(page)] == [ + ("phenom", "careers.king.com/us/en"), ("phenom", "www.careers.philips.com/global/en")] + + +def test_discovery_lowercases_what_a_page_writes_in_capitals() -> None: + page = "https://Careers.King.com/US/EN/search-results" + assert [(h, s) for h, s, _ in boards_in(page)] == [("phenom", "careers.king.com/us/en")] + + +def test_discovery_names_a_site_that_loads_phenoms_assets_without_a_locale_root() -> None: + page = '<script src="https://cdn.phenompeople.com/CareerConnectResources/x.js"></script>' + assert [(h, s) for h, s, _ in boards_in(page)] == [("phenom", "")] + + +def test_a_page_that_only_looks_like_one_names_nothing() -> None: + """The search page is the one URL that carries host and locale root, so a + link to any other page of a site is not enough.""" + assert boards_in("https://careers.king.com/us/en/job/R028130/Product-Analyst") == [] + assert boards_in("https://careers.king.com/search-results") == [] + assert boards_in("https://127.0.0.1/us/en/search-results") == [] + + +def test_every_slug_discovery_finds_is_a_slug() -> None: + for page in ("https://careers.king.com/us/en/search-results", + "https://careers.justeattakeaway.com/global/en/search-results#x"): + found = boards_in(page) + assert found and all(phenom.slug_ok(slug) for _h, slug, _ in found), page