Skip to content

test(serve): strengthen POST /ui contract coverage#242

Merged
fahimfaisaal merged 1 commit into
mainfrom
feat/rest-ui-endpoint
Jul 20, 2026
Merged

test(serve): strengthen POST /ui contract coverage#242
fahimfaisaal merged 1 commit into
mainfrom
feat/rest-ui-endpoint

Conversation

@hfl0506

@hfl0506 hfl0506 commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

Closes #216

Changes

  • Add POST /ui contract coverage for HTML responses and Dataset arrays.
  • Verify exact text/html; charset=utf-8 content type.
  • Confirm typed chart overrides and statistics reach UI generation.
  • Test structured validation and template-generation errors.
  • Reject dataUrl at both request and Dataset levels.
  • Validate OpenAPI remote-input rejection and HTML-only success responses.

Test Result

# start server
task build:ui
task build:cli
./bin/vizb serve

Case 1

curl -sS http://127.0.0.1:8080/ui \
          -H 'Content-Type: application/json' \
          -H 'Accept: text/html' \
          --data '{
        "datasets": {
          "name": "Local UI test",
          "axes": [
            {"key":"x","label":"Region"},
            {"key":"y","label":"Latency","type":"value"}
          ],
          "settings": [{"type":"line","smooth":false}],
          "data": [
            {"xAxis":"west","yAxis":"12"},

            {"xAxis":"east","yAxis":"18"}
          ]
        },
        "charts": {
          "types": ["line"],
          "configs": [{"type":"line","smooth":true,"showLabels":true}]                      }
      }' \
          -o /tmp/vizb-report.html
Screenshot 2026-07-19 at 9 04 48 AM

Case 2

curl -i http://127.0.0.1:8080/ui \
          -H 'Content-Type: application/json' \
          -H 'Accept: text/html' \
          --data '{
        "datasets": {
          "name": "Remote test",
          "axes": [],
          "settings": [],
          "data": []
        },
        "dataUrl": "https://example.com/data.json"
      }'
HTTP/1.1 422 Unprocessable Entity
Content-Type: application/problem+json
Date: Sun, 19 Jul 2026 16:06:07 GMT
Content-Length: 264

{"detail":"Request validation failed.","errors":[{"location":"body","path":"/","code":"invalid_json","message":"json: unknown field \"dataUrl\""}],"instance":"/ui","status":422,"title":"Unprocessable content","type":"https://vizb.goptics.org/problems/validation"}

Case 3

curl -i http://127.0.0.1:8080/ui \
          -H 'Content-Type: application/json' \

          -H 'Accept: application/json' \
          --data '{
        "datasets": {
          "name": "Accept test",
          "axes": [],
          "settings": [],
          "data": []
        }
      }'
\HTTP/1.1 406 Not Acceptable
Content-Type: application/problem+json
Date: Sun, 19 Jul 2026 16:06:46 GMT
Content-Length: 154

{"detail":"Accept must allow text/html","instance":"/ui","status":406,"title":"Not acceptable","type":"https://vizb.goptics.org/problems/not-acceptable"}

Summary by CodeRabbit

  • Tests
    • Expanded coverage for the UI endpoint’s request and response contracts.
    • Verified that unsupported remote data inputs are rejected with structured error responses.
    • Confirmed successful UI responses return HTML with the expected content type.
    • Added validation for supported dataset payload formats and chart configuration behavior.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2fc5449e-ed0e-4108-9111-c1311870d4c1

📥 Commits

Reviewing files that changed from the base of the PR and between 71b9aca and 546e8c5.

📒 Files selected for processing (2)
  • api/openapi_test.go
  • cmd/serve_test.go

📝 Walkthrough

Walkthrough

The changes expand /ui contract and endpoint tests to cover strict request schemas, dataset arrays, HTML and problem response content types, remote dataUrl rejection, chart configuration output, and generation failures.

Changes

UI endpoint contract and behavior validation

Layer / File(s) Summary
Contract and endpoint behavior tests
api/openapi_test.go, cmd/serve_test.go
OpenAPI validation rejects remote dataUrl input and requires a single text/html response. Serve tests cover dataset arrays, exact response media types, structured error statuses, showLabels, and generation failures.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: api

Suggested reviewers: fahimfaisaal

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: strengthening POST /ui contract coverage.
Linked Issues check ✅ Passed The added tests align with #216 by covering HTML responses, strict validation, remote input rejection, and contract/error behavior for POST /ui.
Out of Scope Changes check ✅ Passed The changes stay focused on POST /ui contract tests and OpenAPI coverage, with no clear unrelated scope introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/rest-ui-endpoint

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@hfl0506

hfl0506 commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator Author

I think the main implementation has been merge through #232.
If #232 is considered to have fully resolved the issue, this can be treated as a small test-hardening follow-up rather than the primary implementation. Thanks

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@hfl0506
hfl0506 marked this pull request as ready for review July 19, 2026 16:12
@hfl0506
hfl0506 requested a review from fahimfaisaal as a code owner July 19, 2026 16:12
@fahimfaisaal
fahimfaisaal merged commit 15e9f8e into main Jul 20, 2026
14 checks passed
@fahimfaisaal
fahimfaisaal deleted the feat/rest-ui-endpoint branch July 20, 2026 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

expose UI generation through POST /ui

3 participants