-
Notifications
You must be signed in to change notification settings - Fork 0
test: add convenient API for applying custom schema based mocks #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b2e76ba
test: add mock wrapper
kantord 69b7265
better import experience
kantord 91db28b
update mocks documentation
kantord 65cef62
add some usage examples for mock overrides
kantord 2e7dbf2
add overrideResponse helper
kantord bc387f0
encourage type safety in mock overrides
kantord 4c1d01b
allow creating reusable scenarios?
kantord 5f64128
add shared type for mock scenarios
kantord 3924281
simple way to activate same scenario across multipl mocks
kantord 6f30446
jsdoc for mock scenarios
kantord f9dd352
reduce pr size
kantord 3183f97
address claude code review points
kantord 6228d1a
improve wording in jsdoc
kantord 10a9ecf
make docs less verbose
kantord a0b56a3
test: mock token retrieval globally
kantord 23f3f45
apply some of copilot's suggestions
kantord File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/app/catalog/[repoName]/[serverName]/[version]/actions.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { getServerDetails } from "./actions"; | ||
|
|
||
| // Mock the auth to bypass authentication | ||
| vi.mock("@/lib/api-client", async (importOriginal) => { | ||
| const original = await importOriginal<typeof import("@/lib/api-client")>(); | ||
| return { | ||
| ...original, | ||
| getAuthenticatedClient: vi.fn(() => | ||
| original.getAuthenticatedClient("mock-token"), | ||
| ), | ||
| }; | ||
| }); | ||
|
|
||
| describe("getServerDetails", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| describe("successful responses", () => { | ||
| it("returns server data for valid server name and version", async () => { | ||
| const result = await getServerDetails("awslabs/aws-nova-canvas", "1.0.0"); | ||
|
|
||
| expect(result.error).toBeUndefined(); | ||
| expect(result.data?.server?.name).toBe("awslabs/aws-nova-canvas"); | ||
| expect(result.data?.server?.title).toBe("AWS Nova Canvas"); | ||
| }); | ||
|
|
||
| it("returns server data when version is 'latest'", async () => { | ||
| const result = await getServerDetails( | ||
| "awslabs/aws-nova-canvas", | ||
| "latest", | ||
| ); | ||
|
|
||
| expect(result.error).toBeUndefined(); | ||
| expect(result.data?.server?.name).toBe("awslabs/aws-nova-canvas"); | ||
| }); | ||
|
|
||
| it("returns different servers from fixture", async () => { | ||
| const result = await getServerDetails("google/mcp-google-apps", "1.0.0"); | ||
|
|
||
| expect(result.error).toBeUndefined(); | ||
| expect(result.data?.server?.name).toBe("google/mcp-google-apps"); | ||
| expect(result.data?.server?.title).toBe("Google Workspace"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("error handling", () => { | ||
| it("returns 404 for non-existent server", async () => { | ||
| const result = await getServerDetails("non-existent/server", "1.0.0"); | ||
|
|
||
| expect(result.response.status).toBe(404); | ||
| }); | ||
|
|
||
| it("returns 404 for wrong version", async () => { | ||
| const result = await getServerDetails("awslabs/aws-nova-canvas", "9.9.9"); | ||
|
|
||
| expect(result.response.status).toBe(404); | ||
| }); | ||
| }); | ||
|
|
||
| describe("fixture data", () => { | ||
| it("includes metadata in response", async () => { | ||
| const result = await getServerDetails("awslabs/aws-nova-canvas", "1.0.0"); | ||
|
|
||
| expect(result.data?._meta).toBeDefined(); | ||
| }); | ||
|
|
||
| it("returns full server details from fixture", async () => { | ||
| const result = await getServerDetails("awslabs/aws-nova-canvas", "1.0.0"); | ||
|
|
||
| expect(result.data?.server?.name).toBe("awslabs/aws-nova-canvas"); | ||
| expect(result.data?.server?.version).toBe("1.0.0"); | ||
| expect(result.data?.server?.description).toContain("MCP server"); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.