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:
2026-01-15 14:41:44 +01:00
parent be4377253e
commit 5bde27dcdd
6 changed files with 377 additions and 218 deletions

View 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;
}