f100_backend_api-endpoints_tests #31

Merged
jared merged 17 commits from f100_backend_api-endpoints_tests into development 2025-09-04 15:16:50 +02:00
Showing only changes of commit 821b8a6440 - Show all commits

View File

@@ -1,4 +1,4 @@
import { describe, test, expect, vi } from 'vitest';
import { describe, test, expect, vi, beforeEach } from 'vitest';
import { GET, POST } from '../src/routes/api/users/+server';
import bcrypt from 'bcrypt';
@@ -33,6 +33,12 @@ describe('API-Endpoint: Users', () => {
// [INFO] Test auf keine User nicht notwendig, da immer min. ein User vorhanden
// Mock eingelogter User bzw. stelle locals.user zur Verfügung
const fakeLoggedInUser = { id: 'admin', admin: true };
const mockLocals = {
user: fakeLoggedInUser
};
test('Rufe Liste aller User ab', async () => {
const fakeLoggedInUser = { id: 'admin', admin: true };
const event = {
@@ -52,12 +58,7 @@ describe('API-Endpoint: Users', () => {
});
test('Füge Benutzer hinzu: Erfolgreich', async () => {
// mock params and third party function calls
const fakeLoggedInUser = { id: 'admin', admin: true };
const mockLocals = {
user: fakeLoggedInUser
};
// Mocke Parameter und Funktionen von Drittparteien
const fakeUsersAPIURL = `http://localhost:5173/api/users`;
const fakeUserID = 42;
const fakeUsername = 'admin';
@@ -95,12 +96,7 @@ describe('API-Endpoint: Users', () => {
});
test('Füge Benutzer hinzu: Fehlender Name oder Passwort', async () => {
// mock params and third party function calls
const fakeLoggedInUser = { id: 'admin', admin: true };
const mockLocals = {
user: fakeLoggedInUser
};
// Mocke Parameter und Funktionen von Drittparteien
const fakeUsersAPIURL = `http://localhost:5173/api/users`;
const fakeUserID = 42;
const fakeUsername = '';
@@ -129,12 +125,7 @@ describe('API-Endpoint: Users', () => {
});
test('Füge Benutzer hinzu: Nicht erfolgreich, keine Datenbankänderung', async () => {
// mock params and third party function calls
const fakeLoggedInUser = { id: 'admin', admin: true };
const mockLocals = {
user: fakeLoggedInUser
};
// Mocke Parameter und Funktionen von Drittparteien
const fakeUsersAPIURL = `http://localhost:5173/api/users`;
const fakeUserID = 42;
const fakeUsername = 'admin';