Skip to content

Add unit tests for template-sync #34

@mindsocket

Description

@mindsocket

Overview

template-sync currently has no unit tests. The key functions to test are:

  • generateNewContent — core output generation
  • getTypeVariants — schema parsing into variant map
  • mergeAllOfProperties / withEnumPlaceholders / commentedHint — helpers (test via generateNewContent where possible)

Test cases

generateNewContent

  • Produces correct frontmatter structure (header comment, required fields, optional commented hints) for a known variant (e.g. opportunity from general.json)
  • fieldMap remapping: canonical keys in the schema (status) are remapped to file keys (record_status) in the output YAML, and property descriptions still attach to the correct line
  • Inverse fieldMap: a round-trip check that invertFieldMap followed by generateNewContent produces file-field keys, not canonical keys
  • Enum fields are expanded to val1|val2|... placeholder format
  • Integer fields with min/max use midpoint as placeholder
  • Optional fields not in the example appear as # field: ... comment hints
  • Body is preserved verbatim after the closing ---

getTypeVariants

  • Returns expected set of type names from general.json
  • Skips dashboard and ost_on_a_page variants
  • Skips variants with no examples[0]

Notes

  • Use general.json (from schemas/) as the schema source — no need for additional fixtures
  • Plain objects are fine for mock variants where full schema resolution isn't needed
  • Do not mock filesystem — test the functions directly with imported schema data
  • Avoid testing templateSync (the async orchestrator) as it couples to the filesystem and console output; the unit-testable logic is in the helpers

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions