Skip to content

MockForgeAdapter

Defined in: packages/core/src/test-utils/MockForgeAdapter.ts:57

A test double for ForgeAdapter that records all calls and returns configurable responses from a FIFO queue.

This is the primary tool for unit testing generated client functions without a real Forge runtime or network connection.

Responses are dequeued in the order they were queued. If the queue is empty, a default 200 OK with {} body is returned. Errors queued via queueThrow() are thrown before checking the response queue.

import { MockForgeAdapter, asApp } from '@forge-clients/core';
import { getIssue } from '@forge-clients/jira/v3';
const mock = new MockForgeAdapter('jira');
mock.queueResponse({ id: '123', key: 'PROJ-1', fields: {} });
const client = asApp(mock);
const issue = await getIssue(client, { path: { issueIdOrKey: 'PROJ-1' } });
expect(mock.callCount).toBe(1);
expect(mock.getLastCall()?.path).toBe('/rest/api/3/issue/PROJ-1');

new MockForgeAdapter(product?): MockForgeAdapter

Defined in: packages/core/src/test-utils/MockForgeAdapter.ts:68

Create a new MockForgeAdapter.

"jira" | "confluence"

The Atlassian product to simulate (default: 'jira')

MockForgeAdapter

readonly product: "jira" | "confluence"

Defined in: packages/core/src/test-utils/MockForgeAdapter.ts:58

The Atlassian product this adapter is configured to make requests to

ForgeAdapter.product

get callCount(): number

Defined in: packages/core/src/test-utils/MockForgeAdapter.ts:107

The total number of calls made to fetch() since the last reset()

number

fetch(options): Promise<Response>

Defined in: packages/core/src/test-utils/MockForgeAdapter.ts:72

Execute an HTTP request and return a standard Response. Implementations are responsible for authentication header injection, URL construction, and serialisation.

ForgeRequestOptions

Promise<Response>

ForgeAdapter.fetch


getCall(index): RecordedCall | undefined

Defined in: packages/core/src/test-utils/MockForgeAdapter.ts:105

Returns the recorded call at the given zero-based index, or undefined if out of range

number

RecordedCall | undefined


getCalls(): RecordedCall[]

Defined in: packages/core/src/test-utils/MockForgeAdapter.ts:101

Returns a copy of all recorded calls in the order they were made

RecordedCall[]


getLastCall(): RecordedCall | undefined

Defined in: packages/core/src/test-utils/MockForgeAdapter.ts:103

Returns the most recent recorded call, or undefined if no calls have been made

RecordedCall | undefined


queueErrorResponse(status, body?): this

Defined in: packages/core/src/test-utils/MockForgeAdapter.ts:131

Queue a non-2xx error response

number

unknown = {}

this


queueNoContent(): this

Defined in: packages/core/src/test-utils/MockForgeAdapter.ts:142

Queue a 204 No Content response

this


queueResponse(body, status?): this

Defined in: packages/core/src/test-utils/MockForgeAdapter.ts:120

Queue a successful JSON response (FIFO order)

unknown

number = 200

this


queueThrow(error?): this

Defined in: packages/core/src/test-utils/MockForgeAdapter.ts:148

Queue a network-level error (fetch throws, no Response)

Error = ...

this


reset(): this

Defined in: packages/core/src/test-utils/MockForgeAdapter.ts:110

Reset all recorded calls and queued responses

this