Skip to content

Phase 5, Task 2b: parseDatastream() Fixtures + Tests #80

Closed

Description

@Sam-Bolling

Task

Create part2.spec.ts with 8 test cases and fixtures for parseDatastream(), validating all 13 field transformations including 3 time fields, observedProperties normalization, and cross-reference exclusion.

ROADMAP Reference: Phase 5, Task 2b — parseDatastream() Fixtures + Tests (~1–1.5 hours, Medium complexity)


Files to Create or Modify

File Action Est. Lines Purpose
src/ogc-api/csapi/formats/part2.spec.ts Create ~150–200 Unit tests for parseDatastream() — 8 test cases with real-server-derived fixtures

Note: This file will later be extended by Tasks 3, 4, 5b, and 6 to add tests for parseObservation(), parseControlStream(), parseCommand(), and parseCommandStatus(). Structure the file with a top-level describe('parseDatastream', ...) block that accommodates future sibling describe blocks.

Blueprint Reference

Follow the test structure established by existing SensorML parser tests:

  • src/ogc-api/csapi/formats/sensorml/aggregate-process.spec.ts — describe / it structure, fixture-based, pure function testing
  • src/ogc-api/csapi/formats/sensorml/physical-system.spec.ts — test pattern density and assertion style

Key patterns:

  • Top-level describe('parseDatastream', ...) with nested describe groups for logical categories
  • Each it(...) tests a single focused scenario
  • Inline JSON fixtures (not external fixture files) — consistent with existing SensorML test patterns
  • Direct assertion on output fields — verify values, not just that code runs without throwing
  • No mocking needed — parseDatastream() is a pure transformation function

Scope — What to Implement

Fixture Design

Build Datastream fixtures from real OSH response data (Smoke Test #7). The input shape matches what OSH actually returns:

{
  "id": "0ocb",
  "name": "FCU Simulated Weather Station - Weather",
  "system@id": "0o0o",
  "system@link": {
    "href": "http://45.55.99.236:8080/sensorhub/api/systems/0o0o?f=json",
    "uid": "urn:osh:sensor:simweather:001",
    "type": "application/geo+json"
  },
  "outputName": "weather",
  "validTime": ["2026-01-26T18:32:01.56Z", "now"],
  "observedProperties": [
    { "definition": "http://mmisw.org/ont/cf/parameter/air_temperature", "label": "Air Temperature" }
  ],
  "formats": [
    "application/om+json",
    "application/swe+json",
    "application/swe+csv",
    "application/swe+xml",
    "application/swe+binary"
  ],
  "phenomenonTime": ["2026-01-26T18:32:01.56Z", "2026-02-19T14:22:03.12Z"],
  "resultTime": ["2026-01-26T18:32:01.56Z", "2026-02-19T14:22:03.12Z"],
  "resultType": "record",
  "live": true,
  "links": [
    { "rel": "self", "href": "/datastreams/0ocb", "type": "application/json" }
  ]
}

Document fixture source in test file comments (e.g., // Fixture derived from OSH Smoke Test #7 response).

8 Test Cases

# Test Name Input Expected Output Focus
1 Full Datastream All 13 fields present (real OSH shape, including system@id, system@link) All fields correctly transformed; system@id/system@link absent from output End-to-end field extraction
2 Minimal Datastream Only id, name, formats (required per interface: id: string, name: string, formats: string[]) id, name, formats populated; observedProperties → [], phenomenonTime → null, resultTime → null, resultType → null, live → null, optional fields absent Default/fallback values
3 All 3 time fields parsed validTime: ["2026-01-26T18:32:01.56Z", "now"], phenomenonTime: ["2026-01-26T18:32:01.56Z", "2026-02-19T14:22:03.12Z"], resultTime: ["2026-01-26T18:32:01.56Z", "2026-02-19T14:22:03.12Z"] validTime: { start: Date, end: undefined } (now sentinel); phenomenonTime: { start: Date, end: Date }; resultTime: { start: Date, end: Date } parseValidTime() integration, "now" sentinel handling
4 observedProperties as objects observedProperties: [{ "definition": "http://…/air_temperature", "label": "Air Temperature" }, { "definition": "http://…/humidity", "label": "Humidity" }] observedProperties: ["http://…/air_temperature", "http://…/humidity"] definition URI extraction from object form
5 observedProperties as strings observedProperties: ["http://…/air_temperature", "http://…/humidity"] observedProperties: ["http://…/air_temperature", "http://…/humidity"] Direct string pass-through
6 phenomenonTime null phenomenonTime: null (readOnly field, null when no observations exist) phenomenonTime: null (NOT undefined) Nullable vs optional distinction
7 Missing optional fields No description, outputName, type, validTime description → absent/undefined, outputName → absent/undefined, type → absent/undefined, validTime → absent/undefined Optional field handling
8 Non-object input null, 42, "string" Throws Error Input guard

Assertion Patterns

For each test case, assert on specific field values, not just structural checks:

// Good — verifies the actual transformation
expect(result.observedProperties).toEqual(['http://…/air_temperature']);
expect(result.phenomenonTime).toEqual({ start: expect.any(Date), end: expect.any(Date) });
expect(result.phenomenonTime?.start.toISOString()).toBe('2026-01-26T18:32:01.560Z');

// Good — verifies cross-reference exclusion
expect(result).not.toHaveProperty('system@id');
expect(result).not.toHaveProperty('system@link');

// Good — verifies null vs undefined distinction
expect(result.phenomenonTime).toBeNull(); // null, not undefined

// Bad — doesn't verify transformation correctness
expect(result).toBeDefined();

TimeInterval Verification

When verifying parseValidTime() output, check both the Date values and the "now" sentinel behavior:

// validTime with "now" sentinel
expect(result.validTime?.start).toEqual(new Date('2026-01-26T18:32:01.56Z'));
expect(result.validTime?.end).toBeUndefined(); // "now" → undefined

// phenomenonTime with concrete dates
expect(result.phenomenonTime?.start).toEqual(new Date('2026-01-26T18:32:01.56Z'));
expect(result.phenomenonTime?.end).toEqual(new Date('2026-02-19T14:22:03.12Z'));

Scope — What NOT to Touch

  • ❌ Do NOT modify src/ogc-api/csapi/formats/part2.ts — the implementation is Task 2a's scope
  • ❌ Do NOT modify src/ogc-api/csapi/model.ts — the Datastream interface already exists
  • ❌ Do NOT modify src/ogc-api/csapi/formats/geojson.ts — parseValidTime() is already implemented
  • ❌ Do NOT add tests for parseObservation() — that is Task 3's scope
  • ❌ Do NOT add tests for other Part 2 parsers — those are Tasks 4, 5b, 6
  • ❌ Do NOT create schema-response.spec.ts — that belongs to Task 7
  • ❌ Do NOT modify any SensorML files or tests
  • ❌ Do NOT modify QueryBuilder call sites or response.ts
  • ❌ Do NOT modify property.spec.ts (Task 1)
  • ❌ Do NOT refactor existing code unless required to complete this task

Acceptance Criteria

  • src/ogc-api/csapi/formats/part2.spec.ts exists with a describe('parseDatastream', ...) block
  • 8 test cases implemented matching the table above
  • Fixtures derived from real OSH response data (ST#7) with source documented in comments
  • All 3 time fields verified: validTime (with "now" sentinel), phenomenonTime, resultTime
  • observedProperties normalization tested: both object form and string form
  • phenomenonTime: null test confirms null output (not undefined)
  • Cross-reference exclusion verified (system@id / system@link not in output)
  • Non-object input throws Error
  • >80% code coverage on parseDatastream() in part2.ts
  • All tests pass (npm test)
  • No lint errors
  • Existing tests still pass (no regressions)

Dependencies

Blocked by: Task 2a (#79 — parseDatastream() must exist before tests can be written)
Blocks: Task 9 (Integration Wiring — needs tested parsers)


Operational Constraints

⚠️ MANDATORY: Before starting work on this issue, review docs/governance/AI_OPERATIONAL_CONSTRAINTS.md.

For Phase 5 issues: Review the P5 Implementation Guide §4.2 Test Cases table and §9 Testing Strategy for fixture sources, test patterns, and coverage targets. Review Phase 5 parser constraints below.

Key constraints for this task:

  • Precedence: OGC specifications → AI Collaboration Agreement → This issue description → Existing code → Conversational context
  • No scope expansion: Do not infer unstated requirements or add unrequested features
  • No refactoring: Do not rename, restructure, or "improve" code outside this issue's scope
  • Minimal diffs: Prefer the smallest change that satisfies the acceptance criteria
  • Ask when unclear: If intent is ambiguous, stop and ask for clarification

Phase 5 Parser Constraints

  • Parser tests verify client extraction, not server compliance. The input is whatever the server sends; the test verifies we extract it correctly.
  • Fixture-based: Each test uses a JSON fixture representing a real or spec-derived response. Datastream has real server data (OSH, ST#7).
  • No mocking: parseDatastream() is a pure transformation — no network, no state, no mocking needed.
  • Meaningful assertions: Verify field values, not just that code runs without throwing. Assert on specific transformed values.
  • Null vs undefined distinction: phenomenonTime: null and resultTime: null are semantically different from validTime: undefined. Tests must verify this distinction.
  • Cross-reference exclusion: system@id and system@link appear in raw JSON but must NOT appear in the output. Test this explicitly.
  • File structure for growth: part2.spec.ts will be extended by Tasks 3, 4, 5b, 6. Use a top-level describe('parseDatastream', ...) block that sits alongside future sibling describe blocks.

References

Primary References (must read)

# Document Section/Lines What It Provides
1 P5 Implementation Guide §4.2 Test Cases (L315–328) 8 test cases with focus descriptions
2 P5 Implementation Guide §9 Testing Strategy (L888–940) Fixture sources, test patterns, coverage targets, file organization
3 P5 Implementation Guide §4.2 Input Shape + Field Transformations (L248–310) Full input example and 13-field transformation table for assertion design
4 P5 ROADMAP Task 2b (L128–148) Task definition, 8 test case list, deliverables
5 Parsing Coverage Audit Gap #2 (L187) Source of truth for the gap being tested

Blueprint References (pattern to follow)

# Document What It Provides
1 src/ogc-api/csapi/formats/sensorml/aggregate-process.spec.ts Test structure pattern: describe / it, inline fixtures, assertion style
2 src/ogc-api/csapi/formats/sensorml/physical-system.spec.ts Test density and coverage pattern for parser tests
3 src/ogc-api/csapi/formats/property.spec.ts (Task 1) Sibling test file for parseProperty() — same testing approach for a Phase 5 parser

Upstream Type/Import References

# Document What to Import
1 src/ogc-api/csapi/formats/part2.ts (Task 2a) parseDatastream function under test

Specification References (for fixture accuracy)

# Document Use
1 OGC API - Connected Systems Part 2 (23-002) Datastream resource definition, dataStream schema — for verifying fixture field accuracy

Research References (context)

# Document What It Provides
1 validTime coverage analysis Confirms Datastream has validTime per Part 2; "now" sentinel handling
2 P5 Implementation Guide §11 Risk Register Risk #3: observedProperties shape variance — both forms must be tested

Smoke Test References (fixture sources)

Finding Relevance
ST#7 (Datastream responses) Primary fixture source — real OSH Datastream response data with all fields populated
F85 validTime absent from OSH Deployments — validates tolerant extraction for absent validTime scenarios
F45 Response envelope varies by server — confirms parsers only need item-level logic (envelope handled by parseCollectionResponse())

Convention Quick Reference

Rule Example
Use .js extension for relative imports import { parseDatastream } from './part2.js'
describe / it test structure Match existing SensorML parser tests
Inline fixtures JSON objects defined in test file, not external fixture files
No mocking for pure parsers parseDatastream() takes JSON, returns typed object
Coverage target >80% on part2.ts (>90% realistic for pure functions)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions