import pathlib


def jcasc_job_block(job: str) -> str:
    casc = pathlib.Path("services/jenkins/configmap-jcasc.yaml").read_text()
    return casc.split(f"pipelineJob('{job}')", 1)[1].split("pipelineJob(", 1)[0]


def test_in_scope_jenkins_jobs_have_twice_daily_refresh_trigger():
    in_scope_jobs = [
        "ananke",
        "ariadne",
        "atlasbot",
        "bstein-dev-home",
        "data-prepper",
        "metis",
        "pegasus",
        "soteria",
        "titan-iac",
    ]

    for job in in_scope_jobs:
        block = jcasc_job_block(job)
        assert "cron" in block
        assert "spec('H H/12 * * *')" in block


def test_lesavka_jenkins_job_has_daily_refresh_trigger():
    lesavka_block = jcasc_job_block("lesavka")

    assert "scmpoll_spec('H/5 * * * *')" in lesavka_block
    assert "cron" in lesavka_block
    assert "spec('H H * * *')" in lesavka_block


def test_typhon_jenkins_job_has_daily_refresh_trigger():
    typhon_block = jcasc_job_block("typhon")

    assert "scmpoll_spec('H/5 * * * *')" in typhon_block
    assert "cron" in typhon_block
    assert "spec('H H * * *')" in typhon_block


def test_cassandra_jenkins_job_has_scm_poll_trigger():
    cassandra_block = jcasc_job_block("cassandra")

    assert "scmpoll_spec('H/5 * * * *')" in cassandra_block
