quickbooks-api
Version:
A modular TypeScript SDK for seamless integration with Intuit QuickBooks APIs. Provides robust authentication handling and future-ready foundation for accounting, payments, and commerce operations.
67 lines (57 loc) • 2.33 kB
text/typescript
// Imports
import { mock } from 'bun:test';
/**
* Mocks the fetch function
* @param response - The response to mock
* @param ok - Whether the response is ok
* @returns The mocked fetch function
*/
export function mockFetch(responseData: BodyInit, responseStatus = 200, contentType = 'application/json') {
// Setup the Mock
return mock<typeof fetch>(async (_input: URL | RequestInfo, options: undefined | RequestInit) => {
// Check if the options are not valid
if (!options) throw new Error('Invalid options');
// Setup the Response Body
const responseBody: BodyInit = responseData;
// Setup the New Response
const response = new Response(responseBody, {
status: responseStatus,
headers: { 'Content-Type': contentType, intuit_tid: 'test-tid-12345-67890' },
});
// Return the Response
return response;
});
}
/**
* Mocks the fetch function for PDF responses
* @param pdfData - The PDF blob data to mock
* @param responseStatus - The response status code
* @returns The mocked fetch function
*/
export function mockPDF(pdfData: Blob | ArrayBuffer, responseStatus = 200) {
// Setup the Mock
return mock<typeof fetch>(async (_input: URL | RequestInfo, options: undefined | RequestInit) => {
// Check if the options are not valid
if (!options) throw new Error('Invalid options');
// Setup the Response Body
const responseBody: BodyInit = pdfData instanceof Blob ? pdfData : new Blob([pdfData]);
// Setup the New Response
const response = new Response(responseBody, {
status: responseStatus,
headers: { 'Content-Type': 'application/pdf', intuit_tid: 'test-tid-12345-67890' },
});
// Return the Response
return response;
});
}
// Export the Mock Data
export { mockAuthResponseData } from './__mocks__/auth-response-data';
export { mockTokenData } from './__mocks__/token-data';
export { mockInvoiceData } from './__mocks__/invoice-data';
export { mockCustomerData } from './__mocks__/customer-data';
export { mockEstimateData } from './__mocks__/estimate-data';
export { mockPreferenceData } from './__mocks__/preference-data';
export { mockCreditMemoData } from './__mocks__/credit-memo-data';
export { mockPaymentData } from './__mocks__/payment-data';
export { mockAccountData } from './__mocks__/account-data';
export { mockBillData } from './__mocks__/bill-data';