"""Unit tests for the job-profile helpers in job/job_post/plugins.py — pure functions only.""" from __future__ import annotations from job.job_post import plugins # ---------------------------------------------------------------- suggested_source def test_inbox_score_is_email_sourced_even_with_a_candidates_row(): assert plugins.suggested_source(42, None, "upload") == "inbox" def test_form_score_is_form_sourced(): assert plugins.suggested_source(None, "f-1", None) == "form" def test_upload_score_uses_the_candidates_row_source(): assert plugins.suggested_source(None, None, "bank") == "bank" assert plugins.suggested_source(None, None, None) == "upload" assert plugins.suggested_source(None, None, " ") == "upload" # ---------------------------------------------------------------- optional_skill_hits def test_exact_match_ignores_case_and_punctuation(): assert plugins.optional_skill_hits(["FMCG Background", "Arabic"], ["fmcg-background"]) == ["FMCG Background"] def test_keyword_inside_skill_counts_on_word_boundaries(): assert plugins.optional_skill_hits(["CRM (Salesforce)"], ["Salesforce"]) == ["CRM (Salesforce)"] def test_skill_inside_keyword_counts(): assert plugins.optional_skill_hits(["Arabic"], ["Arabic language"]) == ["Arabic"] def test_partial_words_do_not_count(): assert plugins.optional_skill_hits(["Java"], ["JavaScript"]) == [] def test_hits_keep_job_order_and_skip_duplicates(): hits = plugins.optional_skill_hits(["Travel", "Arabic", "Arabic"], ["arabic", "travel"]) assert hits == ["Travel", "Arabic"] def test_no_optional_skills_or_keywords_is_empty(): assert plugins.optional_skill_hits([], ["Python"]) == [] assert plugins.optional_skill_hits(["Python"], None) == [] # ---------------------------------------------------------------- suggested_summary def test_summary_counts_bands_and_top_match(): candidates = [ {"band": "Strong Match", "match_score": 91}, {"band": "Strong Match", "match_score": 85}, {"band": "Potential Match", "match_score": 70}, {"band": "Weak Match", "match_score": 40}, {"band": None, "match_score": None}, ] summary = plugins.suggested_summary(candidates) assert summary["suggested"] == 5 assert summary["top_match"] == 2 assert summary["top_score"] == 91 assert summary["bands"] == {"Strong Match": 2, "Potential Match": 1, "Weak Match": 1} def test_empty_summary(): assert plugins.suggested_summary([]) == { "suggested": 0, "top_match": 0, "top_score": None, "bands": {"Strong Match": 0, "Potential Match": 0, "Weak Match": 0}, }