Skip to content

Comments

feat: complete mock API layer implementation#432

Open
revaarathore11 wants to merge 1 commit intoelixir-cloud-aai:mainfrom
revaarathore11:feat/mock-api-layer
Open

feat: complete mock API layer implementation#432
revaarathore11 wants to merge 1 commit intoelixir-cloud-aai:mainfrom
revaarathore11:feat/mock-api-layer

Conversation

@revaarathore11
Copy link

@revaarathore11 revaarathore11 commented Feb 20, 2026

fixes #419

Description

This PR completes the implementation of the mock API layer for cloud components.

Summary of changes

  • Implemented mock API responses to replace remaining direct fetch calls in components
  • Centralized mock data handling for consistency across components
  • Ensured mocks are correctly resolved and usable in local/dev environments
  • Updated .gitignore to prevent mock artifacts/symlinks from being tracked
  • Fixed minor linting issues encountered during integration

This improves development reliability, testability, and decouples components from live backend dependencies.

Fixes #(issue) (if applicable)

Checklist

  • My code follows the contributing guidelines of this project.
  • I am aware that all my commits will be squashed into a single commit.
  • I have performed a self-review of my own code.
  • I have commented my code in hard-to-understand areas.
  • I have updated user-facing documentation where required.
  • My changes generate no new warnings.
  • I have added tests for this change (not required for mock-only integration).
  • I have not reduced the existing code coverage.

Comments

This PR focuses on mock infrastructure and development-time behavior.
No production logic is affected.

Summary by Sourcery

Introduce a centralized fetcher utility to support environment-controlled mock API responses and wire it through all GA4GH/ELIXIR client providers and components.

New Features:

  • Add a shared fetcher helper that can transparently switch between live APIs and JSON-based mocks based on environment configuration.
  • Document how to enable and configure the mock API layer for development and documentation sites.

Enhancements:

  • Refactor GA4GH TRS, WES, TES, DRS, and service registry clients, plus ELIXIR TRS/DRS/Cloud Registry providers and UI components, to use the centralized fetcher instead of direct fetch calls.
  • Export the new API client utility from the shared design package for reuse across consumers.
  • Tidy various templates and TypeScript constructors for consistency and minor lint compliance.

Build:

  • Add Node scripts to generate local mock JSON payloads for TRS and DRS services.

Documentation:

  • Add documentation page explaining the mock API mechanism, environment flags, and mock file layout.

Chores:

  • Check in structured mock JSON files for multiple GA4GH and ELIXIR service endpoints to support offline and deterministic development.

@vercel
Copy link

vercel bot commented Feb 20, 2026

@revaarathore11 is attempting to deploy a commit to the elixir-cloud-aai Team on Vercel.

A member of the Team first needs to authorize it.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 20, 2026

Reviewer's Guide

Introduces a centralized mock-aware fetcher utility and refactors all remaining direct fetch usages in GA4GH/ELIXIR client providers and components to use it, wiring them to a structured mocks/ directory and documenting how to enable the mock API layer.

Sequence diagram for API call with mock interception and fallback

sequenceDiagram
  actor Dev as Developer
  participant UI as WebComponent
  participant Provider as RestProvider
  participant Fetcher as fetcher
  participant Mocks as MockFiles
  participant API as LiveService

  Dev->>UI: Load docs/app with VITE_USE_MOCK_API=true
  UI->>Provider: getTool(id)
  Provider->>Fetcher: fetcher(url, options, mockPath)
  Fetcher->>Fetcher: Check env vars for mock flag
  alt Mock enabled
    Fetcher->>Mocks: fetch(/mocks/mockPath.json)
    alt Mock file found (200 OK)
      Mocks-->>Fetcher: Mock JSON response
      Fetcher-->>Provider: Response (mock)
      Provider-->>UI: Parsed data from mock
    else Mock missing or error
      Mocks-->>Fetcher: Error or non-OK
      Fetcher->>Fetcher: Log warning, fall back
      Fetcher->>API: fetch(url, options)
      API-->>Fetcher: Live HTTP response
      Fetcher-->>Provider: Response (live)
      Provider-->>UI: Parsed data from live API
    end
  else Mock disabled
    Fetcher->>API: fetch(url, options)
    API-->>Fetcher: Live HTTP response
    Fetcher-->>Provider: Response (live)
    Provider-->>UI: Parsed data from live API
  end
Loading

File-Level Changes

Change Details Files
Introduce centralized mock-aware fetcher utility and export it from design package.
  • Add utils/apiClient.ts with a fetcher wrapper that checks env flags to decide between live API and /mocks/*.json responses, with graceful fallback to real fetch on missing mocks or errors.
  • Export fetcher from the ecc-utils-design entrypoint so all client packages can import a single HTTP abstraction.
packages/ecc-utils-design/src/utils/apiClient.ts
packages/ecc-utils-design/src/index.ts
Refactor GA4GH/ELIXIR client providers and components to use fetcher instead of direct fetch and wire each call to a mock path.
  • Replace direct fetch calls with fetcher() in TRS, TRS-Filer, DRS, DRS-Filer, WES, TES, Cloud Registry, and Service Registry providers, passing stable mockPath strings that mirror REST routes.
  • Update a few components (GA4GH TRS tool viewer, GA4GH WES run viewer, TES task APIs) to use fetcher for URL-based content/log retrieval and to slightly tighten response.ok checks and error messages.
  • Perform minor formatting/whitespace fixes in updated TypeScript/templating blocks while touching these call sites.
packages/ecc-client-ga4gh-trs/src/components/tool/tool.ts
packages/ecc-client-ga4gh-wes/src/components/run/run.ts
packages/ecc-client-elixir-trs-filer/src/providers/rest-trs-filer-provider.ts
packages/ecc-client-ga4gh-trs/src/providers/rest-trs-provider.ts
packages/ecc-client-elixir-drs-filer/src/providers/rest-drs-filer-provider.ts
packages/ecc-client-elixir-cloud-registry/src/providers/rest-cr-provider.ts
packages/ecc-client-ga4gh-wes/src/providers/rest-wes-provider.ts
packages/ecc-client-ga4gh-tes/src/API/Task/tesGet.ts
packages/ecc-client-ga4gh-drs/src/providers/rest-drs-provider.ts
packages/ecc-client-ga4gh-service-registry/src/providers/rest-sr-provider.ts
Add concrete mock JSON payloads for GA4GH and ELIXIR services and ensure they are organized under a mocks/ directory keyed by mockPath.
  • Create mocks for TRS, TRS-Filer, WES, TES, DRS, DRS-Filer, GA4GH Service Registry, and ELIXIR Cloud Registry endpoints, with file names matching the mockPath conventions (e.g. ga4gh-trs/tools/id.json).
  • Include a simple text fixture for GA4GH TRS descriptor-related URLs to back file-content fetches.
  • Add placeholder/marker files for various service-info, CRUD, and action endpoints to allow full-path coverage when mocking is enabled.
mocks/elixir-cloud-registry/service-info-post.json
mocks/elixir-cloud-registry/service-info.json
mocks/elixir-cloud-registry/services/delete.json
mocks/elixir-cloud-registry/services/get.json
mocks/elixir-cloud-registry/services/id.json
mocks/elixir-cloud-registry/services/post.json
mocks/elixir-cloud-registry/services/put.json
mocks/elixir-cloud-registry/services/types.json
mocks/elixir-drs-filer/objects/access.json
mocks/elixir-drs-filer/objects/access/delete.json
mocks/elixir-drs-filer/objects/delete.json
mocks/elixir-drs-filer/objects/get.json
mocks/elixir-drs-filer/objects/id.json
mocks/elixir-drs-filer/objects/post.json
mocks/elixir-drs-filer/objects/put.json
mocks/elixir-drs-filer/service-info-post.json
mocks/elixir-drs-filer/service-info.json
mocks/elixir-trs-filer/toolClasses/get.json
mocks/elixir-trs-filer/toolClasses/post.json
mocks/elixir-trs-filer/toolClasses/put.json
mocks/elixir-trs-filer/tools/containerfile.json
mocks/elixir-trs-filer/tools/descriptor-path.json
mocks/elixir-trs-filer/tools/descriptor.json
mocks/elixir-trs-filer/tools/files.json
mocks/elixir-trs-filer/tools/get.json
mocks/elixir-trs-filer/tools/id.json
mocks/elixir-trs-filer/tools/post.json
mocks/elixir-trs-filer/tools/put.json
mocks/elixir-trs-filer/tools/tests.json
mocks/elixir-trs-filer/tools/version-id.json
mocks/elixir-trs-filer/tools/versions-post.json
mocks/elixir-trs-filer/tools/versions-put.json
mocks/elixir-trs-filer/tools/versions.json
mocks/ga4gh-drs/objects/access.json
mocks/ga4gh-drs/objects/get.json
mocks/ga4gh-drs/objects/id.json
mocks/ga4gh-drs/service-info.json
mocks/ga4gh-service-registry/service-info.json
mocks/ga4gh-service-registry/services/get.json
mocks/ga4gh-service-registry/services/id.json
mocks/ga4gh-service-registry/services/types.json
mocks/ga4gh-tes/service-info.json
mocks/ga4gh-tes/tasks/cancel.json
mocks/ga4gh-tes/tasks/get.json
mocks/ga4gh-tes/tasks/id.json
mocks/ga4gh-tes/tasks/post.json
mocks/ga4gh-trs/toolClasses/get.json
mocks/ga4gh-trs/tools/containerfile.json
mocks/ga4gh-trs/tools/descriptor-path.json
mocks/ga4gh-trs/tools/descriptor.json
mocks/ga4gh-trs/tools/files.json
mocks/ga4gh-trs/tools/get.json
mocks/ga4gh-trs/tools/id.json
mocks/ga4gh-trs/tools/mock-content.txt
mocks/ga4gh-trs/tools/tests.json
mocks/ga4gh-trs/tools/version-id.json
mocks/ga4gh-trs/tools/versions.json
mocks/ga4gh-wes/runs/cancel.json
mocks/ga4gh-wes/runs/get.json
mocks/ga4gh-wes/runs/id.json
mocks/ga4gh-wes/runs/post.json
mocks/ga4gh-wes/runs/status.json
Add helper Node scripts to generate mock files for selected services.
  • Introduce create_trs_mocks.js, create_ga4gh_trs_mocks.js, and create_drs_mocks.js that write pre-canned JSON payloads into the mocks/* directories, easing regeneration or customization of mock data during development.
scripts/create_trs_mocks.js
scripts/create_ga4gh_trs_mocks.js
scripts/create_drs_mocks.js
Document the mock API behavior and environment knobs in the documentation site.
  • Add mocking.mdx to the docs describing how the fetcher chooses between live and mock APIs, what env vars enable mocking, and how to structure/edit mock files under /mocks.
  • Wire the new page into the docs navigation via _meta.json so it appears in the documentation sidebar.
apps/documentation/pages/docs/mocking.mdx
apps/documentation/pages/docs/_meta.json
Miscellaneous project-level and type declaration updates to support mocks and SSR testing.
  • Update .gitignore and repo layout to account for mock artifacts/symlinks (exact ignore patterns not visible in the diff snippet but implied by the description).
  • Add a Next.js env type declaration file for the SSR test app to ensure type safety when using env-driven mocking flags.
.gitignore
apps/ssr-test/next-env.d.ts

Possibly linked issues

  • #unknown: PR adds centralized fetcher, mock JSON files, env-based toggling, and docs fulfilling the mock API issue requirements.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 3 issues, and left some high level feedback:

  • The mock-generation scripts under scripts/ use absolute, user-specific filesystem paths; consider switching to paths relative to the repo root or a configurable base directory so they can be run on other machines and CI.
  • The fetcher utility logs to console.log/console.warn on every mocked or failed mock fetch; you may want to guard these behind a debug flag or environment check to avoid noisy logs in production environments.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The mock-generation scripts under `scripts/` use absolute, user-specific filesystem paths; consider switching to paths relative to the repo root or a configurable base directory so they can be run on other machines and CI.
- The `fetcher` utility logs to `console.log`/`console.warn` on every mocked or failed mock fetch; you may want to guard these behind a debug flag or environment check to avoid noisy logs in production environments.

## Individual Comments

### Comment 1
<location> `scripts/create_trs_mocks.js:4` </location>
<code_context>
+const fs = require('fs');
+const path = require('path');
+
+const mockDir = '/Users/revaa/Desktop/orgs/cloud-component/cloud-components/mocks/elixir-trs-filer';
+
+const files = {
</code_context>

<issue_to_address>
**issue (bug_risk):** Using an absolute, user-specific path for `mockDir` makes this script non-portable.

To keep this usable in CI and for other developers, derive `mockDir` from the repo instead, e.g. `path.join(__dirname, '..', 'mocks', 'elixir-trs-filer')`, or read it from an environment variable. This also helps avoid accidental writes outside the repo when local paths differ.
</issue_to_address>

### Comment 2
<location> `scripts/create_ga4gh_trs_mocks.js:4` </location>
<code_context>
+const fs = require('fs');
+const path = require('path');
+
+const mockDir = '/Users/revaa/Desktop/orgs/cloud-component/cloud-components/mocks/ga4gh-trs';
+
+const files = {
</code_context>

<issue_to_address>
**issue (bug_risk):** The GA4GH TRS mock generator also uses a hard-coded absolute path, which should be made relative.

You can mirror the approach from `create_trs_mocks.js` using something like `path.join(__dirname, '..', 'mocks', 'ga4gh-trs')` so this runs correctly in CI and on other developers’ machines.
</issue_to_address>

### Comment 3
<location> `scripts/create_drs_mocks.js:4` </location>
<code_context>
+const fs = require('fs');
+const path = require('path');
+
+const mockDir = '/Users/revaa/Desktop/orgs/cloud-component/cloud-components/mocks/ga4gh-drs';
+
+const files = {
</code_context>

<issue_to_address>
**issue (bug_risk):** The DRS mock generator also hard-codes a user-specific path for the mocks directory.

Please derive `mockDir` from the script location or project root (e.g., via `__dirname` and `path.join`) instead of using an absolute path, so the script works on other machines and in CI.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

const fs = require('fs');
const path = require('path');

const mockDir = '/Users/revaa/Desktop/orgs/cloud-component/cloud-components/mocks/elixir-trs-filer';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Using an absolute, user-specific path for mockDir makes this script non-portable.

To keep this usable in CI and for other developers, derive mockDir from the repo instead, e.g. path.join(__dirname, '..', 'mocks', 'elixir-trs-filer'), or read it from an environment variable. This also helps avoid accidental writes outside the repo when local paths differ.

const fs = require('fs');
const path = require('path');

const mockDir = '/Users/revaa/Desktop/orgs/cloud-component/cloud-components/mocks/ga4gh-trs';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): The GA4GH TRS mock generator also uses a hard-coded absolute path, which should be made relative.

You can mirror the approach from create_trs_mocks.js using something like path.join(__dirname, '..', 'mocks', 'ga4gh-trs') so this runs correctly in CI and on other developers’ machines.

const fs = require('fs');
const path = require('path');

const mockDir = '/Users/revaa/Desktop/orgs/cloud-component/cloud-components/mocks/ga4gh-drs';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): The DRS mock generator also hard-codes a user-specific path for the mocks directory.

Please derive mockDir from the script location or project root (e.g., via __dirname and path.join) instead of using an absolute path, so the script works on other machines and in CI.

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.

Create Mock APIs for All Services in Documentation and Demo Pages

1 participant