Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/mock-api-layer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@elixir-cloud/cloud-registry": minor
"@elixir-cloud/design": minor
"@elixir-cloud/drs": minor
"@elixir-cloud/drs-filer": minor
"@elixir-cloud/service-registry": minor
"@elixir-cloud/tes": minor
"@elixir-cloud/trs": minor
"@elixir-cloud/trs-filer": minor
"@elixir-cloud/wes": minor
---

feat: complete mock API layer implementation
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ yarn-error.log*
# vercel
.vercel

.idea
.idea

apps/documentation/public/mocks
1 change: 1 addition & 0 deletions apps/documentation/pages/docs/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"introduction": "Introduction",
"installation": "Installation",
"customization": "Customization",
"mocking": "Mock APIs",
"providers": "Providers",
"-- Supported Services": {
"type": "separator",
Expand Down
32 changes: 32 additions & 0 deletions apps/documentation/pages/docs/mocking.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Mock APIs

ELIXIR Cloud Components provides a built-in mock API layer to allow reliable testing, offline development, and demonstration without relying on live services.

Our documentation and demo pages are configured to use these mock responses to ensure consistent behavior.

## Enabling Mock APIs

The mock API layer is controlled via environment variables. By default, components will attempt to use live API routes provided via the `baseUrl` property. If you want to intercept these requests and serve mock data instead, set the appropriate environment variable:

- **For Vite / standard web environments:** `VITE_USE_MOCK_API=true`
- **For Next.js environments:** `NEXT_PUBLIC_USE_MOCK_API=true`

Once enabled, API calls (e.g., fetching a GA4GH WES run or an ELIXIR Service Registry listing) will automatically be intercepted and resolved using local JSON files.

## How it works

The components use a centralized `fetcher` utility from `@elixir-cloud/design` under the hood. When the mock environment variable is detected, `fetcher` substitutes the HTTP request with a local fetch to the `/mocks/` directory.

> **Note:** If a mock file doesn't exist for a particular endpoint, the library will gracefully fall back to the live API to ensure development isn't blocked.

## Writing or Updating Mocks

Mock files are standard JSON files stored in the `mocks/` directory at the root of the repository. When setting up a new application or documentation site, ensure that this folder is publicly served (e.g., via a symlink to `public/mocks/` in Next.js).

If you want to modify a mock response, simply edit the corresponding JSON file. For example, to change the mocked response of a specific TRS tool, you would modify:

```text
/mocks/ga4gh-trs/tools/id.json
```

No rebuild of the components is necessary when updating mock JSON files—they are resolved at runtime by the browser.
6 changes: 6 additions & 0 deletions apps/ssr-test/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
import "./.next/types/routes.d.ts";

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
1 change: 1 addition & 0 deletions mocks/elixir-cloud-registry/service-info-post.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
14 changes: 14 additions & 0 deletions mocks/elixir-cloud-registry/service-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "mock-registry-info-001",
"name": "Mock ELIXIR Registry Info",
"type": {
"group": "org.elixir",
"artifact": "registry-info",
"version": "1.0.0"
},
"organization": {
"name": "ELIXIR Mock",
"url": "https://example.com"
},
"version": "1.0.0"
}
3 changes: 3 additions & 0 deletions mocks/elixir-cloud-registry/services/delete.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "mock-elixir-cr-deleted"
}
17 changes: 17 additions & 0 deletions mocks/elixir-cloud-registry/services/get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"id": "mock-elixir-cr-001",
"name": "Mock ELIXIR Cloud Registry Service",
"type": {
"group": "org.elixir",
"artifact": "cloud-registry",
"version": "1.0.0"
},
"organization": {
"name": "ELIXIR Mock",
"url": "https://example.com"
},
"version": "1.0.0",
"url": "https://example.com/cr/v1"
}
]
15 changes: 15 additions & 0 deletions mocks/elixir-cloud-registry/services/id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"id": "mock-elixir-cr-001",
"name": "Mock ELIXIR Cloud Registry Service",
"type": {
"group": "org.elixir",
"artifact": "cloud-registry",
"version": "1.0.0"
},
"organization": {
"name": "ELIXIR Mock",
"url": "https://example.com"
},
"version": "1.0.0",
"url": "https://example.com/cr/v1"
}
3 changes: 3 additions & 0 deletions mocks/elixir-cloud-registry/services/post.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "mock-elixir-cr-new-post"
}
3 changes: 3 additions & 0 deletions mocks/elixir-cloud-registry/services/put.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "mock-elixir-cr-put"
}
7 changes: 7 additions & 0 deletions mocks/elixir-cloud-registry/services/types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"group": "org.elixir",
"artifact": "cloud-registry",
"version": "1.0.0"
}
]
4 changes: 4 additions & 0 deletions mocks/elixir-drs-filer/objects/access.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"url": "https://example.com/mock-drs-file.txt",
"headers": []
}
1 change: 1 addition & 0 deletions mocks/elixir-drs-filer/objects/access/delete.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions mocks/elixir-drs-filer/objects/delete.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
24 changes: 24 additions & 0 deletions mocks/elixir-drs-filer/objects/get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"objects": [
{
"id": "mock-drs-001",
"name": "Mock DRS Object 1",
"size": 1024,
"created_time": "2023-01-01T00:00:00Z",
"updated_time": "2023-01-01T00:00:00Z",
"version": "1.0",
"mime_type": "text/plain",
"checksums": [
{
"type": "md5",
"checksum": "d41d8cd98f00b204e9800998ecf8427e"
}
]
}
],
"pagination": {
"offset": 0,
"limit": 10,
"total": 1
}
}
22 changes: 22 additions & 0 deletions mocks/elixir-drs-filer/objects/id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"id": "mock-drs-001",
"name": "Mock DRS Object 1",
"size": 1024,
"created_time": "2023-01-01T00:00:00Z",
"updated_time": "2023-01-01T00:00:00Z",
"version": "1.0",
"mime_type": "text/plain",
"checksums": [
{
"type": "md5",
"checksum": "d41d8cd98f00b204e9800998ecf8427e"
}
],
"access_methods": [
{
"access_id": "access-001",
"type": "s3",
"region": "us-east-1"
}
]
}
3 changes: 3 additions & 0 deletions mocks/elixir-drs-filer/objects/post.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "mock-drs-newly-created"
}
3 changes: 3 additions & 0 deletions mocks/elixir-drs-filer/objects/put.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "mock-drs-updated"
}
1 change: 1 addition & 0 deletions mocks/elixir-drs-filer/service-info-post.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
14 changes: 14 additions & 0 deletions mocks/elixir-drs-filer/service-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "mock-drs-service",
"name": "Mock DRS Service",
"type": {
"group": "org.ga4gh",
"artifact": "drs",
"version": "1.1.0"
},
"organization": {
"name": "Mock Org",
"url": "https://example.com"
},
"version": "1.1.0"
}
1 change: 1 addition & 0 deletions mocks/elixir-trs-filer/toolClasses/get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id": "mock-class", "name": "Mock Class", "description": "Mock class description"}]
1 change: 1 addition & 0 deletions mocks/elixir-trs-filer/toolClasses/post.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id": "mock-toolclass-post"}
1 change: 1 addition & 0 deletions mocks/elixir-trs-filer/toolClasses/put.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id": "mock-toolclass-put"}
1 change: 1 addition & 0 deletions mocks/elixir-trs-filer/tools/containerfile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"content": "FROM ubuntu:latest\nRUN echo mock", "url": "https://example.com/containerfile"}]
1 change: 1 addition & 0 deletions mocks/elixir-trs-filer/tools/descriptor-path.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"content": "mock descriptor by path", "url": "https://example.com/descriptor"}
1 change: 1 addition & 0 deletions mocks/elixir-trs-filer/tools/descriptor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"content": "mock descriptor content", "url": "https://example.com/descriptor"}
1 change: 1 addition & 0 deletions mocks/elixir-trs-filer/tools/files.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"path": "/mock/file.txt", "file_type": "TEST_FILE"}]
1 change: 1 addition & 0 deletions mocks/elixir-trs-filer/tools/get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id": "mock-tool-001", "name": "Mock Tool", "organization": "Mock Org"}]
1 change: 1 addition & 0 deletions mocks/elixir-trs-filer/tools/id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id": "mock-tool-001", "name": "Mock Tool", "organization": "Mock Org", "description": "A mocked tool"}
1 change: 1 addition & 0 deletions mocks/elixir-trs-filer/tools/post.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id": "mock-tool-new-post"}
1 change: 1 addition & 0 deletions mocks/elixir-trs-filer/tools/put.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id": "mock-tool-put-updated"}
1 change: 1 addition & 0 deletions mocks/elixir-trs-filer/tools/tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"content": "mock test content", "url": "https://example.com/test"}]
1 change: 1 addition & 0 deletions mocks/elixir-trs-filer/tools/version-id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id": "v1", "name": "Version 1.0", "author": ["Mock Author"], "is_production": true}
1 change: 1 addition & 0 deletions mocks/elixir-trs-filer/tools/versions-post.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id": "mock-version-post"}
1 change: 1 addition & 0 deletions mocks/elixir-trs-filer/tools/versions-put.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id": "mock-version-put"}
1 change: 1 addition & 0 deletions mocks/elixir-trs-filer/tools/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id": "v1", "name": "Version 1.0", "author": ["Mock Author"]}]
4 changes: 4 additions & 0 deletions mocks/ga4gh-drs/objects/access.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"url": "https://example.com/mock-drs-file.txt",
"headers": []
}
24 changes: 24 additions & 0 deletions mocks/ga4gh-drs/objects/get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"objects": [
{
"id": "mock-drs-001",
"name": "Mock DRS Object 1",
"size": 1024,
"created_time": "2023-01-01T00:00:00Z",
"updated_time": "2023-01-01T00:00:00Z",
"version": "1.0",
"mime_type": "text/plain",
"checksums": [
{
"type": "md5",
"checksum": "d41d8cd98f00b204e9800998ecf8427e"
}
]
}
],
"pagination": {
"offset": 0,
"limit": 10,
"total": 1
}
}
22 changes: 22 additions & 0 deletions mocks/ga4gh-drs/objects/id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"id": "mock-drs-001",
"name": "Mock DRS Object 1",
"size": 1024,
"created_time": "2023-01-01T00:00:00Z",
"updated_time": "2023-01-01T00:00:00Z",
"version": "1.0",
"mime_type": "text/plain",
"checksums": [
{
"type": "md5",
"checksum": "d41d8cd98f00b204e9800998ecf8427e"
}
],
"access_methods": [
{
"access_id": "access-001",
"type": "s3",
"region": "us-east-1"
}
]
}
14 changes: 14 additions & 0 deletions mocks/ga4gh-drs/service-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "mock-ga4gh-drs-service",
"name": "Mock GA4GH DRS Service",
"type": {
"group": "org.ga4gh",
"artifact": "drs",
"version": "1.1.0"
},
"organization": {
"name": "Mock Org",
"url": "https://example.com"
},
"version": "1.1.0"
}
14 changes: 14 additions & 0 deletions mocks/ga4gh-service-registry/service-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "mock-registry-001",
"name": "Mock Service Registry",
"type": {
"group": "org.ga4gh",
"artifact": "service-registry",
"version": "1.0.0"
},
"organization": {
"name": "ELIXIR Mock",
"url": "https://example.com"
},
"version": "1.0.0"
}
17 changes: 17 additions & 0 deletions mocks/ga4gh-service-registry/services/get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"id": "mock-service-001",
"name": "Mock Service 1",
"type": {
"group": "org.ga4gh",
"artifact": "tes",
"version": "1.0.0"
},
"organization": {
"name": "ELIXIR Mock",
"url": "https://example.com"
},
"version": "1.0.0",
"url": "https://example.com/tes/v1"
}
]
Loading