organize tests into units

This commit is contained in:
2025-09-30 11:43:54 +02:00
parent e1e76612d6
commit 2863eae3fb
13 changed files with 22 additions and 22 deletions

View File

@@ -0,0 +1,43 @@
import { describe, test, expect, vi } from 'vitest';
import { GET } from '$root/routes/api/vorgang/[vorgang]/vorgangPIN/+server';
import { db } from '$lib/server/dbService';
const mockEvent = {
params: { vorgang: '123' }
};
vi.mock('$lib/server/dbService', () => ({
db: {
prepare: vi.fn()
}
}));
describe('API-Endpoint: Vorgang-PIN', () => {
test('Vorgang PIN: Erfolgreich', async () => {
// only interested in PIN value
const mockPIN = 'pin-123';
const mockRow = { pin: mockPIN };
const getMock = vi.fn().mockReturnValue(mockRow);
db.prepare.mockReturnValue({ get: getMock });
const response = await GET(mockEvent);
expect(response.status).toBe(200);
const body = await response.text();
expect(body).toEqual(mockPIN);
});
test('Vorgang PIN: Nicht erfolgreich', async () => {
const mockRow = {};
const getMock = vi.fn().mockReturnValue(mockRow);
db.prepare.mockReturnValue({ get: getMock });
const response = await GET(mockEvent);
expect(response.status).toBe(404);
const body = await response.text();
expect(body).toEqual('');
});
});