Skip to content

Commit

Permalink
Add configuration to debug with VSCode
Browse files Browse the repository at this point in the history
minor fixes from eslint and yarn.lock
  • Loading branch information
manelcecs committed Oct 25, 2023
1 parent 4f69df7 commit 2c623d8
Show file tree
Hide file tree
Showing 8 changed files with 495 additions and 553 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@
/index.d.ts
/yarn-error.log
package-lock.json

# IDE artifacts
.vscode
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Jest Tests",
"type": "node",
"preLaunchTask": "start-containers",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/.bin/jest",
"--runInBand",
"--detectOpenHandles"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
13 changes: 13 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "start-containers",
"type": "shell",
"command": "${workspaceRoot}/test.sh",
"args": ["-oc"]
}
]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"yarn": ">=1.22.10"
},
"dependencies": {
"@types/knex": "^0.16.1",
"@types/lodash": "^4.14.194",
"@types/node-fetch": "2.6.3",
"fp-ts": "^2.14.0",
Expand Down
46 changes: 25 additions & 21 deletions tests/models/currency.spec.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import ContextProvider from "../testContext";
import ContextProvider from '../testContext';

const context = ContextProvider.Instance;

describe('Ensure creation of a currency', () => {

it('should be able to create a currency', async () => {

const trx = await context.conn?.transaction()!;

const currency = await context.models?.currency.create({
code: 'TST'
}, {trx})

expect(currency).toBeDefined();
expect(currency?.id).toBeDefined();
expect(currency?.code).toEqual('TST');

context.transactions = {
...context.transactions,
'create_currency': trx
}

})
})
it('should be able to create a currency', async () => {
if (!context.conn) {
throw new Error('Context connection is not defined');
}

const trx = await context.conn.transaction();

const currency = await context.models?.currency.create(
{
code: 'TST',
},
{ trx }
);

expect(currency).toBeDefined();
expect(currency?.id).toBeDefined();
expect(currency?.code).toEqual('TST');

context.transactions = {
...context.transactions,
create_currency: trx,
};
});
});
2 changes: 1 addition & 1 deletion tests/test-environment-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ afterEach(async () => {
await trx[key]?.rollback();
}
}
});
});
7 changes: 3 additions & 4 deletions tests/testContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export default class ContextProvider implements IContext {
transactions: Record<string, Knex.Transaction>;

private constructor() {
this.models = undefined;
this.conn = undefined;
this.transactions = undefined;
this.models = {} as Database;
this.transactions = {};
this.conn = {} as Knex;
}

public static get Instance(): ContextProvider {
Expand All @@ -34,7 +34,6 @@ export default class ContextProvider implements IContext {
const connection = await this.createDbTestConection();
this.conn = connection;
this.models = v4Models(this.conn);
this.transactions = {};
}

private async createDbTestConection(): Promise<Knex<any, unknown[]>> {
Expand Down
Loading

0 comments on commit 2c623d8

Please sign in to comment.