Testing the database
Tests der Datenbank hinzugefügt. Alle sind erfolgreich durchgelaufen.
This commit is contained in:
1 parent
38c3139403
commit
67888e7f33
1 file changed
+30
-14
+30
-14
@@ -1,12 +1,14 @@
|
||||
import { prisma } from "@/lib/db/prisma"
|
||||
import argon2 from 'argon2'
|
||||
|
||||
// If you want to implement user, just uncomment this.
|
||||
// import argon2 from 'argon2'
|
||||
|
||||
|
||||
// TEST
|
||||
import { getSongs, getSongById, searchSongsByTitle, createSong, updateSong, deleteSong } from "@/lib/db/song";
|
||||
import { getSongBooks, getSongBookById, searchSongBooksByTitle, createSongBook, updateSongBook, deleteSongBook } from "@/lib/db/songbook";
|
||||
import { addSongToBook, updateSongInBook, removeSongFromBook, getSongByNumber, isSongNumberTaken } from "@/lib/db/songbooksongs";
|
||||
import { getUsers, getUserById, getUserByUsername, createUser, updateUser, deleteUser } from "@/lib/db/user";
|
||||
// import { getSongs, getSongById, searchSongsByTitle, createSong, updateSong, deleteSong } from "@/lib/db/song";
|
||||
// import { getSongBooks, getSongBookById, searchSongBooksByTitle, createSongBook, updateSongBook, deleteSongBook } from "@/lib/db/songbook";
|
||||
// import { addSongToBook, updateSongInBook, removeSongFromBook, getSongByNumber, isSongNumberTaken } from "@/lib/db/songbooksongs";
|
||||
// import { getUsers, getUserById, getUserByUsername, createUser, updateUser, deleteUser } from "@/lib/db/user";
|
||||
// TEST
|
||||
|
||||
|
||||
@@ -14,8 +16,17 @@ import { getUsers, getUserById, getUserByUsername, createUser, updateUser, delet
|
||||
|
||||
|
||||
export async function initDB() {
|
||||
const count = await prisma.user.count()
|
||||
|
||||
// TEST if Database works
|
||||
const count = await prisma.user.count()
|
||||
console.log("Database OK");
|
||||
|
||||
// TEST
|
||||
// runTests();
|
||||
|
||||
// No need for users, in future maybe?
|
||||
//
|
||||
//
|
||||
// if (count === 0) {
|
||||
// await prisma.user.create({
|
||||
// data: {
|
||||
@@ -28,8 +39,6 @@ export async function initDB() {
|
||||
// console.log('Created admin user')
|
||||
// }
|
||||
|
||||
// TEST
|
||||
runTests();
|
||||
|
||||
}
|
||||
|
||||
@@ -54,7 +63,7 @@ async function runTests() {
|
||||
}
|
||||
|
||||
const user2 = await createUser({ username: "UserUser", password: "Admin" });
|
||||
if (user2.success) { // Korrigiert: user2 statt user1
|
||||
if (user2.success) {
|
||||
console.log("✅ [PASSED] create user 2");
|
||||
} else {
|
||||
console.log("❌ [FAILED] create user 2", user2);
|
||||
@@ -81,6 +90,9 @@ async function runTests() {
|
||||
const deletedUser = await deleteUser(1);
|
||||
console.log(deletedUser.success ? "✅ [PASSED] deleteUser" : "❌ [FAILED] deleteUser", deletedUser);
|
||||
|
||||
const deletedUser2 = await deleteUser(2);
|
||||
console.log(deletedUser2.success ? "✅ [PASSED] deleteUser" : "❌ [FAILED] deleteUser", deletedUser2);
|
||||
|
||||
|
||||
// ==========================================
|
||||
// TEST: SONGBOOKS
|
||||
@@ -104,12 +116,12 @@ async function runTests() {
|
||||
console.log(sbById.success ? "✅ [PASSED] getSongBookById" : "❌ [FAILED] getSongBookById", sbById);
|
||||
|
||||
const sbSearch = await searchSongBooksByTitle("GesangBuch");
|
||||
console.log(sbSearch.success ? "✅ [PASSED] searchSongBooksByTitle" : "❌ [FAILED] searchSongBooksByTitle", sbSearch);
|
||||
console.log(sbSearch.success && sbSearch.songBooks?.length === 2 ? "✅ [PASSED] searchSongBooksByTitle" : "❌ [FAILED] searchSongBooksByTitle", sbSearch);
|
||||
|
||||
const sbUpdate = await updateSongBook(1, { title: "Liederbuch", language: "Deutsch" });
|
||||
console.log(sbUpdate.success ? "✅ [PASSED] updateSongBook" : "❌ [FAILED] updateSongBook", sbUpdate);
|
||||
|
||||
const sbDel = await deleteSongBook(1);
|
||||
const sbDel = await deleteSongBook(2);
|
||||
console.log(sbDel.success ? "✅ [PASSED] deleteSongBook" : "❌ [FAILED] deleteSongBook", sbDel);
|
||||
|
||||
|
||||
@@ -135,12 +147,13 @@ async function runTests() {
|
||||
console.log(songById.success ? "✅ [PASSED] getSongById" : "❌ [FAILED] getSongById", songById);
|
||||
|
||||
const songSearch = await searchSongsByTitle("liEd");
|
||||
console.log(songSearch.success ? "✅ [PASSED] searchSongsByTitle" : "❌ [FAILED] searchSongsByTitle", songSearch);
|
||||
console.log(songSearch.success && songSearch.songs?.length === 1 ? "✅ [PASSED] searchSongsByTitle" : "❌ [FAILED] searchSongsByTitle", songSearch);
|
||||
|
||||
const songUpdate = await updateSong(1, { title: "Lied der Lieder" });
|
||||
console.log(songUpdate.success ? "✅ [PASSED] updateSong" : "❌ [FAILED] updateSong", songUpdate);
|
||||
|
||||
const songDel = await deleteSong(1);
|
||||
await createSong({ title: "3 Lied" });
|
||||
const songDel = await deleteSong(3);
|
||||
console.log(songDel.success ? "✅ [PASSED] deleteSong" : "❌ [FAILED] deleteSong", songDel);
|
||||
|
||||
|
||||
@@ -155,7 +168,10 @@ async function runTests() {
|
||||
const addSong1_dupl = await addSongToBook(1, 1, 1);
|
||||
console.log(!addSong1_dupl.success ? "✅ [PASSED] prevent duplicate song in book" : "❌ [FAILED] prevent duplicate song in book", addSong1_dupl);
|
||||
|
||||
const addSong2 = await addSongToBook(1, 2, 2);
|
||||
const addSong1_dupl2 = await addSongToBook(2, 1, 1);
|
||||
console.log(!addSong1_dupl2.success ? "✅ [PASSED] prevent duplicate songnumber in book" : "❌ [FAILED] prevent duplicate songnumber in book", addSong1_dupl2);
|
||||
|
||||
const addSong2 = await addSongToBook(2, 1, 2);
|
||||
console.log(addSong2.success ? "✅ [PASSED] addSongToBook 2" : "❌ [FAILED] addSongToBook 2", addSong2);
|
||||
|
||||
const songByNum = await getSongByNumber(1, 2);
|
||||
|
||||
Reference in new issue
Block a user