Skip to content

Add unit tests for v0.40.0 surface (lnk_mapping_code, persist additions, pipeline_run mapping_code phase, deprecation shims) #191

Description

@NewGraphEnvironment

Context

v0.40.0 (#187) landed substantial new R code without dedicated unit tests. Compile-time checks + /code-check rounds caught real bugs during implementation (Phase 2's conditional-col dropouts, Phase 4's missing roxygen, Phase 6's body-ref renames after signature rename), and the existing 1119-test suite continued to pass — but no new test files / test_that blocks were added for the new surface.

Coverage gaps

Surface Current state Gap
R/lnk_mapping_code.R (new exported function) no test file tests/testthat/test-lnk_mapping_code.R missing entirely
R/lnk_persist_init.R — new cols_streams_access_base / cols_streams_mapping_code_base + per-species helpers + CREATE TABLE / VIEW blocks existing 10 tests cover the pre-#187 schema no test asserts the new tables/view exist post-init, no test asserts per-species column naming
R/lnk_pipeline_persist.R — new streams_access + streams_mapping_code write blocks (gated on working-table presence) existing 6 tests cover pre-#187 writes no test asserts the gated-write logic (skip when working table absent; fire + JOIN-back when present)
R/lnk_pipeline_run.R — new mapping_code = FALSE param + conditional phase existing 8 tests cover pre-#187 flow no test asserts the new phase fires + writes expected tables when mapping_code = TRUE
R/lnk_pipeline_mapping_code.Rspecies_<role> param rename + deprecation shims existing tests use old param names no test asserts the deprecation shim warns + remaps correctly

Goals

Add the missing tests with mocks (same with_mocked_bindings pattern as test-lnk_compare_wsg.R) so:

  • tests/testthat/test-lnk_mapping_code.R — covers query construction (table_* args), habitat long→wide pivot, presence derivation logic, species_<role> pass-through to lnk_pipeline_mapping_code, error paths (empty access, empty habitat).
  • test-lnk_persist_init.R extended — assert <schema>.streams_access, <schema>.streams_mapping_code, and <schema>.streams_habitat_long_vw exist after init with the species-driven column set. Assert per-species column naming convention.
  • test-lnk_pipeline_persist.R extended — assert new write blocks skip cleanly when working tables absent (gating); assert they fire with correct JOIN projection when present.
  • test-lnk_pipeline_run.R extended — assert mapping_code = TRUE triggers the new phase (mock lnk_barriers_views + lnk_pipeline_access + lnk_mapping_code and verify call ordering); assert mapping_code = FALSE (default) does not.
  • test-lnk_pipeline_mapping_code.R extended — assert deprecation shims for resident_species / anadromous_species / spawn_only_species emit .Deprecated() warning and remap to species_<role>.

Acceptance

  • devtools::test() count increases by 15–25 test_that blocks across the five files (rough estimate based on the surface size).
  • All new tests use mocks; none require a live DB.
  • Deprecation-shim tests verify both warn-on-use and functional-remap.
  • 0 FAIL throughout.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions