Class: PatreonMock
Defined in: schemas/v2/mock/mock.ts:148
A class with utitilies to mock the Patreon API
See
https://patreon-api.pages.dev/guide/features/sandbox
Constructors
Constructor
new PatreonMock(
options?):PatreonMock
Defined in: schemas/v2/mock/mock.ts:153
Parameters
| Parameter | Type |
|---|---|
options | PatreonMockOptions |
Returns
PatreonMock
Properties
| Property | Modifier | Type | Default value | Description |
|---|---|---|---|---|
cache | public | CacheStore<false> | undefined | - |
data | public | PatreonMockData | undefined | - |
options | public | PatreonMockOptions | {} | - |
webhooks | public | PatreonMockWebhooks | undefined | - |
origin | static | string | undefined | The origin url for the Patreon API Default 'https://patreon.com' |
path | static | string | undefined | The API path that every route starts with Default '/api/oauth2/v2' |
Methods
getMockAgentReplyCallback()
getMockAgentReplyCallback(
options?): (callbackOptions) => {data?:string;responseOptions: {headers:Record<string,string>; };statusCode:number; }
Defined in: schemas/v2/mock/mock.ts:490
Note: Uses the undici-types package for typing. If you don't have undici, @types/node or undici-types installed, ts will be not be able to import the types.
Creates a callback for an intercepted request on a mock agent.
Note: for non-GET requests and if no mocked attributes are defined; the request body is returned as response body.
Parameters
| Parameter | Type | Description |
|---|---|---|
options? | PatreonMockHandlerOptions | Options for the mocked response |
Returns
the intercept callback
(callbackOptions) => { data?: string; responseOptions: { headers: Record<string, string>; }; statusCode: number; }
getMockHandlers()
getMockHandlers<
R,T>(options?):Record<"getCampaign"|"getCampaigns"|"getIdentity"|"getLive"|"deleteLive"|"editLive"|"createLive"|"getCampaignMembers"|"getMember"|"getCampaignPosts"|"getPost"|"editWebhook"|"deleteWebhook"|"getWebhooks"|"createWebhook",PatreonMockHandler<If<T,Response,R>>>
Defined in: schemas/v2/mock/mock.ts:519
Get handlers for mocking a route
Note: for non-GET requests and if no mocked attributes are defined; the request body is returned as response body.
Type Parameters
| Type Parameter | Default type |
|---|---|
R | PatreonMockHandlerDefaultResponse |
T extends boolean | false |
Parameters
| Parameter | Type | Description |
|---|---|---|
options? | PatreonMockHandlerOptions & { includeOrigin?: boolean; pathParam?: string; transformResponse?: (response) => R; transformToResponse?: T; } | Options for generating the routes |
Returns
Record<"getCampaign" | "getCampaigns" | "getIdentity" | "getLive" | "deleteLive" | "editLive" | "createLive" | "getCampaignMembers" | "getMember" | "getCampaignPosts" | "getPost" | "editWebhook" | "deleteWebhook" | "getWebhooks" | "createWebhook", PatreonMockHandler<If<T, Response, R>>>
Handlers for each route that returns a successful response.
See
https://patreon-api.pages.dev/guide/features/sandbox#msw
pathFilter()
staticpathFilter(path):boolean
Defined in: schemas/v2/mock/mock.ts:182
A filter to check if a random path is an API route
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | The path to check. Can include query parameters |
Returns
boolean
if the path is valid route for the V2 Patreon API
route()
staticroute(path,options?):string
Defined in: schemas/v2/mock/mock.ts:196
Create a mocked route
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | The request path to use: /api/oauth2/v2 |
options? | { includeOrigin?: boolean; query?: string; } | Path options |
options.includeOrigin? | boolean | Include the origin url (default false) |
options.query? | string | The url query to append |
Returns
string
the mocked API route