refactoring: extract common locals.user definition and translatation of comments
This commit is contained in:
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user