-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adds a test that runs the db seed, making sure it's compatible with latest schema #402
Conversation
thomhickey
commented
Sep 2, 2024
•
edited
Loading
edited
- creates a test db
- runs 'seedfile' from src/backend/db/lib/seed.ts
- queries the db for both students and users
- asserts that there are >0 students and users
- closes Test for db: seed #387
…is should work, might have to modify the assertions as we go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me except for a minor comment on test naming.
I tested that this actually fails when backwards incompatible schema changes are made by replacing all instances of last_name
with surname
in src/backend/db/migrations/1_initial-migrations.sql
and then running the test. It failed exactly as I'd expect with the error message below. ✅
Thank you, @thomhickey !
Uncaught exception in src/backend/db/lib/seed.test.ts
error: terminating connection due to administrator command
› Parser.parseErrorMessage (node_modules/pg-protocol/dist/parser.js:287:98)
› Parser.handlePacket (node_modules/pg-protocol/dist/parser.js:126:29)
› Parser.parse (node_modules/pg-protocol/dist/parser.js:39:38)
› Socket.<anonymous> (node_modules/pg-protocol/dist/index.js:11:42)
✘ [fail]: seedFile works after schema changes Rejected promise returned by test
✘ src/backend/db/lib/seed.test.ts exited with a non-zero exit code: 1
─
seedFile works after schema changes
Rejected promise returned by test. Reason:
Error {
message: 'column "last_name" of relation "user" does not exist',
}
› Parser.parseErrorMessage (node_modules/pg-protocol/dist/parser.js:287:98)
› Parser.handlePacket (node_modules/pg-protocol/dist/parser.js:126:29)
› Parser.parse (node_modules/pg-protocol/dist/parser.js:39:38)
› Socket.<anonymous> (node_modules/pg-protocol/dist/index.js:11:42)
› PostgresConnection.executeQuery (node_modules/kysely/dist/cjs/dialect/postgres/postgres-driver.js:91:69)
› <anonymous> (node_modules/kysely/dist/cjs/query-executor/query-executor-base.js:37:28)
› DefaultConnectionProvider.provideConnection (node_modules/kysely/dist/cjs/driver/default-connection-provider.js:12:20)
› DefaultQueryExecutor.executeQuery (node_modules/kysely/dist/cjs/query-executor/query-executor-base.js:36:16)
› InsertQueryBuilder.execute (node_modules/kysely/dist/cjs/query-builder/insert-query-builder.js:517:24)
› InsertQueryBuilder.executeTakeFirst (node_modules/kysely/dist/cjs/query-builder/insert-query-builder.js:532:26)
› InsertQueryBuilder.executeTakeFirstOrThrow (node_modules/kysely/dist/cjs/query-builder/insert-query-builder.js:544:24)
› seed (src/backend/tests/seed.ts:6:17)
› Object.beforeTemplateIsBaked (src/backend/tests/fixtures/get-test-database.ts:21:24)
─
1 test failed
1 uncaught exception
src/backend/db/lib/seed.test.ts
Outdated
import { getDb } from "@/backend/db/lib/get-db"; | ||
import { seedfile } from "@/backend/db/lib/seed"; | ||
|
||
test("seedFile works after schema changes", async (t) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor suggestion: I think "seedFile works with current schema" would be a slightly better title. The "after schema changes" part could imply that the test itself is applying schema changes before running seedFile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the negative test to make sure it fails @mrabbitt .. awesome |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ✅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems pretty straightforward, and I can confirm in the debugger that students and users are what they're supposed to be. Looks good!
@mrabbitt I added a catch block, now the test fails more elegantly, if it fails: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ✅