diff --git a/.gitignore b/.gitignore index c4f70fa..f57182c 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ dist-ssr build/ db-data/ +test-db-data/ book-data.csv # Playwright diff --git a/backend/README.md b/backend/README.md index 8c832c3..c683c91 100644 --- a/backend/README.md +++ b/backend/README.md @@ -148,6 +148,43 @@ 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). + +> [!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: diff --git a/backend/package.json b/backend/package.json index f7f0dac..7f4ebbf 100644 --- a/backend/package.json +++ b/backend/package.json @@ -11,6 +11,7 @@ "main": "dist/index.js", "scripts": { "typecheck": "tsc", + "test": "vitest run", "lint": "eslint .", "codegen": "graphql-codegen", "format": "prettier --write .", @@ -73,6 +74,7 @@ "prettier": "3.9.9", "tsx": "^4.23.15", "typescript": "^6.0.3", - "typescript-eslint": "^8.72.1" + "typescript-eslint": "^8.72.1", + "vitest": "^5.1.0" } } diff --git a/backend/pnpm-lock.yaml b/backend/pnpm-lock.yaml index 73f7737..a25ef87 100644 --- a/backend/pnpm-lock.yaml +++ b/backend/pnpm-lock.yaml @@ -180,7 +180,7 @@ importers: version: 9.2.8(graphql@17.1.0) better-auth: specifier: ^1.7.18 - version: 1.7.18(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.18(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.6)(vite@8.3.8(@types/node@26.6.6)(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 @@ -251,6 +251,9 @@ importers: typescript-eslint: specifier: ^8.72.1 version: 8.72.1(eslint@10.14.0(jiti@2.7.0))(typescript@6.0.3) + vitest: + specifier: ^5.1.0 + version: 5.1.0(@types/node@26.6.6)(vite@8.3.8(@types/node@26.6.6)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.15)(yaml@2.9.1)) packages: @@ -516,6 +519,15 @@ packages: peerDependencies: graphql: ^15.0.0 || ^16.0.0 || ^17.0.0 + '@emnapi/core@2.0.0-beta.2': + resolution: {integrity: sha512-MzCVoWtcg4Pm2B3je5mMvYMvj3MmBKw+fU7vbsJc9/iT8ip6/eYIHo/Dsm/mr+wsHB6SEyJDuxB09Yy6r/8+4A==} + + '@emnapi/runtime@2.0.0-beta.2': + resolution: {integrity: sha512-JcrSPzPvZuNZvJqPTF9Fw25LbOJ8avzFVlaf2grmH4Cku0oGP47tRgqPZadcfj3YoZMHkFVnCYFbQM8I+i5QEw==} + + '@emnapi/wasi-threads@2.2.0': + resolution: {integrity: sha512-JP7OYH38Q7+pyTAe14raZHLQIK7BDKbdwji+Xi3pcd/6QkJYQH3SX4wu6EplGrGJWRepoNzedfm0G3B9Z4e9Rw==} + '@envelop/core@5.6.1': resolution: {integrity: sha512-KEbJ7yrAA+W7IY9MZzpZJ77w/72ndaV/16+hhPapd+0Ohjqffl0mmF3QWy62/m3nRP4qidD+1eiEjJhS/O38Tg==} engines: {node: '>=18.0.0'} @@ -1313,6 +1325,13 @@ packages: '@keyv/serialize@1.1.1': resolution: {integrity: sha512-dXn3FZhPv0US+7dtJsIi2R+c7qWYiReoEh5zUntWCf4oSpMNib8FDhSoed6m3QyZdx5hK7iLFkYk3rNxwt8vTA==} + '@napi-rs/wasm-runtime@1.2.6': + resolution: {integrity: sha512-mRyDmEw9/fCDXCGfL1sbgIw/GUK0PVxRW4YwgPN61F3LQ+fSyoBFarJVzgGyhF6kRzEQZ0FejDqm4WLXSeqQmw==} + engines: {node: ^20.19.0 || ^22.13.0 || >=23.5.0} + peerDependencies: + '@emnapi/core': ^1.7.1 || 2.0.0-beta.2 + '@emnapi/runtime': ^1.7.1 || 2.0.0-beta.2 + '@noble/ciphers@2.4.0': resolution: {integrity: sha512-AnjFn0Jv92laAkvMrghlFZq4qQCIN/4DxFV/eooqtC2YTjB7kBeLMS2T9KJX4Dn+ZVXLOwK0lSgqDtx9gvxtiw==} engines: {node: '>= 20.19.0'} @@ -1333,6 +1352,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==} @@ -1366,21 +1388,134 @@ packages: '@repeaterjs/repeater@3.1.0': resolution: {integrity: sha512-TaoVksZRSx2KWYYpyLQtMQXXeS98VsgZImzW65xmiVgbYhXLk+aEsmzPLirqVuE4/XuUapH2iMtxUzaBNDzdSQ==} + '@rolldown/binding-android-arm-eabi@1.2.19': + resolution: {integrity: sha512-e+Ebe0WT+9tbXmNKPIiC8YrWAHYwug3m6i4p3rZGGulfZri1jtI4HslT+OZnFf/OIHowWF71DTlHwXBP2SiA7A==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm] + os: [android] + + '@rolldown/binding-android-arm64@1.2.19': + resolution: {integrity: sha512-hOombrTJ+szt2ciEzS7oCA78lMPBgF5UMQWCJIyNfnrI7GLl8HYoFqCnpL2gcPOaXMqryGCU5ExdQKyDDcC+yA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [android] + + '@rolldown/binding-darwin-arm64@1.2.19': + resolution: {integrity: sha512-XoMA2pwCKGTQzUjPgtRwkedH4WmXhdIPKT6l6oOxd1PUbNodGI6DcBekgN7EC//+x3pfBYX/qL1gNmZAqivw5g==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [darwin] + + '@rolldown/binding-darwin-x64@1.2.19': + resolution: {integrity: sha512-zo8EsSSwMZCY/e+fRnGaX02YGgvJD0yvhNi/9hpGPA2MJ9ZF8dPCw75UGfpI6OpQ/myR/dIYmogRvqiZD0TrXg==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [darwin] + + '@rolldown/binding-freebsd-x64@1.2.19': + resolution: {integrity: sha512-O8ISAOfI1nj7AuBPd30FSF47z7f7lzlk5poQVGgiikvQuGEBFYvW8ki+UEnT+YJPnNGjQzn304klt4O9FUE7mA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [freebsd] + + '@rolldown/binding-linux-arm-gnueabihf@1.2.19': + resolution: {integrity: sha512-/lYCba5NO0yq4S0jGMH8QTBtkvQxoXjoQWzF5BcWp9MjB9jxVRD1GQDNofkVjcOj30DWyhLIN/4Oe60JKzaONw==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm] + os: [linux] + + '@rolldown/binding-linux-arm64-gnu@1.2.19': + resolution: {integrity: sha512-pm/apFMBnSbFb3O6nG5pHO1iqHhZrjGDFEjSm+ot9J17XXPvH9L90y5h+jgfHCE+Qdlsvy8qKEcU4VKxgjD+vA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [linux] + libc: [glibc] + + '@rolldown/binding-linux-arm64-musl@1.2.19': + resolution: {integrity: sha512-K1SmQp3FFichn8oqrNIwvFoZ5wcvjC7goBzpaMNvLf9FZc+QB/QvLmnpJZgAAGHiD980tP8FZZnXk2K94rvlxg==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [linux] + libc: [musl] + + '@rolldown/binding-linux-ppc64-gnu@1.2.19': + resolution: {integrity: sha512-I0xwD57jP/3A7+5UPZin2w8Y7XHEmEM5zqpYZOcQ45MlNW6tUJUziymV3yRr7rL4vwyfEcRsRksC4a7Kc08p5Q==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [ppc64] + os: [linux] + libc: [glibc] + + '@rolldown/binding-linux-s390x-gnu@1.2.19': + resolution: {integrity: sha512-BrtEHT24SNXj9HiXqy+s/kXiSiQGt6EKCPUlRirAoIioVxKGnbXBUEkbZASAei7iZJB0/Ynm+0JP00Ipx7AnSw==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [s390x] + os: [linux] + libc: [glibc] + + '@rolldown/binding-linux-x64-gnu@1.2.19': + resolution: {integrity: sha512-rm75/9DkHKeU2WnA8w4X94WGYgLlDCFCfkQC+4bguVJmC/jvDRv2B+2wLOYhyE0fVuv7//Ckk39OoOufyCu76Q==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [linux] + libc: [glibc] + + '@rolldown/binding-linux-x64-musl@1.2.19': + resolution: {integrity: sha512-irh/4+iYFM4GAzpluDErgjz89bj6NDtqqMAG/6O1LG38Ed3NpyebzCpcVNkFW8uhy+/3/BocUvnXDR33CXWe9A==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [linux] + libc: [musl] + + '@rolldown/binding-openharmony-arm64@1.2.19': + resolution: {integrity: sha512-+KWTWNoPt+CfSq94CiceWu3yPE+QzkaG+phPyz9G60tmZLwfQkcA4AeksafzvJAw4pvg1mcd5a1TkUqVv0s4JA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [openharmony] + + '@rolldown/binding-wasm32-wasi@1.2.19': + resolution: {integrity: sha512-7EH+skOsl5qpWnK0vzamgJFhOv1cwxQpsxm8tI883K9fur5c27p8q87fzEO6BbBPabA2/+s/zR63/pLc137iOg==} + engines: {node: ^20.19.0 || ^22.13.0 || >=23.5.0} + cpu: [wasm32] + + '@rolldown/binding-win32-arm64-msvc@1.2.19': + resolution: {integrity: sha512-3Q1Yg1Q7tEvBWoZf5rFvG/GKZQPgwfru+p4wBajDfJFBs0SHCpL++dfTjW9gyAKd1T7ZpIYvdaUax7Pa/IhFVQ==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [win32] + + '@rolldown/binding-win32-x64-msvc@1.2.19': + resolution: {integrity: sha512-y/sqRRc6d7hECzOFc5n3LSeqctmIp9mMjY1Kq4s14uLPd/LZ4z7i1zrW6fMtp2mPeuQIC4e6ULMcwQzMomqQag==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [win32] + + '@rolldown/pluginutils@1.1.0': + resolution: {integrity: sha512-K+NU2HDCEem4sClgHH4ZZXwdJeNFkJo+hRk479DIwdIviAPN2hFJH1KHHwg8CxHQXvi0M5XY4deTXINfIiSG6w==} + '@standard-schema/spec@1.1.0': resolution: {integrity: sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==} '@ts-morph/common@0.23.0': resolution: {integrity: sha512-m7Lllj9n/S6sOkCkRftpM7L24uvmfXQFedlW/4hENcuJH1HHm9u5EgxZb9uVjQSCGrbBWBkOGgcTxNg36r6ywA==} + '@tybys/wasm-util@0.10.4': + resolution: {integrity: sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A==} + '@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/esrecurse@4.3.1': resolution: {integrity: sha512-xJBAbDifo5hpffDBuHl0Y8ywswbiAp/Wi7Y/GtAgSlZyIABppyurxVueOPE8LUQOxdlgi6Zqce7uoEpqNTeiUw==} @@ -1482,6 +1617,20 @@ packages: resolution: {integrity: sha512-SB8xqipSzZHUePCCLNeYxqnxq83X61/qzNhjQGbTfjxGZIeOEP7tBgWYX05Tcd6CgE02WdTJnh5b8kMZJ/+bnQ==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + '@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'} @@ -1550,6 +1699,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==} @@ -1686,6 +1839,10 @@ packages: caniuse-lite@1.0.30001823: resolution: {integrity: sha512-TQ5s/djDjNk1axreUW+4rULH+BmdCMLiJkhaXnO5wqivG7tITkSUj4ItIdzqdZHKaXcHAV8dhH3JxOM7/7bwqw==} + 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} @@ -1820,6 +1977,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'} @@ -2015,6 +2176,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'} @@ -2078,6 +2242,9 @@ packages: resolution: {integrity: sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==} engines: {node: '>=4.0'} + estree-walker@3.0.3: + resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==} + esutils@2.0.3: resolution: {integrity: sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==} engines: {node: '>=0.10.0'} @@ -2089,6 +2256,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'} @@ -2438,6 +2609,80 @@ packages: resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==} engines: {node: '>= 0.8.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==} @@ -2478,6 +2723,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'} @@ -2543,6 +2791,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} @@ -2579,6 +2832,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'} @@ -2693,6 +2950,10 @@ packages: 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'} @@ -2780,6 +3041,11 @@ packages: rfdc@1.4.1: resolution: {integrity: sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==} + rolldown@1.2.19: + resolution: {integrity: sha512-QIiV1J9d0pzN4jeeTH4sjPy0AZ6cAy2cG0ExeoE1+U8Rvj+hR3gYkokx0YbeUNGlZqiQJJ2utcETe0oKXwzsuA==} + engines: {node: ^20.19.0 || >=22.12.0} + hasBin: true + rou3@0.9.2: resolution: {integrity: sha512-3SOzvaAg8rkHrXtRjpCvCvbyO5to9oOO27Z/XqHEYXfMRVSw/qMIVdmaOk9W2lcRLtR6dlqTjo9hDeJk70QBYQ==} @@ -2872,6 +3138,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'} @@ -2883,6 +3153,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==} @@ -2909,6 +3182,14 @@ 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'} @@ -3007,6 +3288,90 @@ packages: resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==} engines: {node: '>= 0.8'} + vite@8.3.8: + resolution: {integrity: sha512-LzOn3h9rG/0vhLdXrV4yJ4QFA9eEoqCl+Yx+kGJd7aB9w6nfNgVHKSYwLPZUHrz4ZGa+t+kXjV9itvcHDLQouA==} + 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'} @@ -3028,6 +3393,11 @@ packages: engines: {node: '>= 8'} hasBin: true + why-is-node-running@3.2.1: + resolution: {integrity: sha512-Tb2FUhB4vUsGQlfSquQLYkApkuPAFQXGFzxWKHHumVz2dK+X1RUm/HnID4+TfIGYJ1kTcwOaCk/buYCEJr6YjQ==} + engines: {node: '>=20.11'} + hasBin: true + word-wrap@1.2.5: resolution: {integrity: sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==} engines: {node: '>=0.10.0'} @@ -3406,6 +3776,22 @@ snapshots: transitivePeerDependencies: - graphql-sock + '@emnapi/core@2.0.0-beta.2': + dependencies: + '@emnapi/wasi-threads': 2.2.0 + tslib: 2.9.1 + optional: true + + '@emnapi/runtime@2.0.0-beta.2': + dependencies: + tslib: 2.9.1 + optional: true + + '@emnapi/wasi-threads@2.2.0': + dependencies: + tslib: 2.9.1 + optional: true + '@envelop/core@5.6.1': dependencies: '@envelop/instrumentation': 1.0.1 @@ -4188,6 +4574,13 @@ snapshots: '@keyv/serialize@1.1.1': {} + '@napi-rs/wasm-runtime@1.2.6(@emnapi/core@2.0.0-beta.2)(@emnapi/runtime@2.0.0-beta.2)': + dependencies: + '@emnapi/core': 2.0.0-beta.2 + '@emnapi/runtime': 2.0.0-beta.2 + '@tybys/wasm-util': 0.10.4 + optional: true + '@noble/ciphers@2.4.0': {} '@noble/hashes@2.4.0': {} @@ -4204,6 +4597,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': {} @@ -4228,6 +4623,60 @@ snapshots: '@repeaterjs/repeater@3.1.0': {} + '@rolldown/binding-android-arm-eabi@1.2.19': + optional: true + + '@rolldown/binding-android-arm64@1.2.19': + optional: true + + '@rolldown/binding-darwin-arm64@1.2.19': + optional: true + + '@rolldown/binding-darwin-x64@1.2.19': + optional: true + + '@rolldown/binding-freebsd-x64@1.2.19': + optional: true + + '@rolldown/binding-linux-arm-gnueabihf@1.2.19': + optional: true + + '@rolldown/binding-linux-arm64-gnu@1.2.19': + optional: true + + '@rolldown/binding-linux-arm64-musl@1.2.19': + optional: true + + '@rolldown/binding-linux-ppc64-gnu@1.2.19': + optional: true + + '@rolldown/binding-linux-s390x-gnu@1.2.19': + optional: true + + '@rolldown/binding-linux-x64-gnu@1.2.19': + optional: true + + '@rolldown/binding-linux-x64-musl@1.2.19': + optional: true + + '@rolldown/binding-openharmony-arm64@1.2.19': + optional: true + + '@rolldown/binding-wasm32-wasi@1.2.19': + dependencies: + '@emnapi/core': 2.0.0-beta.2 + '@emnapi/runtime': 2.0.0-beta.2 + '@napi-rs/wasm-runtime': 1.2.6(@emnapi/core@2.0.0-beta.2)(@emnapi/runtime@2.0.0-beta.2) + optional: true + + '@rolldown/binding-win32-arm64-msvc@1.2.19': + optional: true + + '@rolldown/binding-win32-x64-msvc@1.2.19': + optional: true + + '@rolldown/pluginutils@1.1.0': {} + '@standard-schema/spec@1.1.0': {} '@ts-morph/common@0.23.0': @@ -4237,11 +4686,21 @@ snapshots: mkdirp: 3.0.1 path-browserify: 1.0.1 + '@tybys/wasm-util@0.10.4': + dependencies: + tslib: 2.9.1 + optional: true + '@types/body-parser@1.19.6': dependencies: '@types/connect': 3.4.38 '@types/node': 26.6.6 + '@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.6 @@ -4250,6 +4709,8 @@ snapshots: dependencies: '@types/node': 26.6.6 + '@types/deep-eql@4.0.2': {} + '@types/esrecurse@4.3.1': {} '@types/estree@1.0.10': {} @@ -4391,6 +4852,17 @@ snapshots: '@typescript-eslint/types': 8.72.1 eslint-visitor-keys: 5.0.1 + '@vitest/mocker@5.1.0(vite@8.3.8(@types/node@26.6.6)(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.8(@types/node@26.6.6)(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 @@ -4463,6 +4935,8 @@ snapshots: array-union@2.1.0: {} + assertion-error@2.0.1: {} + async-retry@1.3.3: dependencies: retry: 0.13.1 @@ -4479,7 +4953,7 @@ snapshots: baseline-browser-mapping@2.11.35: {} - better-auth@1.7.18(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.18(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.6)(vite@8.3.8(@types/node@26.6.6)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.15)(yaml@2.9.1))): dependencies: '@better-auth/core': 1.7.18(@better-auth/utils@0.5.1)(@better-fetch/fetch@1.3.3)(better-call@1.4.5(zod@4.6.7))(jose@6.2.15)(kysely@0.29.8)(nanostores@1.5.5) '@better-auth/drizzle-adapter': 1.7.18(@better-auth/core@1.7.18(@better-auth/utils@0.5.1)(@better-fetch/fetch@1.3.3)(better-call@1.4.5(zod@4.6.7))(jose@6.2.15)(kysely@0.29.8)(nanostores@1.5.5))(@better-auth/utils@0.5.1)(drizzle-orm@1.0.0-rc.4(@types/pg@8.23.1)(pg@8.23.1)(zod@4.6.7)) @@ -4502,6 +4976,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.6)(vite@8.3.8(@types/node@26.6.6)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.15)(yaml@2.9.1)) transitivePeerDependencies: - '@opentelemetry/api' @@ -4579,6 +5054,8 @@ snapshots: caniuse-lite@1.0.30001823: {} + chai@6.3.0: {} + chalk@5.6.2: {} change-case-all@2.2.0: @@ -4686,6 +5163,8 @@ snapshots: detect-indent@7.0.2: {} + detect-libc@2.1.2: {} + dir-glob@3.0.1: dependencies: path-type: 4.0.0 @@ -4732,6 +5211,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 @@ -4864,12 +5345,18 @@ snapshots: estraverse@5.3.0: {} + estree-walker@3.0.3: + dependencies: + '@types/estree': 1.0.10 + esutils@2.0.3: {} etag@1.8.1: {} eventemitter3@5.0.4: {} + expect-type@1.4.0: {} + express@5.3.0: dependencies: accepts: 2.0.0 @@ -5219,6 +5706,55 @@ snapshots: prelude-ls: 1.2.1 type-check: 0.4.0 + 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: @@ -5262,6 +5798,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: {} @@ -5303,6 +5843,8 @@ snapshots: mute-stream@3.0.0: {} + nanoid@3.3.20: {} + nanostores@1.5.5: {} natural-compare@1.4.0: {} @@ -5329,6 +5871,8 @@ snapshots: object-inspect@1.13.4: {} + obug@3.0.0: {} + on-finished@2.4.2: dependencies: ee-first: 1.1.1 @@ -5436,6 +5980,12 @@ snapshots: 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: {} @@ -5500,6 +6050,28 @@ snapshots: rfdc@1.4.1: {} + rolldown@1.2.19: + dependencies: + '@oxc-project/types': 0.156.0 + '@rolldown/pluginutils': 1.1.0 + optionalDependencies: + '@rolldown/binding-android-arm-eabi': 1.2.19 + '@rolldown/binding-android-arm64': 1.2.19 + '@rolldown/binding-darwin-arm64': 1.2.19 + '@rolldown/binding-darwin-x64': 1.2.19 + '@rolldown/binding-freebsd-x64': 1.2.19 + '@rolldown/binding-linux-arm-gnueabihf': 1.2.19 + '@rolldown/binding-linux-arm64-gnu': 1.2.19 + '@rolldown/binding-linux-arm64-musl': 1.2.19 + '@rolldown/binding-linux-ppc64-gnu': 1.2.19 + '@rolldown/binding-linux-s390x-gnu': 1.2.19 + '@rolldown/binding-linux-x64-gnu': 1.2.19 + '@rolldown/binding-linux-x64-musl': 1.2.19 + '@rolldown/binding-openharmony-arm64': 1.2.19 + '@rolldown/binding-wasm32-wasi': 1.2.19 + '@rolldown/binding-win32-arm64-msvc': 1.2.19 + '@rolldown/binding-win32-x64-msvc': 1.2.19 + rou3@0.9.2: {} router@2.2.0: @@ -5618,12 +6190,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: @@ -5651,6 +6227,10 @@ 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) @@ -5746,6 +6326,42 @@ snapshots: vary@1.1.2: {} + vite@8.3.8(@types/node@26.6.6)(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.19 + tinyglobby: 0.2.17 + optionalDependencies: + '@types/node': 26.6.6 + 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.6)(vite@8.3.8(@types/node@26.6.6)(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.8(@types/node@26.6.6)(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.8(@types/node@26.6.6)(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.6 + transitivePeerDependencies: + - msw + web-streams-polyfill@3.3.3: {} whatwg-mimetype@4.0.0: {} @@ -5766,6 +6382,8 @@ snapshots: dependencies: isexe: 2.0.0 + why-is-node-running@3.2.1: {} + word-wrap@1.2.5: {} wrap-ansi@10.0.2: diff --git a/backend/tests/books.test.ts b/backend/tests/books.test.ts new file mode 100644 index 0000000..49593e9 --- /dev/null +++ b/backend/tests/books.test.ts @@ -0,0 +1,226 @@ +import assert from "node:assert"; +import { describe, expect, it } from "vitest"; +import { execute } from "./server"; + +// The test books are listed in tests/fixtures.ts. + +const SEARCH_BOOKS = ` + query SearchBooks( + $query: String + $genres: [String!] + $language: String + $bookFormat: String + $minPages: Int + $maxPages: Int + $sortBy: BookSortField + $sortDirection: SortDirection + $limit: Int + $offset: Int + ) { + searchBooks( + query: $query + 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(); + assert(result.data); + const { totalCount, books } = result.data.searchBooks; + return { totalCount, titles: books.map((book) => book.title) }; +} + +describe("searchBooks", () => { + it("returns all books, most ratings first, by default", async () => { + expect(await searchBooks()).toEqual({ + totalCount: 7, + titles: [ + "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({ query: "hobbit" })).titles).toEqual([ + "The Hobbit", + ]); + 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({ query: "no such book" })).toEqual({ + totalCount: 0, + titles: [], + }); + }); + + it("returns books in any of the selected genres", async () => { + expect( + ( + await searchBooks({ + genres: ["Romance", "Science Fiction"], + sortBy: "ID", + }) + ).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, + sortBy: "ID", + }); + + 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, + sortBy: "ID", + }); + const secondPage = await searchBooks({ + genres: ["Fantasy"], + limit: 2, + offset: 2, + sortBy: "ID", + }); + + 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(); + assert(result.data); + 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"], + }); + }); +}); diff --git a/backend/tests/favorites.test.ts b/backend/tests/favorites.test.ts new file mode 100644 index 0000000..284dc3b --- /dev/null +++ b/backend/tests/favorites.test.ts @@ -0,0 +1,107 @@ +import assert from "node:assert"; +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(); + assert(result.data); + 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"], + }); + }); +}); diff --git a/backend/tests/fixtures.ts b/backend/tests/fixtures.ts new file mode 100644 index 0000000..e068ba6 --- /dev/null +++ b/backend/tests/fixtures.ts @@ -0,0 +1,119 @@ +import assert from "node:assert"; +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 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])); + + // 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); +} + +export { seedTestData, testBooks }; diff --git a/backend/tests/globalSetup.ts b/backend/tests/globalSetup.ts new file mode 100644 index 0000000..58d8c31 --- /dev/null +++ b/backend/tests/globalSetup.ts @@ -0,0 +1,96 @@ +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; + 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); + + // 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 0000000..14ae390 --- /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 0000000..b9ba03d --- /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 0000000..f9e9841 --- /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, + }, +}); diff --git a/docs/infrastructure.md b/docs/infrastructure.md index 29310e5..d65293e 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 diff --git a/frontend/README.md b/frontend/README.md index 53a5f52..35d611f 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -80,7 +80,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 @@ -89,16 +94,23 @@ markup (like `Header` and `Footer`) is not tested: such tests break on every intended change without catching real bugs. - **Component tests** for `BookCard`, `ItemPagination`, `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). ### Playwright (end-to-end tests)