add tests for API endpoint: vorgang/[vorgang]/vorgangPIN
This commit is contained in:
43
tests/APIVorgangVorgangVorgangPIN.test.ts
Normal file
43
tests/APIVorgangVorgangVorgangPIN.test.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { describe, test, expect, vi } from 'vitest';
|
||||
import { GET } from '../src/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('');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user