-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: run database tests in CI (#174)
* use transactions for db tests * add mssql actions * convert offer-adapter tests to use parameter db * dotenv with path in config * set env ci db pwd * remove redundant jest config config * use db transaction context for delete-listing and get-listings-with-applicants * convert all tests to use transaction context * allow read commited snapshot to allow parallelised jest tests that uses transactions * use transaction context * run without parallelisation for now * move test config stuff out of application code and remove unused exports * clean up
- Loading branch information
1 parent
10ca334
commit f164a9f
Showing
28 changed files
with
2,481 additions
and
2,254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
LEASING_DATABASE__PASSWORD=Passw0rd! | ||
LEASING_DATABASE__HOST=localhost | ||
LEASING_DATABASE__USER=sa | ||
LEASING_DATABASE__PORT=1433 | ||
LEASING_DATABASE__DATABASE=tenants-leases-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ config.json | |
# Jetbrains IDE | ||
.idea/ | ||
|
||
.vscode/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import path from 'path' | ||
import knex from 'knex' | ||
|
||
import Config from '../src/common/config' | ||
|
||
export default async function migrate() { | ||
const db = knex({ | ||
client: 'mssql', | ||
connection: Config.leasingDatabase, | ||
useNullAsDefault: true, | ||
migrations: { | ||
tableName: 'migrations', | ||
directory: path.join(__dirname, '../migrations'), | ||
}, | ||
}) | ||
|
||
await db.migrate | ||
.latest() | ||
.then(() => { | ||
console.log('Migrations applied') | ||
}) | ||
.catch((error) => { | ||
console.error('Error applying migrations', error) | ||
}) | ||
|
||
await db.destroy() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import path from 'path' | ||
import knex from 'knex' | ||
|
||
import Config from '../src/common/config' | ||
|
||
export default async function teardown() { | ||
const db = knex({ | ||
client: 'mssql', | ||
connection: Config.leasingDatabase, | ||
useNullAsDefault: true, | ||
migrations: { | ||
tableName: 'migrations', | ||
directory: path.join(__dirname, '../migrations'), | ||
}, | ||
}) | ||
|
||
try { | ||
await db.migrate.rollback().then(() => { | ||
console.log('Migrations rolled back') | ||
}) | ||
} catch (error) { | ||
console.error('Error rolling back migrations:', error) | ||
} | ||
|
||
await db.destroy() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// Update with your config settings. | ||
|
||
require('dotenv').config() | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,11 @@ | ||
import knex from 'knex' | ||
import Config from '../../../common/config' | ||
import * as path from 'path' | ||
|
||
const getStandardConfig = () => ({ | ||
client: 'mssql', | ||
connection: Config.leasingDatabase, | ||
}) | ||
import Config from '../../../common/config' | ||
|
||
const getTestConfig = () => { | ||
return { | ||
export const createDbClient = () => | ||
knex({ | ||
client: 'mssql', | ||
connection: Config.leasingDatabase, | ||
useNullAsDefault: true, | ||
migrations: { | ||
tableName: 'migrations', | ||
directory: path.join(__dirname, '../../../../migrations'), | ||
}, | ||
} | ||
} | ||
|
||
const getConfigBasedOnEnvironment = () => { | ||
const environment = process.env.NODE_ENV || 'dev' | ||
return environment === 'test' ? getTestConfig() : getStandardConfig() | ||
} | ||
|
||
export const db = knex(getConfigBasedOnEnvironment()) | ||
|
||
const migrate = async () => { | ||
await db.migrate | ||
.latest() | ||
.then(() => { | ||
console.log('Migrations applied') | ||
}) | ||
.catch((error) => { | ||
console.error('Error applying migrations', error) | ||
}) | ||
} | ||
|
||
const teardown = async () => { | ||
console.log('Rolling back migrations') | ||
try { | ||
await db.migrate.rollback().then(() => { | ||
console.log('Migrations rolled back') | ||
}) | ||
} catch (error) { | ||
console.error('Error rolling back migrations:', error) | ||
} | ||
|
||
await db.destroy().then(() => { | ||
console.log('Database destroyed') | ||
}) | ||
} | ||
|
||
export { migrate, teardown } | ||
export const db = createDbClient() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.