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

Remove deprecated typeorm function and fix hanging test suite. #456

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
lint:
runs-on: ubuntu-latest
container:
image: node:18
image: node:20
steps:
- uses: actions/checkout@v4
- name: Cache and restore node_modules
Expand All @@ -36,7 +36,7 @@ jobs:
needs: [ lint ]
runs-on: ubuntu-latest
container:
image: node:18
image: node:20
steps:
- uses: actions/checkout@v4
- name: Cache and restore node_modules
Expand All @@ -62,7 +62,7 @@ jobs:
needs: [ lint ]
runs-on: ubuntu-latest
container:
image: node:18
image: node:20
services:
mariadb:
image: mariadb:lts
Expand Down Expand Up @@ -196,7 +196,7 @@ jobs:
STRIPE_WEBHOOK_SECRET: ${{ secrets.STRIPE_WEBHOOK_TEST_SECRET }}
SKIP_SQLITE_DEFAULTS: true
container:
image: node:18
image: node:20
services:
mariadb:
image: mariadb:lts
Expand Down
8 changes: 4 additions & 4 deletions src/database/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

import {
createConnection, DataSource,
DataSource,
} from 'typeorm';
import fs from 'fs';
import User from '../entity/user/user';
Expand Down Expand Up @@ -219,10 +219,10 @@ export let AppDataSource = new DataSource(options);

const Database = {
initialize: async () => {
if (AppDataSource && AppDataSource.isInitialized) return AppDataSource;
AppDataSource = await createConnection(options);
return AppDataSource;
if (AppDataSource.isInitialized) return AppDataSource;
return AppDataSource.initialize();
},
};

export default Database;

8 changes: 8 additions & 0 deletions test/root-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import * as mocha from 'mocha';
import sinon from 'sinon';
import nodemailer, { Transporter } from 'nodemailer';
import { AppDataSource } from '../src/database/database';

/**
* Object containing all global stubs that are set before each test case.
Expand All @@ -47,3 +48,10 @@ export const mochaHooks: mocha.RootHookObject = {
rootStubs?.mail.restore();
},
};


export const closeDBHook = {
after: async () => {
await AppDataSource.destroy();
},
};
2 changes: 1 addition & 1 deletion test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { PERSISTENT_TEST_DATABASES } from '../src/helpers/database';
import '../src/database/database';

// Root hooks
export { mochaHooks } from './root-hooks';
export { mochaHooks, closeDBHook } from './root-hooks';

use(chaiAsPromised);
use(chaiHttp);
Expand Down
Loading