Skip to content
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

Dev Tooling: Add Basic Test Suite Setup To Project #17

Merged

Conversation

klondikemarlen
Copy link
Member

@klondikemarlen klondikemarlen commented Aug 7, 2023

Fixes #16

Depends on:

Context

Create a basic test suite setup for the api.
Also created basic migration pipeline. It currently needs way more migrations and some kind of initial schema load, but I'm deferring that for now.

TODO

  • initialize enough tables and such to get a basic db test to pass. - Deferring to future date

Notes

  1. When using the native knex migrator, you must use snake casing for all table and column names. You must also supply the schema name.
  2. When using the db-client you get case conversion, but can't perform schema operations.

Testing Instructions

  1. dev test will watch the tests and re-run when a test is saved.
  2. Edit src/api/tests/db/db-client.test.ts and see that the test suite re-runs

Note the tests will fail, because the test database doesn't have enough tables or data to run on. This will be handled in future PRs.

@klondikemarlen klondikemarlen added the enhancement New feature or request label Aug 7, 2023
@klondikemarlen klondikemarlen self-assigned this Aug 7, 2023
@klondikemarlen klondikemarlen marked this pull request as draft August 7, 2023 19:25
@klondikemarlen
Copy link
Member Author

Might want to add a basic knex file and load that in the config.ts?
e.g.

import type { Knex } from "knex"

const DB_NAME = process.env.DB_NAME;
const DB_USER = process.env.DB_USER;
const DB_PASS = process.env.DB_PASS;
const DB_HOST = process.env.DB_HOST;
const DB_PORT = parseInt(process.env.DB_PORT || '1433')

const config: { [key: string]: Knex.Config } = {
  development: {
    client: "mssql",
    connection: {
      host: DB_HOST,
      user: DB_USER,
      password: DB_PASS,
      database: DB_NAME,
      port: DB_PORT,
    },
  },
  test: {
    client: "mssql",
    connection: {
      host: DB_HOST,
      user: DB_USER,
      password: DB_PASS,
      database: DB_NAME,
      port: DB_PORT,
    },
    migrations: {
      tableName: "knex_migrations",
    },
  },
}

module.exports = config

@klondikemarlen klondikemarlen changed the base branch from test to issue-14/dev-tooling-add-root-alias-support August 7, 2023 19:34
@klondikemarlen klondikemarlen changed the base branch from issue-14/dev-tooling-add-root-alias-support to test August 7, 2023 19:34
@klondikemarlen klondikemarlen force-pushed the issue-16/dev-tooling--add-basic-test-suite-setup-to-project branch from fb55b71 to 3d254a0 Compare August 7, 2023 19:37
@klondikemarlen klondikemarlen changed the base branch from test to issue-14/dev-tooling-add-root-alias-support August 7, 2023 19:38
Base automatically changed from issue-14/dev-tooling-add-root-alias-support to test August 8, 2023 22:16
@klondikemarlen klondikemarlen force-pushed the issue-16/dev-tooling--add-basic-test-suite-setup-to-project branch 3 times, most recently from e9d3ce3 to 228e549 Compare August 9, 2023 23:13
I'll probably need to add in extra stuff to handle testing express endpoints.
In the future the test database will be separate from the regular one.
> A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks. Active timers can also cause this, ensure that .unref() was called on them.

The database instance should probably be loaded globally or in some kind of helper and close globally as well, rather than just in this file.
I _want_ this to only run on app _boot_.
I also want to figure out how to set the default schema.
How? by using the hacked db schema instance instead.
This is clearly not a wining strategy.
…able.

It needs npm exec ts-node -r tsconfig-paths/register to run.
Use kebab case for file names.
Note: using default knex for schema migrations.
Note that I'm using the custom db client for backfilling as it has a cleaner interface.
Note that there are no migrations in the test setup, so all database tests will fail.
@klondikemarlen klondikemarlen force-pushed the issue-16/dev-tooling--add-basic-test-suite-setup-to-project branch from 52a33d1 to bdc04e7 Compare August 10, 2023 19:02
@klondikemarlen klondikemarlen marked this pull request as ready for review August 10, 2023 19:07
@klondikemarlen klondikemarlen force-pushed the issue-16/dev-tooling--add-basic-test-suite-setup-to-project branch from 31564a2 to 16b2066 Compare August 10, 2023 20:31
Why? They exist in production and the the Knex system will crash if it can't find all the migrations that it expects.

They can be deleted once the relevant rows are removed from the dbo.knex_migrations table in production.
This will create the `SFADB_DEV` and `sfa_client_test` databases.
Why? To avoid cluttering the repo with private mssql content.
@klondikemarlen klondikemarlen force-pushed the issue-16/dev-tooling--add-basic-test-suite-setup-to-project branch from bb0a0ea to 5eee5b4 Compare August 11, 2023 02:55
@klondikemarlen klondikemarlen force-pushed the issue-16/dev-tooling--add-basic-test-suite-setup-to-project branch from 069fc14 to 2fa28e2 Compare August 11, 2023 03:24
@datajohnson datajohnson merged commit cb85c9e into test Aug 11, 2023
@datajohnson datajohnson deleted the issue-16/dev-tooling--add-basic-test-suite-setup-to-project branch August 11, 2023 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dev Tooling: Add Basic Test Suite Setup To Project
2 participants