From fdbe4f4b1bdc88b72faeec1aa1d34132d090e93c Mon Sep 17 00:00:00 2001 From: Johannes Horn Date: Fri, 6 Nov 2026 10:00:05 +0100 Subject: [PATCH 1/7] test: set up API tests with their own test database --- .gitignore | 1 + backend/package.json | 4 +- backend/pnpm-lock.yaml | 595 ++++++++++++++++++++++++++++++++++- backend/tests/fixtures.ts | 120 +++++++ backend/tests/globalSetup.ts | 93 ++++++ backend/tests/server.ts | 37 +++ backend/tests/setup.ts | 7 + backend/vitest.config.ts | 22 ++ 8 files changed, 876 insertions(+), 3 deletions(-) create mode 100644 backend/tests/fixtures.ts create mode 100644 backend/tests/globalSetup.ts create mode 100644 backend/tests/server.ts create mode 100644 backend/tests/setup.ts create mode 100644 backend/vitest.config.ts diff --git a/.gitignore b/.gitignore index 3bf0c560..8a76ca79 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ dist-ssr build/ db-data/ +test-db-data/ book-data.csv diff --git a/backend/package.json b/backend/package.json index 7a1ccd6d..f453f53b 100644 --- a/backend/package.json +++ b/backend/package.json @@ -12,6 +12,7 @@ "scripts": { "prestart": "graphql-codegen", "typecheck": "tsc", + "test": "vitest run", "dev": "pnpm prestart && tsx src/index.ts", "build": "esbuild src/index.ts --bundle --platform=node --format=esm --target=node24 --packages=external --outfile=dist/index.js", "start": "pnpm build && node dist/index.js", @@ -66,6 +67,7 @@ "esbuild": "0.28.2", "prettier": "3.9.9", "tsx": "^4.23.15", - "typescript": "^7.0.2" + "typescript": "^7.0.2", + "vitest": "^5.1.0" } } diff --git a/backend/pnpm-lock.yaml b/backend/pnpm-lock.yaml index b31e0134..a419962c 100644 --- a/backend/pnpm-lock.yaml +++ b/backend/pnpm-lock.yaml @@ -180,7 +180,7 @@ importers: version: 9.2.8(graphql@17.0.2) better-auth: specifier: ^1.7.12 - version: 1.7.12(drizzle-kit@1.0.0-rc.4)(drizzle-orm@1.0.0-rc.4(@types/pg@8.23.1)(pg@8.23.1)(zod@4.6.7))(pg@8.23.1) + version: 1.7.12(drizzle-kit@1.0.0-rc.4)(drizzle-orm@1.0.0-rc.4(@types/pg@8.23.1)(pg@8.23.1)(zod@4.6.7))(pg@8.23.1)(vitest@5.1.0(@types/node@26.6.5)(vite@8.3.6(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.15)(yaml@2.9.1))) cors: specifier: ^2.8.6 version: 2.8.6 @@ -239,6 +239,9 @@ importers: typescript: specifier: ^7.0.2 version: 7.0.2 + vitest: + specifier: ^5.1.0 + version: 5.1.0(@types/node@26.6.5)(vite@8.3.6(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.15)(yaml@2.9.1)) packages: @@ -1247,6 +1250,9 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} + '@oxc-project/types@0.156.0': + resolution: {integrity: sha512-1Duyg48TdJNdyhEB8Xn1L36bT9Pv6GUtlKjHxOys8xkaF/rQq3XJE+bAurSK/AgIz5mGFsb77cn9Pb20+WCScw==} + '@protobufjs/aspromise@1.1.2': resolution: {integrity: sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==} @@ -1280,6 +1286,105 @@ packages: '@repeaterjs/repeater@3.1.0': resolution: {integrity: sha512-TaoVksZRSx2KWYYpyLQtMQXXeS98VsgZImzW65xmiVgbYhXLk+aEsmzPLirqVuE4/XuUapH2iMtxUzaBNDzdSQ==} + '@rolldown/binding-android-arm-eabi@1.2.16': + resolution: {integrity: sha512-ia3DwAs0OsMGS7+IConptSiyk9pEXkOx/AbJ2n/lAGxH3QkWQus1t8d7gnAT38FCU2sQu8lUbeR6AiZFv4JxaA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm] + os: [android] + + '@rolldown/binding-android-arm64@1.2.16': + resolution: {integrity: sha512-kx5wBiMB6E7TEvpl2B9gjLU004BkvEm2Dr941BFjx/SontPwSzNuQUIoVKxHHoSjpFIfHMmcguyLOtyn0hObRg==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [android] + + '@rolldown/binding-darwin-arm64@1.2.16': + resolution: {integrity: sha512-qslZrXnKJU4cUpjoAmtAo/KQM9e2IRMlmpig6Zpwj+8KWxW8v+nkAf9216Bsek9lOC1jvg2yCjygCFo2f83msQ==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [darwin] + + '@rolldown/binding-darwin-x64@1.2.16': + resolution: {integrity: sha512-FdF+y48ND13eAyM2mQn+85kvAqNlvRWROy2rhgA463X/0Gv4vGtazZtfaF1mRBLscYvtOlh4QnLjOWiFzX69OQ==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [darwin] + + '@rolldown/binding-freebsd-x64@1.2.16': + resolution: {integrity: sha512-ddjqFM5e95AgLbUPtKIS7V1KTVlA0RUgCVr5mn+/IEhsdy3pr+Vuj/HZ7nlMN2FyxIwUktOH1LEPIQXO1v9y1Q==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [freebsd] + + '@rolldown/binding-linux-arm-gnueabihf@1.2.16': + resolution: {integrity: sha512-tHdKWbFkFBI687iim3LIyIvyL7j66VvQYkDPss5Stn/qyE2tWkR1YD0dXmXPFKKqT/o5ZEJVsaRsWS2meQwGOA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm] + os: [linux] + + '@rolldown/binding-linux-arm64-gnu@1.2.16': + resolution: {integrity: sha512-FJiLGAblPBMlBEdbOqw6kW6QcXDWAf/oJu7gYs9ZJZwmg+K+/zjFLxPTIY9izJUzxzc24FHvmseyA0IvJSl17w==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [linux] + libc: [glibc] + + '@rolldown/binding-linux-arm64-musl@1.2.16': + resolution: {integrity: sha512-hrJpblMsrQ58U9veWpbXzkhV5zStunds6HWLprqq1qauvgBr1E6P+24kLj6lSLI9vjRn/RYpjprhkHQPKGWpNg==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [linux] + libc: [musl] + + '@rolldown/binding-linux-ppc64-gnu@1.2.16': + resolution: {integrity: sha512-qJd/dC6j6CwLG9/s/RP2nb1RZ0GIgj7Ioj7x/SYa3RzjVrlzrmH0fhIOpfvqQDeIsdP0loi+kHaMhJzY1PBIaA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [ppc64] + os: [linux] + libc: [glibc] + + '@rolldown/binding-linux-s390x-gnu@1.2.16': + resolution: {integrity: sha512-Vx7Xg5uUJuNcujJjI70OICaH0EYj80BtOLZTSN7uOYg8QOLlyKnaG0IW7Fn/J0IpJsaKzmDKMhOQv1JBM9m9vg==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [s390x] + os: [linux] + libc: [glibc] + + '@rolldown/binding-linux-x64-gnu@1.2.16': + resolution: {integrity: sha512-TNKhgE3uJTsTzatUSSYt0Kgo+Oa2uSlSjz4r1aEIea7HX6ULBym4fAlYUhG1i6pjNf2njfCUAfKwr6C3E9Xg1w==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [linux] + libc: [glibc] + + '@rolldown/binding-linux-x64-musl@1.2.16': + resolution: {integrity: sha512-7chXdpjXZ8qG0+mIxECN3cT9kvhZ3/oZhMX6Pp876P7CDrIy8nJswva6Mq357JR7eYXfuskwZxMeV1SzoZdHrA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [linux] + libc: [musl] + + '@rolldown/binding-openharmony-arm64@1.2.16': + resolution: {integrity: sha512-Kwjt+7uNTJK5/MDkGWGVO2KQPnj8yAV75dMpfwyHZrJSXWHrniOB0aUEWlVYf3H1hOqFLIStLdM5QXq6bnKmOQ==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [openharmony] + + '@rolldown/binding-win32-arm64-msvc@1.2.16': + resolution: {integrity: sha512-/LH6WfjDRXXJz/p5xl4TmU+jpcnwcxbKEQBW/GZE0JHfN0lGIyTtsUEGaQ/q/GikkGJ2yLKe6pwm7AnEWO8pdw==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [win32] + + '@rolldown/binding-win32-x64-msvc@1.2.16': + resolution: {integrity: sha512-1lv1KvX0Z871zfk7vw+dnXMMnHNyDwMzWG8Kv3HxDXMOhzCX4SHc7HK319fInP0i+0p9D8brkfzL7pJOaGl+tw==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [win32] + + '@rolldown/pluginutils@1.0.1': + resolution: {integrity: sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw==} + '@standard-schema/spec@1.1.0': resolution: {integrity: sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==} @@ -1289,12 +1394,21 @@ packages: '@types/body-parser@1.19.6': resolution: {integrity: sha512-HLFeCYgz89uk22N5Qg3dvGvsv46B8GLvKKo1zKG4NybA8U2DiEO3w9lqGg29t/tfLRJpJ6iQxnVw4OnB7MoM9g==} + '@types/chai@5.2.3': + resolution: {integrity: sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==} + '@types/connect@3.4.38': resolution: {integrity: sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==} '@types/cors@2.8.19': resolution: {integrity: sha512-mFNylyeyqN93lfe/9CSxOGREz8cpzAhH+E93xJ4xWQf62V8sQ/24reV2nyzUWM6H6Xji+GGHpkbLe7pVoUEskg==} + '@types/deep-eql@4.0.2': + resolution: {integrity: sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==} + + '@types/estree@1.0.10': + resolution: {integrity: sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g==} + '@types/express-serve-static-core@5.1.3': resolution: {integrity: sha512-dPfW8NFiOF4wOHc7+N/QSxlY9cfSsenewGbAz8C8U/MULPd/YZ27LvJUIlzaXie7e6Ove9YunJGgC9tbHD2cKw==} @@ -1448,6 +1562,20 @@ packages: cpu: [x64] os: [win32] + '@vitest/mocker@5.1.0': + resolution: {integrity: sha512-5umB9/jlWcqVS6fsrFmv5Gdnpu6wAUio/lEOwAmvB7v+lFo/IW2B9FhAD0p19GCULTgMzLCdUmuCDCnAzWgppQ==} + peerDependencies: + msw: ^2.4.9 || ^3.0.0 + vite: ^6.0.0 || ^7.0.0 || ^8.0.0 + peerDependenciesMeta: + msw: + optional: true + vite: + optional: true + + '@vitest/spy@5.1.0': + resolution: {integrity: sha512-2DPO5OMHWKrBngC+fCmTQqemNF0gidRhp3lxbBmRhW+M1XJrfgPpqNqWVevXtn2f2ufD5ZaR1B6B641aAlcX5A==} + '@whatwg-node/disposablestack@0.0.6': resolution: {integrity: sha512-LOtTn+JgJvX8WfBVJtF08TGrdjuFzGJc4mkP8EdDI8ADbvO7kiexYep1o8dwnt0okb0jYclCDXF13xU7Ge4zSw==} engines: {node: '>=18.0.0'} @@ -1503,6 +1631,10 @@ packages: resolution: {integrity: sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==} engines: {node: '>=8'} + assertion-error@2.0.1: + resolution: {integrity: sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==} + engines: {node: '>=12'} + async-retry@1.3.3: resolution: {integrity: sha512-wfr/jstw9xNi/0teMHrRW7dsz3Lt5ARhYNZ2ewpadnhaIp5mbALhOAP+EAdsC7t4Z6wqsDVv9+W6gm1Dk9mEyw==} @@ -1636,6 +1768,10 @@ packages: caniuse-lite@1.0.30001819: resolution: {integrity: sha512-LFUqIIAwpzsIuevnKnsR9qnStBcgzPShTX61lBwN9uFkkf8o8zLiebEjbW8AYtZiF+1YKDWfdt/pWDtMuG8Xwg==} + chai@6.3.0: + resolution: {integrity: sha512-XWAtwJ6OHO+tj0EKCs0Y2UamnyOxseZWltU4x2U2wh8g4AigdjwvtUjvLP2tqkA/avxHEtzxNaqGq/YGNwckKg==} + engines: {node: '>=18'} + chalk@5.6.2: resolution: {integrity: sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==} engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} @@ -1763,6 +1899,10 @@ packages: resolution: {integrity: sha512-y+8xyqdGLL+6sh0tVeHcfP/QDd8gUgbasolJJpY7NgeQGSZ739bDtSiaiDgtoicy+mtYB81dKLxO9xRhCyIB3A==} engines: {node: '>=12.20'} + detect-libc@2.1.2: + resolution: {integrity: sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==} + engines: {node: '>=8'} + dir-glob@3.0.1: resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} engines: {node: '>=8'} @@ -1958,6 +2098,9 @@ packages: resolution: {integrity: sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==} engines: {node: '>= 0.4'} + es-module-lexer@2.3.2: + resolution: {integrity: sha512-poHGpORABojJJucnV9KbOavETW8lBVnphkW77ER5/BQ5Fz7oXSoCNek7IH3vR5nRjdsEz926ibFYX8KtLQmdyw==} + es-object-atoms@1.1.2: resolution: {integrity: sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==} engines: {node: '>= 0.4'} @@ -1979,6 +2122,9 @@ packages: escape-html@1.0.3: resolution: {integrity: sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==} + estree-walker@3.0.3: + resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==} + etag@1.8.1: resolution: {integrity: sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==} engines: {node: '>= 0.6'} @@ -1986,6 +2132,10 @@ packages: eventemitter3@5.0.4: resolution: {integrity: sha512-mlsTRyGaPBjPedk6Bvw+aqbsXDtoAyAzm5MO7JgU+yVRyMQ5O8bD4Kcci7BS85f93veegeCPkL8R4GLClnjLFw==} + expect-type@1.4.0: + resolution: {integrity: sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA==} + engines: {node: '>=12.0.0'} + express@5.3.0: resolution: {integrity: sha512-qCqy1xSoaugxOD4IVHb1ZWdkvCF2W3aE2okKouWj8VwJ+ztskSiXoBnCSJqfKT+cVPJhuJqe9YLbY425+Zh00g==} engines: {node: '>= 18'} @@ -2006,6 +2156,15 @@ packages: fastq@1.20.3: resolution: {integrity: sha512-XKv5nnLs6nLF71NgiKJLIZFLkPyIEuOselLG7ujZnGrRfQK8HpvY+WqKhAJUAdLomwVHErVS4LfxFlPq0/FTAw==} + fdir@6.5.0: + resolution: {integrity: sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==} + engines: {node: '>=12.0.0'} + peerDependencies: + picomatch: ^3 || ^4 + peerDependenciesMeta: + picomatch: + optional: true + fetch-blob@3.2.0: resolution: {integrity: sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==} engines: {node: ^12.20 || >= 14.13} @@ -2262,6 +2421,80 @@ packages: resolution: {integrity: sha512-fmIq+7kv4WbFm2tcfznRzikqB4cuNpgZ40PSU2fAJ2/OO5XhojqnTPrmgrCjYSRJVwBln03XcRXJGnw9H099IQ==} engines: {node: '>=22.0.0'} + lightningcss-android-arm64@1.33.0: + resolution: {integrity: sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [android] + + lightningcss-darwin-arm64@1.33.0: + resolution: {integrity: sha512-Sciaz8eenNTKn9b3t7+xr0ipTp9YxKQY4npwQ3mrRuL0BAVHBLyZxofhaKBAVtzmtRZ/zTyo0/to4B1uWG/Djg==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [darwin] + + lightningcss-darwin-x64@1.33.0: + resolution: {integrity: sha512-Z5UPAxzrjlWNNyGy6i65cJzzvgJ5D3T6wMvs+gWpY9d7qRhANrxqAp6LhxIgZhWEw18RfJTGcRxjuLIBr+m8XQ==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [darwin] + + lightningcss-freebsd-x64@1.33.0: + resolution: {integrity: sha512-QQM/Ti/hQajJwCY+RiWuCZ9sdtI/XQk7nDK5vC8kkdwixezOlDgvDx7+RT+QjK6FcFT4MpsuoBnHIo/O3StRRg==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [freebsd] + + lightningcss-linux-arm-gnueabihf@1.33.0: + resolution: {integrity: sha512-N7FVBe6iS24MlM6R/4RBTxGhQheZGs7tiQ9U32UtF75NzP5Q7xWPRqLBCKxlRQRk3rY1jCIPLzx7WzOhuUIRLQ==} + engines: {node: '>= 12.0.0'} + cpu: [arm] + os: [linux] + + lightningcss-linux-arm64-gnu@1.33.0: + resolution: {integrity: sha512-j2v/itmy4HlNxlc6voKXYgBqNi0Ng2LShg4z7GufpEgs05P+2suBVyi9I6YHq5uoVFx9ETin3eCEhLVyXGQnKg==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [linux] + libc: [glibc] + + lightningcss-linux-arm64-musl@1.33.0: + resolution: {integrity: sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [linux] + libc: [musl] + + lightningcss-linux-x64-gnu@1.33.0: + resolution: {integrity: sha512-ar+Ju7LmcN0Jo4FpL4hpFybwNG9/3A/Br5KW2n2jyODg3MEZXaDYADdemoNS+BDNfMgKvylJLj4S5tyRActuAg==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [linux] + libc: [glibc] + + lightningcss-linux-x64-musl@1.33.0: + resolution: {integrity: sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [linux] + libc: [musl] + + lightningcss-win32-arm64-msvc@1.33.0: + resolution: {integrity: sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [win32] + + lightningcss-win32-x64-msvc@1.33.0: + resolution: {integrity: sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [win32] + + lightningcss@1.33.0: + resolution: {integrity: sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==} + engines: {node: '>= 12.0.0'} + lines-and-columns@1.2.4: resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==} @@ -2298,6 +2531,9 @@ packages: lru-cache@5.1.1: resolution: {integrity: sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==} + magic-string@1.4.5: + resolution: {integrity: sha512-oLLC2+YvQUfAa+vxoufE/yc1icb87M9iXIRqAoR/2EhE/8cb3SF/+Gi0c2By1B+5Vz2e2vQtUvHiu1+63Znh+w==} + map-cache@0.2.2: resolution: {integrity: sha512-8y/eV9QQZCiyn1SprXSrCmqJN0yNRATe+PO8ztwqrvrbdRLA3eYJF0yaR0YayLWkMbsQSKWS9N2gPcGEc4UsZg==} engines: {node: '>=0.10.0'} @@ -2363,6 +2599,11 @@ packages: resolution: {integrity: sha512-dkEJPVvun4FryqBmZ5KhDo0K9iDXAwn08tMLDinNdRBNPcYEDiWYysLcc6k3mjTMlbP9KyylvRpd4wFtwrT9rw==} engines: {node: ^20.17.0 || >=22.9.0} + nanoid@3.3.20: + resolution: {integrity: sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==} + engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} + hasBin: true + nanostores@1.5.5: resolution: {integrity: sha512-FixtE239Gl6Gz0ZGCK0WzvNwObNCIwVT+L7zQcf1QgcA6AzBxblzqe9OT88qiucNkhsjSOqiogSaF5jVbJiqSA==} engines: {node: ^20.0.0 || >=22.0.0} @@ -2396,6 +2637,10 @@ packages: resolution: {integrity: sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==} engines: {node: '>= 0.4'} + obug@3.0.0: + resolution: {integrity: sha512-5vvB5+W7ePv+p3uqxi+RcW1XAzLW0/hxt3/4X4Lc4qHudzOhmBiBwOY6DRob4WnanAEGvNcLjF+KNOufrUoEQw==} + engines: {node: '>=12.20.0'} + on-finished@2.4.2: resolution: {integrity: sha512-ATWUv387i+nLD49EiDoOft5scf32Vsdz3ktrQJG9bi7jRFmaXTssvyvj1EmeKVVgvesbqUtvQQvaS2TpTukAZQ==} engines: {node: '>= 0.8'} @@ -2486,10 +2731,18 @@ packages: resolution: {integrity: sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==} engines: {node: '>=8.6'} + picomatch@4.0.7: + resolution: {integrity: sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==} + engines: {node: '>=12'} + possible-typed-array-names@1.1.0: resolution: {integrity: sha512-/+5VFTchJDoVj3bhoqi6UeymcD00DAwb1nJwamzPvHEszJ4FpF6SNNbUbOS8yI56qHzdV8eK0qEfOSiodkTdxg==} engines: {node: '>= 0.4'} + postcss@8.5.32: + resolution: {integrity: sha512-LJlKCCAUFKOuZxipUdYw1NzIITEsPcgyOG9LkvRJvuKj/bRzbuRY0ARXvL0pWGpsZvn8jku+LMep2eU0seHp8g==} + engines: {node: ^10 || ^12 || >=14} + postgres-array@2.0.0: resolution: {integrity: sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==} engines: {node: '>=4'} @@ -2565,6 +2818,11 @@ packages: rfdc@1.4.1: resolution: {integrity: sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==} + rolldown@1.2.16: + resolution: {integrity: sha512-bWvlMpFKiTfDKfnK7FC2MPgPeWCf/Kpwsq49ApdW+FQaBZb6O6dZ4MAPbPUjp7hYQrw/RobqCzn64BRrQecGHw==} + engines: {node: ^20.19.0 || >=22.12.0} + hasBin: true + rou3@0.9.2: resolution: {integrity: sha512-3SOzvaAg8rkHrXtRjpCvCvbyO5to9oOO27Z/XqHEYXfMRVSw/qMIVdmaOk9W2lcRLtR6dlqTjo9hDeJk70QBYQ==} @@ -2644,6 +2902,10 @@ packages: resolution: {integrity: sha512-stxByr12oeeOyY2BlviTNQlYV5xOj47GirPr4yA1hE9JCtxfQN0+tVbkxwCtYDQWhEKWFHsEK48ORg5jrouCAg==} engines: {node: '>=20'} + source-map-js@1.2.2: + resolution: {integrity: sha512-KGj/8Y43x35aZVDtt+J4mK1hoLGHULMYfSkODJNQjNDC3oW1PqPoxMwo0pLUsWM/UEGzON/NxeHywEfNXNP3Vw==} + engines: {node: '>=0.10.0'} + split2@4.2.0: resolution: {integrity: sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==} engines: {node: '>= 10.x'} @@ -2655,6 +2917,9 @@ packages: resolution: {integrity: sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==} engines: {node: '>= 0.8'} + std-env@4.3.0: + resolution: {integrity: sha512-OtU/EgQ1kIm5KwqQpBC6ZEMXrZRui11w8zgfTWp8cdO9B8OaPsbA8bTHO2P+HNo1VlUTGMVBwPhydu6poeXiag==} + string-env-interpolation@1.0.1: resolution: {integrity: sha512-78lwMoCcn0nNu8LszbP1UA7g55OeE4v7rCeWnM5B453rnNr4aq+5it3FEYtZrSEiMvHZOZ9Jlqb0OD0M2VInqg==} @@ -2681,6 +2946,18 @@ packages: resolution: {integrity: sha512-YBGpG4bWsHoPvofT6y/5iqulfXIiIErl5B0LdtHT1mGXDFTAhhRrbUpTvBgYbovr+3cKblya2WAOcpoy90XguA==} engines: {node: '>=16'} + tinybench@6.2.3: + resolution: {integrity: sha512-Al01C2JIBnO2CXCAPbpAl6sUiOZHeThGtHYNTa51JRw9PyWOCdr+9Ong05R4qg/Sk3+H645E8ov1h2c58ityNw==} + engines: {node: '>=20.0.0'} + + tinyexec@1.3.1: + resolution: {integrity: sha512-GCvB3aoys96IuDFBMcTB46JOR6mdMtAToqwiW8JlWhsoh1mhHi/xn9ss/Dg7N555GiJyEt2qzoG/NHCwM6h1EA==} + engines: {node: '>=18'} + + tinyglobby@0.2.17: + resolution: {integrity: sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==} + engines: {node: '>=12.0.0'} + title-case@3.0.3: resolution: {integrity: sha512-e1zGYRvbffpcHIrnuqT0Dh+gEJtDaxDSoG4JAIpq4oDFyooziLBIiYQv0GBT4FUAnUop5uZ1hiIAj7oAF6sOCA==} @@ -2752,6 +3029,90 @@ packages: resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==} engines: {node: '>= 0.8'} + vite@8.3.6: + resolution: {integrity: sha512-UI7dK29NnS54Fk+mmo7o+jI6U8Fp7hDl+X5Q1k45WH+d4dSlbLVUETGQ+hfkNgvLQGyoElPj837nZyv4MBc0VA==} + engines: {node: ^20.19.0 || >=22.12.0} + hasBin: true + peerDependencies: + '@types/node': ^20.19.0 || >=22.12.0 + '@vitejs/devtools': ^0.7.1 || ^0.8.0 + esbuild: ^0.27.0 || ^0.28.0 + jiti: '>=1.21.0' + less: ^4.0.0 + sass: ^1.70.0 + sass-embedded: ^1.70.0 + stylus: '>=0.54.8' + sugarss: ^5.0.0 + terser: ^5.16.0 + tsx: ^4.8.1 + yaml: ^2.4.2 + peerDependenciesMeta: + '@types/node': + optional: true + '@vitejs/devtools': + optional: true + esbuild: + optional: true + jiti: + optional: true + less: + optional: true + sass: + optional: true + sass-embedded: + optional: true + stylus: + optional: true + sugarss: + optional: true + terser: + optional: true + tsx: + optional: true + yaml: + optional: true + + vitest@5.1.0: + resolution: {integrity: sha512-MzmNFnrwa8v8lF1bLxw3UJ4EREwVOVb75VqJZmUDRjJ6EluK/x9th7qTbaeDk41WxE1GxWqmTXcdsfobfH5sOA==} + engines: {node: ^22.12.0 || ^24.0.0 || >=26.0.0} + hasBin: true + peerDependencies: + '@edge-runtime/vm': '*' + '@opentelemetry/api': ^1.9.0 + '@types/node': ^22.0.0 || >=24.0.0 + '@vitest/browser-playwright': 5.1.0 + '@vitest/browser-preview': 5.1.0 + '@vitest/browser-webdriverio': ^5.0.0-beta.5 || >=5.0.0 + '@vitest/coverage-istanbul': 5.1.0 + '@vitest/coverage-v8': 5.1.0 + '@vitest/ui': 5.1.0 + happy-dom: '*' + jsdom: '*' + vite: ^6.4.0 || ^7.0.0 || ^8.0.0 + peerDependenciesMeta: + '@edge-runtime/vm': + optional: true + '@opentelemetry/api': + optional: true + '@types/node': + optional: true + '@vitest/browser-playwright': + optional: true + '@vitest/browser-preview': + optional: true + '@vitest/browser-webdriverio': + optional: true + '@vitest/coverage-istanbul': + optional: true + '@vitest/coverage-v8': + optional: true + '@vitest/ui': + optional: true + happy-dom: + optional: true + jsdom: + optional: true + web-streams-polyfill@3.3.3: resolution: {integrity: sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==} engines: {node: '>= 8'} @@ -2768,6 +3129,11 @@ packages: resolution: {integrity: sha512-wk4Mf4pR5mRP7eYuuTBCIQ9d0ud2Fv2jRLQpfgnRjbOxAFHmjKFValgTpitVKzJJS8ajnYQV2Du1SZ8j6b/EUQ==} engines: {node: '>= 0.4'} + why-is-node-running@3.2.1: + resolution: {integrity: sha512-Tb2FUhB4vUsGQlfSquQLYkApkuPAFQXGFzxWKHHumVz2dK+X1RUm/HnID4+TfIGYJ1kTcwOaCk/buYCEJr6YjQ==} + engines: {node: '>=20.11'} + hasBin: true + wrap-ansi@10.0.2: resolution: {integrity: sha512-6OLRNZqRntVGBm26ghZ5eZhCuWWyOkRCSn8XsOIuq5stpCE/tjLbdozd93naILZig0lmD8ANfRwnhn0DLeXGlg==} engines: {node: '>=20'} @@ -3870,6 +4236,8 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.20.3 + '@oxc-project/types@0.156.0': {} + '@protobufjs/aspromise@1.1.2': {} '@protobufjs/base64@1.1.2': {} @@ -3894,6 +4262,53 @@ snapshots: '@repeaterjs/repeater@3.1.0': {} + '@rolldown/binding-android-arm-eabi@1.2.16': + optional: true + + '@rolldown/binding-android-arm64@1.2.16': + optional: true + + '@rolldown/binding-darwin-arm64@1.2.16': + optional: true + + '@rolldown/binding-darwin-x64@1.2.16': + optional: true + + '@rolldown/binding-freebsd-x64@1.2.16': + optional: true + + '@rolldown/binding-linux-arm-gnueabihf@1.2.16': + optional: true + + '@rolldown/binding-linux-arm64-gnu@1.2.16': + optional: true + + '@rolldown/binding-linux-arm64-musl@1.2.16': + optional: true + + '@rolldown/binding-linux-ppc64-gnu@1.2.16': + optional: true + + '@rolldown/binding-linux-s390x-gnu@1.2.16': + optional: true + + '@rolldown/binding-linux-x64-gnu@1.2.16': + optional: true + + '@rolldown/binding-linux-x64-musl@1.2.16': + optional: true + + '@rolldown/binding-openharmony-arm64@1.2.16': + optional: true + + '@rolldown/binding-win32-arm64-msvc@1.2.16': + optional: true + + '@rolldown/binding-win32-x64-msvc@1.2.16': + optional: true + + '@rolldown/pluginutils@1.0.1': {} + '@standard-schema/spec@1.1.0': {} '@ts-morph/common@0.23.0': @@ -3908,6 +4323,11 @@ snapshots: '@types/connect': 3.4.38 '@types/node': 26.6.5 + '@types/chai@5.2.3': + dependencies: + '@types/deep-eql': 4.0.2 + assertion-error: 2.0.1 + '@types/connect@3.4.38': dependencies: '@types/node': 26.6.5 @@ -3916,6 +4336,10 @@ snapshots: dependencies: '@types/node': 26.6.5 + '@types/deep-eql@4.0.2': {} + + '@types/estree@1.0.10': {} + '@types/express-serve-static-core@5.1.3': dependencies: '@types/node': 26.6.5 @@ -4020,6 +4444,17 @@ snapshots: '@typescript/typescript-win32-x64@7.0.2': optional: true + '@vitest/mocker@5.1.0(vite@8.3.6(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.15)(yaml@2.9.1))': + dependencies: + '@jridgewell/trace-mapping': 0.3.31 + '@vitest/spy': 5.1.0 + estree-walker: 3.0.3 + magic-string: 1.4.5 + optionalDependencies: + vite: 8.3.6(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.15)(yaml@2.9.1) + + '@vitest/spy@5.1.0': {} + '@whatwg-node/disposablestack@0.0.6': dependencies: '@whatwg-node/promise-helpers': 1.3.2 @@ -4079,6 +4514,8 @@ snapshots: array-union@2.1.0: {} + assertion-error@2.0.1: {} + async-retry@1.3.3: dependencies: retry: 0.13.1 @@ -4095,7 +4532,7 @@ snapshots: baseline-browser-mapping@2.11.32: {} - better-auth@1.7.12(drizzle-kit@1.0.0-rc.4)(drizzle-orm@1.0.0-rc.4(@types/pg@8.23.1)(pg@8.23.1)(zod@4.6.7))(pg@8.23.1): + better-auth@1.7.12(drizzle-kit@1.0.0-rc.4)(drizzle-orm@1.0.0-rc.4(@types/pg@8.23.1)(pg@8.23.1)(zod@4.6.7))(pg@8.23.1)(vitest@5.1.0(@types/node@26.6.5)(vite@8.3.6(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.15)(yaml@2.9.1))): dependencies: '@better-auth/core': 1.7.12(@better-auth/utils@0.5.0)(@better-fetch/fetch@1.3.2)(better-call@1.4.4(zod@4.6.7))(jose@6.2.13)(kysely@0.29.7)(nanostores@1.5.5) '@better-auth/drizzle-adapter': 1.7.12(@better-auth/core@1.7.12(@better-auth/utils@0.5.0)(@better-fetch/fetch@1.3.2)(better-call@1.4.4(zod@4.6.7))(jose@6.2.13)(kysely@0.29.7)(nanostores@1.5.5))(@better-auth/utils@0.5.0)(drizzle-orm@1.0.0-rc.4(@types/pg@8.23.1)(pg@8.23.1)(zod@4.6.7)) @@ -4118,6 +4555,7 @@ snapshots: drizzle-kit: 1.0.0-rc.4 drizzle-orm: 1.0.0-rc.4(@types/pg@8.23.1)(pg@8.23.1)(zod@4.6.7) pg: 8.23.1 + vitest: 5.1.0(@types/node@26.6.5)(vite@8.3.6(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.15)(yaml@2.9.1)) transitivePeerDependencies: - '@opentelemetry/api' @@ -4187,6 +4625,8 @@ snapshots: caniuse-lite@1.0.30001819: {} + chai@6.3.0: {} + chalk@5.6.2: {} change-case-all@2.1.0: @@ -4286,6 +4726,8 @@ snapshots: detect-indent@7.0.2: {} + detect-libc@2.1.2: {} + dir-glob@3.0.1: dependencies: path-type: 4.0.0 @@ -4332,6 +4774,8 @@ snapshots: es-errors@1.3.0: {} + es-module-lexer@2.3.2: {} + es-object-atoms@1.1.2: dependencies: es-errors: 1.3.0 @@ -4398,10 +4842,16 @@ snapshots: escape-html@1.0.3: {} + estree-walker@3.0.3: + dependencies: + '@types/estree': 1.0.10 + etag@1.8.1: {} eventemitter3@5.0.4: {} + expect-type@1.4.0: {} + express@5.3.0: dependencies: accepts: 2.0.0 @@ -4457,6 +4907,10 @@ snapshots: dependencies: reusify: 1.1.0 + fdir@6.5.0(picomatch@4.0.7): + optionalDependencies: + picomatch: 4.0.7 + fetch-blob@3.2.0: dependencies: node-domexception: 1.0.0 @@ -4691,6 +5145,55 @@ snapshots: kysely@0.29.7: {} + lightningcss-android-arm64@1.33.0: + optional: true + + lightningcss-darwin-arm64@1.33.0: + optional: true + + lightningcss-darwin-x64@1.33.0: + optional: true + + lightningcss-freebsd-x64@1.33.0: + optional: true + + lightningcss-linux-arm-gnueabihf@1.33.0: + optional: true + + lightningcss-linux-arm64-gnu@1.33.0: + optional: true + + lightningcss-linux-arm64-musl@1.33.0: + optional: true + + lightningcss-linux-x64-gnu@1.33.0: + optional: true + + lightningcss-linux-x64-musl@1.33.0: + optional: true + + lightningcss-win32-arm64-msvc@1.33.0: + optional: true + + lightningcss-win32-x64-msvc@1.33.0: + optional: true + + lightningcss@1.33.0: + dependencies: + detect-libc: 2.1.2 + optionalDependencies: + lightningcss-android-arm64: 1.33.0 + lightningcss-darwin-arm64: 1.33.0 + lightningcss-darwin-x64: 1.33.0 + lightningcss-freebsd-x64: 1.33.0 + lightningcss-linux-arm-gnueabihf: 1.33.0 + lightningcss-linux-arm64-gnu: 1.33.0 + lightningcss-linux-arm64-musl: 1.33.0 + lightningcss-linux-x64-gnu: 1.33.0 + lightningcss-linux-x64-musl: 1.33.0 + lightningcss-win32-arm64-msvc: 1.33.0 + lightningcss-win32-x64-msvc: 1.33.0 + lines-and-columns@1.2.4: {} listr2@10.2.2: @@ -4730,6 +5233,10 @@ snapshots: dependencies: yallist: 3.1.1 + magic-string@1.4.5: + dependencies: + '@jridgewell/sourcemap-codec': 1.6.0 + map-cache@0.2.2: {} math-intrinsics@1.1.0: {} @@ -4771,6 +5278,8 @@ snapshots: mute-stream@3.0.0: {} + nanoid@3.3.20: {} + nanostores@1.5.5: {} negotiator@1.1.0: @@ -4795,6 +5304,8 @@ snapshots: object-inspect@1.13.4: {} + obug@3.0.0: {} + on-finished@2.4.2: dependencies: ee-first: 1.1.1 @@ -4881,8 +5392,16 @@ snapshots: picomatch@2.3.2: {} + picomatch@4.0.7: {} + possible-typed-array-names@1.1.0: {} + postcss@8.5.32: + dependencies: + nanoid: 3.3.20 + picocolors: 1.1.1 + source-map-js: 1.2.2 + postgres-array@2.0.0: {} postgres-bytea@1.0.1: {} @@ -4939,6 +5458,27 @@ snapshots: rfdc@1.4.1: {} + rolldown@1.2.16: + dependencies: + '@oxc-project/types': 0.156.0 + '@rolldown/pluginutils': 1.0.1 + optionalDependencies: + '@rolldown/binding-android-arm-eabi': 1.2.16 + '@rolldown/binding-android-arm64': 1.2.16 + '@rolldown/binding-darwin-arm64': 1.2.16 + '@rolldown/binding-darwin-x64': 1.2.16 + '@rolldown/binding-freebsd-x64': 1.2.16 + '@rolldown/binding-linux-arm-gnueabihf': 1.2.16 + '@rolldown/binding-linux-arm64-gnu': 1.2.16 + '@rolldown/binding-linux-arm64-musl': 1.2.16 + '@rolldown/binding-linux-ppc64-gnu': 1.2.16 + '@rolldown/binding-linux-s390x-gnu': 1.2.16 + '@rolldown/binding-linux-x64-gnu': 1.2.16 + '@rolldown/binding-linux-x64-musl': 1.2.16 + '@rolldown/binding-openharmony-arm64': 1.2.16 + '@rolldown/binding-win32-arm64-msvc': 1.2.16 + '@rolldown/binding-win32-x64-msvc': 1.2.16 + rou3@0.9.2: {} router@2.2.0: @@ -5049,12 +5589,16 @@ snapshots: ansi-styles: 6.2.3 is-fullwidth-code-point: 5.1.0 + source-map-js@1.2.2: {} + split2@4.2.0: {} sponge-case@2.0.3: {} statuses@2.0.2: {} + std-env@4.3.0: {} + string-env-interpolation@1.0.1: {} string-width@7.2.0: @@ -5082,6 +5626,15 @@ snapshots: timeout-signal@2.0.0: {} + tinybench@6.2.3: {} + + tinyexec@1.3.1: {} + + tinyglobby@0.2.17: + dependencies: + fdir: 6.5.0(picomatch@4.0.7) + picomatch: 4.0.7 + title-case@3.0.3: dependencies: tslib: 2.8.1 @@ -5168,6 +5721,42 @@ snapshots: vary@1.1.2: {} + vite@8.3.6(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.15)(yaml@2.9.1): + dependencies: + lightningcss: 1.33.0 + picomatch: 4.0.7 + postcss: 8.5.32 + rolldown: 1.2.16 + tinyglobby: 0.2.17 + optionalDependencies: + '@types/node': 26.6.5 + esbuild: 0.28.2 + fsevents: 2.3.3 + jiti: 2.7.0 + tsx: 4.23.15 + yaml: 2.9.1 + + vitest@5.1.0(@types/node@26.6.5)(vite@8.3.6(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.15)(yaml@2.9.1)): + dependencies: + '@types/chai': 5.2.3 + '@vitest/mocker': 5.1.0(vite@8.3.6(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.15)(yaml@2.9.1)) + chai: 6.3.0 + es-module-lexer: 2.3.2 + expect-type: 1.4.0 + magic-string: 1.4.5 + obug: 3.0.0 + picomatch: 4.0.7 + std-env: 4.3.0 + tinybench: 6.2.3 + tinyexec: 1.3.1 + tinyglobby: 0.2.17 + vite: 8.3.6(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.15)(yaml@2.9.1) + why-is-node-running: 3.2.1 + optionalDependencies: + '@types/node': 26.6.5 + transitivePeerDependencies: + - msw + web-streams-polyfill@3.3.3: {} whatwg-mimetype@4.0.0: {} @@ -5184,6 +5773,8 @@ snapshots: gopd: 1.2.0 has-tostringtag: 1.0.2 + why-is-node-running@3.2.1: {} + wrap-ansi@10.0.2: dependencies: ansi-styles: 6.2.3 diff --git a/backend/tests/fixtures.ts b/backend/tests/fixtures.ts new file mode 100644 index 00000000..4b250ebe --- /dev/null +++ b/backend/tests/fixtures.ts @@ -0,0 +1,120 @@ +import type { NodePgDatabase } from "drizzle-orm/node-postgres"; +import { bookGenres, books, bookToGenres, user } from "~/db/schema"; + +type BookFixture = Omit & { + genres: string[]; +}; + +// A small, fixed dataset, chosen so the expected results of searching, +// filtering and sorting are easy to work out by hand. The database is created +// from scratch, so the books get the ids 1-7 in this order. +const testBooks: BookFixture[] = [ + { + title: "The Blade Itself", + author: "Joe Abercrombie", + language: "English", + bookFormat: "Paperback", + pages: 515, + rating: 4.2, + numRatings: 1000, + genres: ["Fantasy"], + }, + { + title: "Before They Are Hanged", + author: "Joe Abercrombie", + language: "English", + bookFormat: "Hardcover", + pages: 441, + rating: 4.3, + numRatings: 800, + genres: ["Fantasy"], + }, + { + title: "The Hobbit", + author: "J.R.R. Tolkien", + language: "English", + bookFormat: "Paperback", + pages: 310, + rating: 4.5, + numRatings: 3000, + genres: ["Fantasy", "Classics"], + }, + { + title: "Pride and Prejudice", + author: "Jane Austen", + language: "English", + bookFormat: "Paperback", + pages: 279, + rating: 4.3, + numRatings: 2500, + genres: ["Romance", "Classics"], + }, + { + title: "Dune", + author: "Frank Herbert", + language: "English", + bookFormat: "Hardcover", + pages: 688, + rating: 4.4, + numRatings: 1500, + genres: ["Science Fiction"], + }, + { + title: "Le Petit Prince", + author: "Antoine de Saint-Exupéry", + language: "French", + bookFormat: "Hardcover", + pages: 96, + rating: 4.5, + numRatings: 900, + genres: ["Classics"], + }, + { + title: "An Unrated Book", + author: "Unknown Author", + language: "English", + bookFormat: "Paperback", + pages: 200, + rating: null, + numRatings: null, + genres: ["Fantasy"], + }, +]; + +// Users that the tests log in as. Favorites reference a user, so they must exist. +const testUsers = [ + { id: "user-1", name: "Test User", email: "user1@example.com" }, + { id: "user-2", name: "Other User", email: "user2@example.com" }, +]; + +async function seedTestData(db: NodePgDatabase) { + const insertedBooks = await db + .insert(books) + .values( + testBooks.map(({ genres: _genres, ...book }, i) => ({ + ...book, + isbn: `978000000000${i}`, + })), + ) + .returning({ id: books.id }); + + const genreNames = [...new Set(testBooks.flatMap((book) => book.genres))]; + const insertedGenres = await db + .insert(bookGenres) + .values(genreNames.map((genre) => ({ genre }))) + .returning(); + const genreIds = new Map(insertedGenres.map((g) => [g.genre, g.id])); + + await db.insert(bookToGenres).values( + testBooks.flatMap((book, i) => + book.genres.map((genre) => ({ + bookId: insertedBooks[i].id, + genreId: genreIds.get(genre)!, + })), + ), + ); + + await db.insert(user).values(testUsers); +} + +export { seedTestData, testBooks }; diff --git a/backend/tests/globalSetup.ts b/backend/tests/globalSetup.ts new file mode 100644 index 00000000..8d63d304 --- /dev/null +++ b/backend/tests/globalSetup.ts @@ -0,0 +1,93 @@ +import { spawnSync } from "node:child_process"; +import { existsSync, rmSync } from "node:fs"; +import pg from "pg"; +import { drizzle } from "drizzle-orm/node-postgres"; +import { migrate } from "drizzle-orm/node-postgres/migrator"; +import type { TestProject } from "vitest/node"; +import { seedTestData } from "./fixtures"; + +// The tests run their own Postgres server from this folder, separate from the +// development database in db-data/. It is created for each run and deleted +// afterwards. +const DATA_DIR = "test-db-data"; + +function run(command: string, args: string[]) { + const result = spawnSync(command, args, { + encoding: "utf8", + windowsHide: true, + }); + if (result.error) { + throw new Error( + `Could not run "${command}". Is PostgreSQL installed and on your PATH? See the backend README.`, + { cause: result.error }, + ); + } + if (result.status !== 0) { + throw new Error(`"${command} ${args.join(" ")}" failed:\n${result.stderr}`); + } +} + +// Runs once before all API tests: starts the test Postgres server, creates the +// test database, runs our migrations and inserts the test data. The returned +// function stops the server and deletes its folder after the tests. +export async function setup(project: TestProject) { + // The test database from vitest.config.ts + const databaseUrl = project.config.env.DATABASE_URL as string; + const url = new URL(databaseUrl); + const databaseName = url.pathname.slice(1); + + // This deletes the database, so refuse to touch anything but a test database. + if (!databaseName.endsWith("_test")) { + throw new Error( + `Refusing to reset "${databaseName}": the test database name must end with "_test".`, + ); + } + + if (!existsSync(DATA_DIR)) { + run("initdb", [ + "-D", + DATA_DIR, + "-U", + "postgres", + "-E", + "UTF8", + "--auth=trust", + ]); + } + + // A run that was stopped early may have left the folder and server behind. + const isRunning = + spawnSync("pg_ctl", ["-D", DATA_DIR, "status"], { windowsHide: true }) + .status === 0; + if (!isRunning) { + run("pg_ctl", [ + "-D", + DATA_DIR, + "-l", + `${DATA_DIR}/test-db-data.log`, + "-w", + "-o", + `-p ${url.port} -c listen_addresses=127.0.0.1`, + "start", + ]); + } + + // Drop and create the test database from the default "postgres" database. + const adminUrl = new URL(url); + adminUrl.pathname = "/postgres"; + const admin = new pg.Client({ connectionString: adminUrl.toString() }); + await admin.connect(); + await admin.query(`DROP DATABASE IF EXISTS "${databaseName}" WITH (FORCE)`); + await admin.query(`CREATE DATABASE "${databaseName}"`); + await admin.end(); + + const db = drizzle(databaseUrl); + await migrate(db, { migrationsFolder: "./drizzle" }); + await seedTestData(db); + await db.$client.end(); + + return () => { + run("pg_ctl", ["-D", DATA_DIR, "-w", "stop"]); + rmSync(DATA_DIR, { recursive: true, force: true }); + }; +} diff --git a/backend/tests/server.ts b/backend/tests/server.ts new file mode 100644 index 00000000..14ae3902 --- /dev/null +++ b/backend/tests/server.ts @@ -0,0 +1,37 @@ +import assert from "node:assert"; +import { ApolloServer } from "@apollo/server"; +import type { ApolloContext } from "~/index"; +import { createBookGenresLoader } from "~/schema/loaders"; +import { resolvers } from "~/schema/resolvers.generated"; +import { typeDefs } from "~/schema/typeDefs.generated"; + +// The same schema and resolvers as the real server, without the HTTP layer. +// Queries go through GraphQL and the resolvers to the test database. +const server = new ApolloServer({ typeDefs, resolvers }); + +/** + * Runs a GraphQL operation against the API. Pass `userId` to run it as a + * logged-in user: the resolvers only read the user id from the session. + */ +async function execute>( + query: string, + variables?: Record, + { userId }: { userId?: string } = {}, +) { + const response = await server.executeOperation( + { query, variables }, + { + contextValue: { + session: userId + ? ({ user: { id: userId } } as ApolloContext["session"]) + : null, + loaders: { bookGenres: createBookGenresLoader() }, + }, + }, + ); + + assert(response.body.kind === "single"); + return response.body.singleResult; +} + +export { execute }; diff --git a/backend/tests/setup.ts b/backend/tests/setup.ts new file mode 100644 index 00000000..b9ba03dd --- /dev/null +++ b/backend/tests/setup.ts @@ -0,0 +1,7 @@ +import { afterAll } from "vitest"; +import { db } from "~/db"; + +// Close the database connections after each test file, so Vitest can exit. +afterAll(async () => { + await db.$client.end(); +}); diff --git a/backend/vitest.config.ts b/backend/vitest.config.ts new file mode 100644 index 00000000..f9e98419 --- /dev/null +++ b/backend/vitest.config.ts @@ -0,0 +1,22 @@ +import { defineConfig } from "vitest/config"; + +// https://vitest.dev/config/ +export default defineConfig({ + resolve: { + tsconfigPaths: true, + }, + test: { + // Creates the test database before the tests run. + globalSetup: ["./tests/globalSetup.ts"], + setupFiles: ["./tests/setup.ts"], + env: { + // The API tests use their own Postgres server on port 5434 (see + // tests/globalSetup.ts), so the development database on port 5433 is + // never touched. This is set before our code loads, and dotenv does not + // override it. + DATABASE_URL: "postgresql://postgres@localhost:5434/readr_test", + }, + // All test files use the same database, so run them one at a time. + fileParallelism: false, + }, +}); From fb5dd88d7954307b614790a0a920f08e07f8f7fe Mon Sep 17 00:00:00 2001 From: Johannes Horn Date: Fri, 6 Nov 2026 10:00:05 +0100 Subject: [PATCH 2/7] test: add API tests for books --- backend/tests/books.test.ts | 208 ++++++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 backend/tests/books.test.ts diff --git a/backend/tests/books.test.ts b/backend/tests/books.test.ts new file mode 100644 index 00000000..faf69bd1 --- /dev/null +++ b/backend/tests/books.test.ts @@ -0,0 +1,208 @@ +import { describe, expect, it } from "vitest"; +import { execute } from "./server"; + +// The test books are listed in tests/fixtures.ts. + +const SEARCH_BOOKS = ` + query SearchBooks( + $title: String + $genres: [String!] + $language: String + $bookFormat: String + $minPages: Int + $maxPages: Int + $sortBy: BookSortField + $sortDirection: SortDirection + $limit: Int + $offset: Int + ) { + searchBooks( + title: $title + genres: $genres + language: $language + bookFormat: $bookFormat + minPages: $minPages + maxPages: $maxPages + sortBy: $sortBy + sortDirection: $sortDirection + limit: $limit + offset: $offset + ) { + totalCount + books { + title + } + } + } +`; + +interface SearchBooksData { + searchBooks: { totalCount: number; books: { title: string }[] }; +} + +async function searchBooks(variables: Record = {}) { + const result = await execute(SEARCH_BOOKS, variables); + expect(result.errors).toBeUndefined(); + const { totalCount, books } = result.data!.searchBooks; + return { totalCount, titles: books.map((book) => book.title) }; +} + +describe("searchBooks", () => { + it("returns all books in id order when nothing is selected", async () => { + expect(await searchBooks()).toEqual({ + totalCount: 7, + titles: [ + "The Blade Itself", + "Before They Are Hanged", + "The Hobbit", + "Pride and Prejudice", + "Dune", + "Le Petit Prince", + "An Unrated Book", + ], + }); + }); + + it("matches a word in the title, ignoring case", async () => { + expect((await searchBooks({ title: "hobbit" })).titles).toEqual([ + "The Hobbit", + ]); + expect((await searchBooks({ title: "BLADE" })).titles).toEqual([ + "The Blade Itself", + ]); + }); + + it("returns no books when nothing matches", async () => { + expect(await searchBooks({ title: "no such book" })).toEqual({ + totalCount: 0, + titles: [], + }); + }); + + it("returns books in any of the selected genres", async () => { + expect( + (await searchBooks({ genres: ["Romance", "Science Fiction"] })).titles, + ).toEqual(["Pride and Prejudice", "Dune"]); + }); + + it("combines language, format and page range filters", async () => { + const result = await searchBooks({ + language: "English", + bookFormat: "Paperback", + minPages: 250, + maxPages: 520, + }); + + expect(result.titles).toEqual([ + "The Blade Itself", + "The Hobbit", + "Pride and Prejudice", + ]); + }); + + it("pages through the results and counts every match", async () => { + const firstPage = await searchBooks({ + genres: ["Fantasy"], + limit: 2, + offset: 0, + }); + const secondPage = await searchBooks({ + genres: ["Fantasy"], + limit: 2, + offset: 2, + }); + + expect(firstPage).toEqual({ + totalCount: 4, + titles: ["The Blade Itself", "Before They Are Hanged"], + }); + expect(secondPage).toEqual({ + totalCount: 4, + titles: ["The Hobbit", "An Unrated Book"], + }); + }); + + // Books with the same rating are ordered by number of ratings, and books + // without a rating come last in both directions. + it("sorts all matches by rating before picking a page", async () => { + expect( + (await searchBooks({ sortBy: "RATING", sortDirection: "DESC" })).titles, + ).toEqual([ + "The Hobbit", + "Le Petit Prince", + "Dune", + "Pride and Prejudice", + "Before They Are Hanged", + "The Blade Itself", + "An Unrated Book", + ]); + expect( + (await searchBooks({ sortBy: "RATING", sortDirection: "ASC" })).titles, + ).toEqual([ + "The Blade Itself", + "Pride and Prejudice", + "Before They Are Hanged", + "Dune", + "The Hobbit", + "Le Petit Prince", + "An Unrated Book", + ]); + expect( + ( + await searchBooks({ + sortBy: "RATING", + sortDirection: "DESC", + limit: 2, + }) + ).titles, + ).toEqual(["The Hobbit", "Le Petit Prince"]); + }); +}); + +describe("book", () => { + const BOOK = ` + query Book($id: Int!) { + book(id: $id) { + title + author + pages + genres + } + } + `; + + it("returns one book with its genres", async () => { + const result = await execute<{ + book: { title: string; author: string; pages: number; genres: string[] }; + }>(BOOK, { id: 3 }); + + expect(result.errors).toBeUndefined(); + const { genres, ...book } = result.data!.book; + expect(book).toEqual({ + title: "The Hobbit", + author: "J.R.R. Tolkien", + pages: 310, + }); + expect(genres.toSorted()).toEqual(["Classics", "Fantasy"]); + }); + + it("returns null for a book that does not exist", async () => { + const result = await execute(BOOK, { id: 999 }); + + expect(result.errors).toBeUndefined(); + expect(result.data).toEqual({ book: null }); + }); +}); + +describe("filter options", () => { + it("lists genres, languages and formats, most common first", async () => { + const result = await execute(`{ genres languages bookFormats }`); + + expect(result.errors).toBeUndefined(); + expect(result.data).toEqual({ + genres: ["Fantasy", "Classics", "Romance", "Science Fiction"], + languages: ["English", "French"], + bookFormats: ["Paperback", "Hardcover"], + }); + }); +}); From 79db7951126b75ae026bcf658c2741ff352c2c91 Mon Sep 17 00:00:00 2001 From: Johannes Horn Date: Fri, 6 Nov 2026 10:00:05 +0100 Subject: [PATCH 3/7] test: add API tests for favorites --- backend/tests/favorites.test.ts | 105 ++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 backend/tests/favorites.test.ts diff --git a/backend/tests/favorites.test.ts b/backend/tests/favorites.test.ts new file mode 100644 index 00000000..fa7dd74b --- /dev/null +++ b/backend/tests/favorites.test.ts @@ -0,0 +1,105 @@ +import { beforeEach, describe, expect, it } from "vitest"; +import { db } from "~/db"; +import { favoriteBooks } from "~/db/schema"; +import { execute } from "./server"; + +// Book ids and users come from tests/fixtures.ts. +const user = { userId: "user-1" }; +const otherUser = { userId: "user-2" }; + +const ADD_FAVORITE = ` + mutation AddFavorite($bookId: Int!) { + addFavoriteBook(bookId: $bookId) { + id + } + } +`; +const REMOVE_FAVORITE = ` + mutation RemoveFavorite($bookId: Int!) { + removeFavoriteBook(bookId: $bookId) + } +`; +const FAVORITE_BOOK_IDS = `{ favoriteBookIds }`; + +async function favoriteBookIds(as: { userId: string }) { + const result = await execute<{ favoriteBookIds: number[] }>( + FAVORITE_BOOK_IDS, + {}, + as, + ); + expect(result.errors).toBeUndefined(); + return result.data!.favoriteBookIds.toSorted(); +} + +describe("favorites", () => { + // Every test starts without favorites. + beforeEach(async () => { + await db.delete(favoriteBooks); + }); + + it("rejects users who are not logged in", async () => { + const add = await execute(ADD_FAVORITE, { bookId: 1 }); + const list = await execute(FAVORITE_BOOK_IDS); + + expect(add.errors?.[0].extensions?.code).toBe("UNAUTHENTICATED"); + expect(list.errors?.[0].extensions?.code).toBe("UNAUTHENTICATED"); + }); + + it("adds and removes favorites for the logged-in user", async () => { + await execute(ADD_FAVORITE, { bookId: 3 }, user); + await execute(ADD_FAVORITE, { bookId: 1 }, user); + // Adding the same book twice does not add it twice. + await execute(ADD_FAVORITE, { bookId: 3 }, user); + + expect(await favoriteBookIds(user)).toEqual([1, 3]); + + await execute(REMOVE_FAVORITE, { bookId: 3 }, user); + + expect(await favoriteBookIds(user)).toEqual([1]); + }); + + it("only shows users their own favorites", async () => { + await execute(ADD_FAVORITE, { bookId: 5 }, otherUser); + + expect(await favoriteBookIds(user)).toEqual([]); + expect(await favoriteBookIds(otherUser)).toEqual([5]); + }); + + it("rejects a book that does not exist", async () => { + const result = await execute(ADD_FAVORITE, { bookId: 999 }, user); + + expect(result.errors?.[0].extensions?.code).toBe("BAD_USER_INPUT"); + expect(await favoriteBookIds(user)).toEqual([]); + }); + + it("lists favorite books newest first, and the most common genres", async () => { + for (const bookId of [3, 4, 5]) { + await execute(ADD_FAVORITE, { bookId }, user); + } + + const result = await execute( + `{ + favoriteBooks(limit: 2) { + totalCount + books { + title + } + } + favoriteGenres + }`, + {}, + user, + ); + + expect(result.errors).toBeUndefined(); + expect(result.data).toEqual({ + favoriteBooks: { + totalCount: 3, + books: [{ title: "Dune" }, { title: "Pride and Prejudice" }], + }, + // The Hobbit and Pride and Prejudice are both classics. The rest have + // one book each and are sorted alphabetically, limited to three. + favoriteGenres: ["Classics", "Fantasy", "Romance"], + }); + }); +}); From 0fb5d0b59f68ad982b07deeafa1c3e6dd7eea6a0 Mon Sep 17 00:00:00 2001 From: Johannes Horn Date: Fri, 6 Nov 2026 10:00:05 +0100 Subject: [PATCH 4/7] docs: describe frontend and API tests --- backend/README.md | 33 +++++++++++++++++++++++++++++++++ docs/infrastructure.md | 2 ++ frontend/README.md | 22 +++++++++++++++++----- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/backend/README.md b/backend/README.md index 8c832c37..35b9e365 100644 --- a/backend/README.md +++ b/backend/README.md @@ -148,6 +148,39 @@ cd backend pnpm dev # or: pnpm run dev ``` +## Testing the API + +The API tests in [./tests](./tests/) send GraphQL queries through our schema and +resolvers to a real Postgres database, and check the responses. They use +Apollo Server's `executeOperation`, so they don't start the HTTP server. The +tests set the logged-in user directly, since that is all the resolvers read +from the session. + +Run the tests with: + +```sh +cd backend +pnpm test +``` + +The tests run their own Postgres server, separate from the development +database, so you don't need `pnpm db:setup` or the book dataset, only +PostgreSQL installed (see above). Before the tests run, +[tests/globalSetup.ts](./tests/globalSetup.ts): + +- creates a temporary database folder named `test-db-data` (gitignored) +- starts Postgres from it on port 5434, so it doesn't collide with the + development database on port 5433 +- deletes and creates the database `readr_test`, runs our migrations and inserts + a small set of test books from [tests/fixtures.ts](./tests/fixtures.ts) + +When the tests are done, Postgres is stopped and the folder is deleted. As a safety check, the setup +refuses to reset a database whose name doesn't end with `_test`. + +The tests cover searching, filtering, sorting and paging through books, getting +one book, the lists of filter options, and adding and removing favorites (also +that users must be logged in, and only see their own favorites). + ## GraphQL automatically generated types Whenever you change the GraphQL schema in the folder [./src/schema](./src/schema/), please run the following command: diff --git a/docs/infrastructure.md b/docs/infrastructure.md index 9ab1736f..a1a47f5e 100644 --- a/docs/infrastructure.md +++ b/docs/infrastructure.md @@ -96,6 +96,8 @@ The backend is built using the following frameworks and libraries: - A small web framework for Node.js. This is the framework that receives the API requests that contain the GraphQL requests - [PostgreSQL](https://www.postgresql.org/) (v18) - A widely used relational SQL database. Works perfectly for our use case and integrates well with Drizzle ORM +- [Vitest](https://vitest.dev/) (v5) + - The same testing framework as in the frontend. Runs our API tests against a separate test database ## An Example: The Journey from Start to Finish diff --git a/frontend/README.md b/frontend/README.md index 96a99aa7..e5c5f68d 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -78,7 +78,12 @@ Shared helpers and fixtures live in `app/test/`: - `setup.ts` adds the [jest-dom](https://github.com/testing-library/jest-dom) matchers (e.g. `toBeInTheDocument`) and clears the DOM and `sessionStorage` after every test. -- `fixtures/` holds a sample book. +- `renderRoutes.tsx` renders routes with an in-memory router and Apollo's + `MockedProvider`. +- `mocks.ts` builds GraphQL responses for the mocked API, and `session.ts` holds + logged-in and logged-out sessions for the mocked auth client. +- `fixtures/` holds sample books, both as components use them and as the API + returns them. ### What is tested @@ -87,16 +92,23 @@ markup (like `Header` and `Footer`) is not tested: such tests break on every intended change without catching real bugs. - **Component tests** for `BookCard`, `BookPagination`, `FavoriteButton`, - `FilterBooksSection` and `SearchBar`: rendering based on props, user - interaction (clicks, typing), keeping search and filters in sync with the - URL, and paging. + `BookFilters` and `SearchBar`: rendering based on props, user interaction + (clicks, typing), keeping search and filters in sync with the URL, paging, and + adding and removing favorites. +- **Page tests** for the home page and the book page: showing results from the + API, sending the search, filters, sort and page to the API, empty results, + errors, and navigating between the pages. - **Snapshot test** for `BookCard`. The rendered HTML is stored in `__snapshots__/` next to the test and compared on every run. If a markup change is intended, update the snapshot with `pnpm test -u`. ### Mocking -The page tests (home and selectedBook) were removed when the frontend moved from Open Library to our GraphQL API. Several component tests have not been updated after recent changes and currently fail, for example `FavoriteButton`, which now uses Apollo instead of `localStorage`. We will fix them and rewrite the page tests with Apollo's MockedProvider in #33. +No requests are sent to the backend in the frontend tests. GraphQL requests go +to Apollo's `MockedProvider`, which only answers a request with exactly the query +and variables of a mock, so the tests also check that the pages ask the API for +the right data. The auth client is replaced with `vi.mock`. The API itself is +tested in the backend, see the [backend README](../backend/README.md#testing-the-api). ### Browsers and devices From ff8c2e1bf1a0d636ded69de652a0b61a2f56f52d Mon Sep 17 00:00:00 2001 From: Johannes Horn Date: Thu, 12 Nov 2026 23:35:55 +0100 Subject: [PATCH 5/7] test: update API tests to the current API --- backend/tests/books.test.ts | 40 ++++++++++++++++++++++++--------- backend/tests/favorites.test.ts | 4 +++- backend/tests/fixtures.ts | 35 ++++++++++++++--------------- backend/tests/globalSetup.ts | 5 ++++- 4 files changed, 53 insertions(+), 31 deletions(-) diff --git a/backend/tests/books.test.ts b/backend/tests/books.test.ts index faf69bd1..49593e9f 100644 --- a/backend/tests/books.test.ts +++ b/backend/tests/books.test.ts @@ -1,3 +1,4 @@ +import assert from "node:assert"; import { describe, expect, it } from "vitest"; import { execute } from "./server"; @@ -5,7 +6,7 @@ import { execute } from "./server"; const SEARCH_BOOKS = ` query SearchBooks( - $title: String + $query: String $genres: [String!] $language: String $bookFormat: String @@ -17,7 +18,7 @@ const SEARCH_BOOKS = ` $offset: Int ) { searchBooks( - title: $title + query: $query genres: $genres language: $language bookFormat: $bookFormat @@ -43,37 +44,45 @@ interface SearchBooksData { async function searchBooks(variables: Record = {}) { const result = await execute(SEARCH_BOOKS, variables); expect(result.errors).toBeUndefined(); - const { totalCount, books } = result.data!.searchBooks; + assert(result.data); + const { totalCount, books } = result.data.searchBooks; return { totalCount, titles: books.map((book) => book.title) }; } describe("searchBooks", () => { - it("returns all books in id order when nothing is selected", async () => { + it("returns all books, most ratings first, by default", async () => { expect(await searchBooks()).toEqual({ totalCount: 7, titles: [ - "The Blade Itself", - "Before They Are Hanged", "The Hobbit", "Pride and Prejudice", "Dune", + "The Blade Itself", "Le Petit Prince", + "Before They Are Hanged", "An Unrated Book", ], }); }); it("matches a word in the title, ignoring case", async () => { - expect((await searchBooks({ title: "hobbit" })).titles).toEqual([ + expect((await searchBooks({ query: "hobbit" })).titles).toEqual([ "The Hobbit", ]); - expect((await searchBooks({ title: "BLADE" })).titles).toEqual([ + expect((await searchBooks({ query: "BLADE" })).titles).toEqual([ "The Blade Itself", ]); }); + it("matches the author, ignoring case", async () => { + expect((await searchBooks({ query: "abercrombie" })).titles).toEqual([ + "The Blade Itself", + "Before They Are Hanged", + ]); + }); + it("returns no books when nothing matches", async () => { - expect(await searchBooks({ title: "no such book" })).toEqual({ + expect(await searchBooks({ query: "no such book" })).toEqual({ totalCount: 0, titles: [], }); @@ -81,7 +90,12 @@ describe("searchBooks", () => { it("returns books in any of the selected genres", async () => { expect( - (await searchBooks({ genres: ["Romance", "Science Fiction"] })).titles, + ( + await searchBooks({ + genres: ["Romance", "Science Fiction"], + sortBy: "ID", + }) + ).titles, ).toEqual(["Pride and Prejudice", "Dune"]); }); @@ -91,6 +105,7 @@ describe("searchBooks", () => { bookFormat: "Paperback", minPages: 250, maxPages: 520, + sortBy: "ID", }); expect(result.titles).toEqual([ @@ -105,11 +120,13 @@ describe("searchBooks", () => { genres: ["Fantasy"], limit: 2, offset: 0, + sortBy: "ID", }); const secondPage = await searchBooks({ genres: ["Fantasy"], limit: 2, offset: 2, + sortBy: "ID", }); expect(firstPage).toEqual({ @@ -177,7 +194,8 @@ describe("book", () => { }>(BOOK, { id: 3 }); expect(result.errors).toBeUndefined(); - const { genres, ...book } = result.data!.book; + assert(result.data); + const { genres, ...book } = result.data.book; expect(book).toEqual({ title: "The Hobbit", author: "J.R.R. Tolkien", diff --git a/backend/tests/favorites.test.ts b/backend/tests/favorites.test.ts index fa7dd74b..284dc3b0 100644 --- a/backend/tests/favorites.test.ts +++ b/backend/tests/favorites.test.ts @@ -1,3 +1,4 @@ +import assert from "node:assert"; import { beforeEach, describe, expect, it } from "vitest"; import { db } from "~/db"; import { favoriteBooks } from "~/db/schema"; @@ -28,7 +29,8 @@ async function favoriteBookIds(as: { userId: string }) { as, ); expect(result.errors).toBeUndefined(); - return result.data!.favoriteBookIds.toSorted(); + assert(result.data); + return result.data.favoriteBookIds.toSorted(); } describe("favorites", () => { diff --git a/backend/tests/fixtures.ts b/backend/tests/fixtures.ts index 4b250ebe..e068ba67 100644 --- a/backend/tests/fixtures.ts +++ b/backend/tests/fixtures.ts @@ -1,3 +1,4 @@ +import assert from "node:assert"; import type { NodePgDatabase } from "drizzle-orm/node-postgres"; import { bookGenres, books, bookToGenres, user } from "~/db/schema"; @@ -88,16 +89,6 @@ const testUsers = [ ]; async function seedTestData(db: NodePgDatabase) { - const insertedBooks = await db - .insert(books) - .values( - testBooks.map(({ genres: _genres, ...book }, i) => ({ - ...book, - isbn: `978000000000${i}`, - })), - ) - .returning({ id: books.id }); - const genreNames = [...new Set(testBooks.flatMap((book) => book.genres))]; const insertedGenres = await db .insert(bookGenres) @@ -105,14 +96,22 @@ async function seedTestData(db: NodePgDatabase) { .returning(); const genreIds = new Map(insertedGenres.map((g) => [g.genre, g.id])); - await db.insert(bookToGenres).values( - testBooks.flatMap((book, i) => - book.genres.map((genre) => ({ - bookId: insertedBooks[i].id, - genreId: genreIds.get(genre)!, - })), - ), - ); + // Insert the books one at a time, so each book's genres can be linked to its + // id. + const genreLinks: (typeof bookToGenres.$inferInsert)[] = []; + for (const [i, { genres, ...book }] of testBooks.entries()) { + const [{ id: bookId }] = await db + .insert(books) + .values({ ...book, isbn: `978000000000${i}` }) + .returning({ id: books.id }); + + for (const genre of genres) { + const genreId = genreIds.get(genre); + assert(genreId !== undefined, `Unknown genre "${genre}"`); + genreLinks.push({ bookId, genreId }); + } + } + await db.insert(bookToGenres).values(genreLinks); await db.insert(user).values(testUsers); } diff --git a/backend/tests/globalSetup.ts b/backend/tests/globalSetup.ts index 8d63d304..58d8c313 100644 --- a/backend/tests/globalSetup.ts +++ b/backend/tests/globalSetup.ts @@ -32,7 +32,10 @@ function run(command: string, args: string[]) { // function stops the server and deletes its folder after the tests. export async function setup(project: TestProject) { // The test database from vitest.config.ts - const databaseUrl = project.config.env.DATABASE_URL as string; + const databaseUrl = project.config.env.DATABASE_URL; + if (!databaseUrl) { + throw new Error("DATABASE_URL must be set in vitest.config.ts."); + } const url = new URL(databaseUrl); const databaseName = url.pathname.slice(1); From fa48c2bbbeb8d627a75bba96434472e9cc8b620a Mon Sep 17 00:00:00 2001 From: Johannes Horn Date: Mon, 16 Nov 2026 11:11:28 +0100 Subject: [PATCH 6/7] docs: note that the API tests do not verify database performance --- backend/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backend/README.md b/backend/README.md index 35b9e365..c683c91b 100644 --- a/backend/README.md +++ b/backend/README.md @@ -181,6 +181,10 @@ The tests cover searching, filtering, sorting and paging through books, getting one book, the lists of filter options, and adding and removing favorites (also that users must be logged in, and only see their own favorites). +> [!NOTE] +> The test database is very small, so the tests do not check or verify the performance of our database. +> This is rather done by careful planning of indexes and checking the results of `EXPLAIN` queries to see if indexes and efficient strategies are used. + ## GraphQL automatically generated types Whenever you change the GraphQL schema in the folder [./src/schema](./src/schema/), please run the following command: From 1246e8362882cde41a4197c1f431e0189538aab2 Mon Sep 17 00:00:00 2001 From: Johannes Horn Date: Mon, 16 Nov 2026 11:11:28 +0100 Subject: [PATCH 7/7] docs: list Vitest under common technologies --- docs/infrastructure.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/infrastructure.md b/docs/infrastructure.md index 90268ec2..d65293ea 100644 --- a/docs/infrastructure.md +++ b/docs/infrastructure.md @@ -53,6 +53,8 @@ These are used in both the frontend and backend: - This is a great utility that generates useful TypeScript types for our GraphQL queries and their response formats - [TypeScript](https://www.typescriptlang.org/) (v6) - The strongly-typed programming language, building upon JavaScript, allowing more predictable code and extensive tooling in IDEs and other tools +- [Vitest](https://vitest.dev/) (v5) + - A testing framework for Vite. Runs the frontend's component and page tests, and the backend's API tests against a separate test database ## Frontend @@ -76,8 +78,6 @@ The frontend is built using the following frameworks and libraries: - A form library that manages state, submitting, validation, all while being strictly type-checked - [testing-library](https://testing-library.com/) - A collection of testing utilities for UI tests -- [Vitest](https://vitest.dev/) (v5) - - A testing framework for Vite - [Vite](https://vite.dev/) (v8) - The build tool for our application @@ -96,8 +96,6 @@ The backend is built using the following frameworks and libraries: - A small web framework for Node.js. This is the framework that receives the API requests that contain the GraphQL requests - [PostgreSQL](https://www.postgresql.org/) (v18) - A widely used relational SQL database. Works perfectly for our use case and integrates well with Drizzle ORM -- [Vitest](https://vitest.dev/) (v5) - - The same testing framework as in the frontend. Runs our API tests against a separate test database ## An Example: The Journey from Start to Finish