Skip to content

Commit

Permalink
remove seed/reset api routes, replace with scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-burel committed Sep 10, 2021
1 parent 1589e55 commit a329887
Show file tree
Hide file tree
Showing 11 changed files with 190,766 additions and 98 deletions.
10 changes: 7 additions & 3 deletions .vn/scripts/build-scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
# See https://github.com/vercel/ncc
# NOTE: you are expected to run "yarn run build:scripts" from the project root for path to be correct
vn_scripts_dir=./.vn/scripts
for f in "$vn_scripts_dir/ts-sources"/*
ts_sources_dir="$vn_scripts_dir/ts-sources"
# The printf strips the root, so result is "db/reset.ts foobar.ts" etc.
for f in `find "$ts_sources_dir" -type f -name "*.ts" -printf '%P\n'`
do
echo "Build $f"
dname=`dirname "$f"`
fname=`basename "$f"`
fname_no_ext=`echo "$fname" | cut -d. -f1`
echo "Filename $fname, without ext $fname_no_ext"
yarn run ncc build "$f" --no-cache --out "$vn_scripts_dir/dist"
mv "$vn_scripts_dir/dist/index.js" "$vn_scripts_dir/$fname_no_ext".js
yarn run ncc build "$ts_sources_dir/$f" --no-cache --out "$vn_scripts_dir/dist"
mkdir -p "$vn_scripts_dir/$dname"
mv "$vn_scripts_dir/dist/index.js" "$vn_scripts_dir/$dname/$fname_no_ext".js
done
rm -R "$vn_scripts_dir/dist"
29 changes: 15 additions & 14 deletions .vn/scripts/test-script.js → .vn/scripts/db/reset.js

Large diffs are not rendered by default.

190,728 changes: 190,728 additions & 0 deletions .vn/scripts/db/seed.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions .vn/scripts/ts-sources/db/reset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import mongoose from "mongoose";
import { closeDbConnection, connectToAppDb } from "~/api/mongoose/connection";

await connectToAppDb();
await mongoose.connection.db.dropDatabase();
await closeDbConnection();
6 changes: 6 additions & 0 deletions .vn/scripts/ts-sources/db/seed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { closeDbConnection, connectToAppDb } from "~/api/mongoose/connection";
import runSeed from "~/api/runSeed";

await connectToAppDb();
await runSeed();
await closeDbConnection();
8 changes: 0 additions & 8 deletions .vn/scripts/ts-sources/test-script.ts

This file was deleted.

4 changes: 2 additions & 2 deletions cypress/integration/e2e/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/
describe("auth", () => {
beforeEach(() => {
cy.request("/api/debug/db/reset");
cy.request("/api/debug/db/seed");
cy.exec("yarn run db:test:reset");
cy.exec("yarn run db:test:seed");
});
it("login", () => {
cy.visit("/login");
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"coverage": "npm run coverage:unit && npm run coverage:e2e",
"cypress:open": "cross-env CYPRESS_coverage=false NODE_ENV=test cypress open",
"cypress:run": "cross-env CYPRESS_DEBUG=false CYPRESS_coverage=false NODE_ENV=test cypress run --headless",
"db:test:seed": "dotenv -e .env.test node .vn/scripts/db/seed.js",
"db:test:reset": "dotenv -e .env.test node .vn/scripts/db/reset.js # reset can only happen against the test database!",
"debug": "NODE_OPTIONS='--inspect' next",
"dev": "next",
"dev:test": "cross-env NODE_ENV=test next # Start app in test + dev mode",
Expand Down
6 changes: 0 additions & 6 deletions src/content/docs/features/testing-+-storybook.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ We followed awesome [recommandations from Bahmutov](https://github.com/bahmutov/

Run `yarn start:test` or `yarn dev:test` to run your Next server in Test mode. This will in particular load `.env.test` environment config and set `NODE_ENV` to "test".

### Database management API routes

Trigger a request to `api/debug/db/seed` and `api/debug/db/reset` to seed/reset your local database.

/!\ Those endpoints wont work in production! They are only for testing.

### TypeScript and vanilla JS (+ESLint)

### Custom commands, with TypeScript
Expand Down
33 changes: 0 additions & 33 deletions src/pages/api/debug/db/reset.ts

This file was deleted.

32 changes: 0 additions & 32 deletions src/pages/api/debug/db/seed.ts

This file was deleted.

0 comments on commit a329887

Please sign in to comment.