46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import { describe, test, expect, vi } from 'vitest';
|
|
import { GET } from '$root/routes/api/vorgang/[vorgang]/vorgangPIN/+server';
|
|
import { db } from '$lib/server/dbService';
|
|
import { baseData } from '../fixtures';
|
|
|
|
const mockEvent = {
|
|
params: { vorgang: '123' },
|
|
locals: { user: baseData.user }
|
|
};
|
|
|
|
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('');
|
|
});
|
|
});
|