Skip to content

Add unit tests for lib/jsonpath.ts and lib/jsonSchema.ts #97

Description

@anurag629

The JSON formatter's JSONPath query panel and JSON Schema validation panel are powered by two small pure modules that have no tests yet. They're a great first contribution: no UI work, just clear inputs and outputs.

Where to look

  • lib/jsonpath.ts (runJsonPath)
  • lib/jsonSchema.ts (validateSchema and SAMPLE_SCHEMA)
  • lib/json-utils.ts (SAMPLE_JSON, near the end of the file)
  • app/(tools)/json-formatter/components/ConversionPanel.tsx (how the UI uses them)
  • lib/__tests__/json-utils.test.ts (for the existing test style)

Acceptance criteria

  • New lib/__tests__/jsonpath.test.ts:
    • empty JSON returns "Paste JSON first"
    • an empty expression returns "Enter a JSONPath expression"
    • invalid JSON returns ok: false with an "Invalid JSON" message
    • $..email on SAMPLE_JSON returns 2 matches (the user's email string and preferences.notifications.email, which is true) with matching paths
    • $.user.projects[?(@.active==true)] returns only the active project
    • an expression with no matches returns ok: true and an empty list
  • New lib/__tests__/jsonSchema.test.ts:
    • empty inputs return the right parseError
    • invalid data JSON and invalid schema JSON are reported separately
    • SAMPLE_SCHEMA validates SAMPLE_JSON with no errors
    • a missing required property and a value breaking minimum or minLength fail, with instanceLocation and keyword filled in
  • Tests use relative imports (../jsonpath) and pass with npm run test

Want to work on this? Comment below and I'll assign it to you. Please take one issue at a time, branch off develop, and open your PR against develop with Closes #97 in the description.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

good first issueGood for newcomershacktoberfestGood pick for Hacktoberfest contributorstestingTests and test coverage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions