Files
accounted/lib/providers/fortnox/__tests__/client.test.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

55 lines
1.7 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { FortnoxApiError, FortnoxClient } from '../client';
describe('FortnoxClient.getBinary', () => {
beforeEach(() => {
vi.stubEnv('UPSTASH_REDIS_REST_URL', '');
vi.stubEnv('UPSTASH_REDIS_REST_TOKEN', '');
});
afterEach(() => {
vi.unstubAllGlobals();
vi.unstubAllEnvs();
});
it('returns the raw bytes and response content type', async () => {
const fetchMock = vi.fn().mockResolvedValue(
new Response(Uint8Array.from([1, 2, 3]), {
status: 200,
headers: { 'Content-Type': 'application/pdf' },
}),
);
vi.stubGlobal('fetch', fetchMock);
const client = new FortnoxClient('https://fortnox.example.test/3');
const result = await client.getBinary('access-token', '/archive/file-1');
expect(Array.from(new Uint8Array(result.bytes))).toEqual([1, 2, 3]);
expect(result.contentType).toBe('application/pdf');
expect(fetchMock).toHaveBeenCalledWith(
'https://fortnox.example.test/3/archive/file-1',
expect.objectContaining({
headers: { Authorization: 'Bearer access-token' },
}),
);
});
it('preserves the HTTP status on binary request failures', async () => {
vi.stubGlobal(
'fetch',
vi.fn().mockResolvedValue(
new Response('missing', { status: 404, statusText: 'Not Found' }),
),
);
const client = new FortnoxClient('https://fortnox.example.test/3');
const error = await client
.getBinary('access-token', '/archive/file-1')
.catch((caught: unknown) => caught);
expect(error).toBeInstanceOf(FortnoxApiError);
expect(error).toMatchObject({ statusCode: 404, body: 'missing' });
});
});