-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure multiple integration test suites can run πββοΈ (#85)
- Loading branch information
Showing
17 changed files
with
157 additions
and
85 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ node_modules | |
# Environment Variables | ||
|
||
.env | ||
.env.test | ||
|
||
# Turborepo | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DATABASE_URL=postgresql://colorstack:colorstack@localhost:5432/colorstack_test | ||
ENVIRONMENT=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
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
10 changes: 10 additions & 0 deletions
10
packages/core/src/infrastructure/database/test/setup.global.ts
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,10 @@ | ||
import { db } from '@/infrastructure/database'; | ||
import { migrate } from '../shared/migrate'; | ||
|
||
export async function setup() { | ||
await migrate({ db }); | ||
} | ||
|
||
export async function teardown() { | ||
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,45 @@ | ||
import { Transaction, sql } from 'kysely'; | ||
|
||
import { db } from '@/infrastructure/database'; | ||
|
||
import { DB } from 'kysely-codegen/dist/db'; | ||
import { TEST_COMPANY_1, TEST_COMPANY_2, TEST_COMPANY_3 } from './constants'; | ||
|
||
beforeEach(async () => { | ||
await db.transaction().execute(async (trx) => { | ||
await truncate(trx); | ||
await seed(trx); | ||
}); | ||
}); | ||
|
||
// Helpers | ||
|
||
/** | ||
* Truncates all tables in the database - wiping all rows, but does not affect | ||
* the schema itself. | ||
* | ||
* @see https://www.postgresql.org/docs/current/sql-truncate.html | ||
*/ | ||
async function truncate(trx: Transaction<DB>) { | ||
const tables = await db.introspection.getTables(); | ||
|
||
const names = tables | ||
.filter((table) => { | ||
// We don't want to wipe the kysely tables, which track migrations b/c | ||
// migrations should only be run once. | ||
return !table.name.includes('kysely_'); | ||
}) | ||
.map((table) => { | ||
return table.name; | ||
}) | ||
.join(', '); | ||
|
||
await sql`truncate table ${sql.raw(names)} cascade;`.execute(trx); | ||
} | ||
|
||
async function seed(trx: Transaction<DB>) { | ||
await trx | ||
.insertInto('companies') | ||
.values([TEST_COMPANY_1, TEST_COMPANY_2, TEST_COMPANY_3]) | ||
.execute(); | ||
} |
36 changes: 0 additions & 36 deletions
36
packages/core/src/infrastructure/database/vitest-environment-kysely.ts
This file was deleted.
Oops, something went wrong.
5 changes: 4 additions & 1 deletion
5
packages/core/src/modules/employment/use-cases/save-company-if-necessary.test.ts
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 |
---|---|---|
|
@@ -13,7 +13,7 @@ import { | |
StudentRemovedEmail, | ||
} from '@oyster/email-templates'; | ||
|
||
import { ENV } from '@/shared/env'; | ||
import { ENVIRONMENT } from '@/shared/env'; | ||
import { | ||
getNodemailerTransporter, | ||
getPostmarkInstance, | ||
|
@@ -43,7 +43,7 @@ const FROM_NOTIFICATIONS = 'ColorStack <[email protected]>'; | |
* own email account and send emails from there. | ||
*/ | ||
export async function sendEmail(input: EmailTemplate) { | ||
return match(ENV.ENVIRONMENT) | ||
return match(ENVIRONMENT) | ||
.with('development', () => { | ||
return sendEmailWithNodemailer(input); | ||
}) | ||
|
@@ -157,7 +157,7 @@ function getSubject(input: EmailTemplate): string { | |
}) | ||
.exhaustive(); | ||
|
||
const subjectWithEnvironment = match(ENV.ENVIRONMENT) | ||
const subjectWithEnvironment = match(ENVIRONMENT) | ||
.with('development', () => `[Development] ${subject}`) | ||
.with('production', 'test', () => subject) | ||
.exhaustive(); | ||
|
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
Oops, something went wrong.