generated from coulomb/repo-seed
Fix base64 encoding for browser environment
The bufferToBase64 function from @binect/js expects Node.js Buffer objects but was receiving browser ArrayBuffer, causing "[object ArrayBuffer]" to be sent instead of valid base64. Use browser-native btoa() instead. Also updates tests to work with @binect/js integration. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
82
tests/__mocks__/@binect/js.ts
Normal file
82
tests/__mocks__/@binect/js.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* Mock for @binect/js library
|
||||
*/
|
||||
|
||||
export class BinectApiError extends Error {
|
||||
status: number;
|
||||
response?: unknown;
|
||||
|
||||
constructor(message: string, status: number, response?: unknown) {
|
||||
super(message);
|
||||
this.name = 'BinectApiError';
|
||||
this.status = status;
|
||||
this.response = response;
|
||||
}
|
||||
}
|
||||
|
||||
export class BinectAuthError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = 'BinectAuthError';
|
||||
}
|
||||
}
|
||||
|
||||
export const EnvelopeType = {
|
||||
DINLANG: 'DINLANG',
|
||||
C4: 'C4',
|
||||
} as const;
|
||||
|
||||
export const FrankingType = {
|
||||
UNSPECIFIED: 'UNSPECIFIED',
|
||||
STANDARD_FRANKING: 'STANDARD_FRANKING',
|
||||
DV_FRANKING: 'DV_FRANKING',
|
||||
} as const;
|
||||
|
||||
// Mock document response
|
||||
const mockDocument = {
|
||||
id: 123,
|
||||
filename: 'test.pdf',
|
||||
numberOfPages: 2,
|
||||
status: { code: 2, text: 'shippable' },
|
||||
documentType: 'LETTER',
|
||||
letter: {
|
||||
letterType: 'LetterData',
|
||||
letterData: {
|
||||
recipientAddress: 'Test Address',
|
||||
price: { priceBeforeTax: 100, priceAfterTax: 119, unit: 'EUROCENT', taxInPercent: 19 },
|
||||
international: false,
|
||||
options: { simplex: false, color: false },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// Mock account response
|
||||
const mockAccount = {
|
||||
id: 1,
|
||||
email: 'test@example.com',
|
||||
};
|
||||
|
||||
export class BinectClient {
|
||||
documents = {
|
||||
upload: jest.fn().mockResolvedValue(mockDocument),
|
||||
};
|
||||
|
||||
accounts = {
|
||||
get: jest.fn().mockResolvedValue(mockAccount),
|
||||
};
|
||||
|
||||
constructor(_config: { username: string; password: string }) {
|
||||
// Store config if needed for tests
|
||||
}
|
||||
}
|
||||
|
||||
export type Document = typeof mockDocument;
|
||||
|
||||
export interface DocumentUploadOptions {
|
||||
content: string;
|
||||
filename: string;
|
||||
simplex?: boolean;
|
||||
color?: boolean;
|
||||
envelope?: string;
|
||||
franking?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user