@coinbase/cdp-sdk
Version:
SDK for interacting with the Coinbase Developer Platform Wallet API
136 lines (127 loc) • 4.65 kB
text/typescript
/**
* Generated by orval v7.6.0 🍺
* Do not edit manually.
* Coinbase Developer Platform APIs
* The Coinbase Developer Platform APIs - leading the world's transition onchain.
* OpenAPI spec version: 2.0.0
*/
import { faker } from "@faker-js/faker";
import { HttpResponse, delay, http } from "msw";
import {
OnrampOrderStatus,
OnrampPaymentLinkType,
OnrampPaymentMethodTypeId,
} from "../coinbaseDeveloperPlatformAPIs.schemas.js";
import type {
CreateOnrampOrder201,
GetOnrampOrderById200,
} from "../coinbaseDeveloperPlatformAPIs.schemas.js";
export const getCreateOnrampOrderResponseMock = (
overrideResponse: Partial<CreateOnrampOrder201> = {},
): CreateOnrampOrder201 => ({
order: {
orderId: faker.string.alpha(20),
paymentTotal: faker.string.alpha(20),
paymentSubtotal: faker.string.alpha(20),
paymentCurrency: faker.string.alpha(20),
paymentMethod: faker.helpers.arrayElement(Object.values(OnrampPaymentMethodTypeId)),
purchaseAmount: faker.string.alpha(20),
purchaseCurrency: faker.string.alpha(20),
fees: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(
() => ({
type: faker.helpers.arrayElement(["FEE_TYPE_NETWORK", "FEE_TYPE_EXCHANGE"] as const),
amount: faker.string.alpha(20),
currency: faker.string.alpha(20),
}),
),
exchangeRate: faker.string.alpha(20),
destinationAddress: faker.string.alpha(20),
destinationNetwork: faker.string.alpha(20),
status: faker.helpers.arrayElement(Object.values(OnrampOrderStatus)),
txHash: faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
createdAt: faker.string.alpha(20),
updatedAt: faker.string.alpha(20),
},
paymentLink: faker.helpers.arrayElement([
{
url: faker.string.alpha(20),
paymentLinkType: faker.helpers.arrayElement(Object.values(OnrampPaymentLinkType)),
},
undefined,
]),
...overrideResponse,
});
export const getGetOnrampOrderByIdResponseMock = (
overrideResponse: Partial<GetOnrampOrderById200> = {},
): GetOnrampOrderById200 => ({
order: {
orderId: faker.string.alpha(20),
paymentTotal: faker.string.alpha(20),
paymentSubtotal: faker.string.alpha(20),
paymentCurrency: faker.string.alpha(20),
paymentMethod: faker.helpers.arrayElement(Object.values(OnrampPaymentMethodTypeId)),
purchaseAmount: faker.string.alpha(20),
purchaseCurrency: faker.string.alpha(20),
fees: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(
() => ({
type: faker.helpers.arrayElement(["FEE_TYPE_NETWORK", "FEE_TYPE_EXCHANGE"] as const),
amount: faker.string.alpha(20),
currency: faker.string.alpha(20),
}),
),
exchangeRate: faker.string.alpha(20),
destinationAddress: faker.string.alpha(20),
destinationNetwork: faker.string.alpha(20),
status: faker.helpers.arrayElement(Object.values(OnrampOrderStatus)),
txHash: faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
createdAt: faker.string.alpha(20),
updatedAt: faker.string.alpha(20),
},
...overrideResponse,
});
export const getCreateOnrampOrderMockHandler = (
overrideResponse?:
| CreateOnrampOrder201
| ((
info: Parameters<Parameters<typeof http.post>[1]>[0],
) => Promise<CreateOnrampOrder201> | CreateOnrampOrder201),
) => {
return http.post("*/v2/onramp/orders", async info => {
await delay(0);
return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === "function"
? await overrideResponse(info)
: overrideResponse
: getCreateOnrampOrderResponseMock(),
),
{ status: 201, headers: { "Content-Type": "application/json" } },
);
});
};
export const getGetOnrampOrderByIdMockHandler = (
overrideResponse?:
| GetOnrampOrderById200
| ((
info: Parameters<Parameters<typeof http.get>[1]>[0],
) => Promise<GetOnrampOrderById200> | GetOnrampOrderById200),
) => {
return http.get("*/v2/onramp/orders/:orderId", async info => {
await delay(0);
return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === "function"
? await overrideResponse(info)
: overrideResponse
: getGetOnrampOrderByIdResponseMock(),
),
{ status: 200, headers: { "Content-Type": "application/json" } },
);
});
};
export const getOnrampMock = () => [
getCreateOnrampOrderMockHandler(),
getGetOnrampOrderByIdMockHandler(),
];