Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Added unit test to sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
vardan10 committed Oct 25, 2023
1 parent 157225b commit 993489b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 0 additions & 1 deletion framework/tests/constants/transactionsSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
module.exports = {
tableName: 'transactions',
primaryKey: 'id',
charset: 'utf8mb4',
schema: {
id: { type: 'string', null: false },
height: { type: 'integer', null: false },
Expand Down
15 changes: 15 additions & 0 deletions framework/tests/unit/database/sqlite3.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,29 @@ const {
} = require('../../../src/database/sqlite3');

const schema = require('../../constants/blocksSchema');
const transactionsSchema = require('../../constants/transactionsSchema');

const tableName = 'functional_test';
const transactionsTableName = 'transactions_functional_test';

const testDir = 'testDir';

schema.tableName = tableName;
transactionsSchema.tableName = transactionsTableName;

const getTable = () => getTableInstance(schema, testDir);
const getTransactionsTable = () => getTableInstance(transactionsSchema, testDir);

const { blockWithoutTransaction, blockWithTransaction } = require('../../constants/blocks');

describe('Test sqlite3 implementation', () => {
// eslint-disable-next-line no-unused-vars
let transactionsTable;
let testTable;

beforeAll(async () => {
// Create table
transactionsTable = await getTransactionsTable();
testTable = await getTable();
});

Expand All @@ -50,6 +59,12 @@ describe('Test sqlite3 implementation', () => {
const result = await testTable.find();
expect(result.length).toBe(0);
});

it('should return same connection for two different table from same db', async () => {
const functionalTableConn = await getDBConnection(tableName, testDir);
const transactionsTableConn = await getDBConnection(transactionsTableName, testDir);
expect(functionalTableConn === transactionsTableConn);
});
});

describe('With IMPLICIT DB transaction (auto-commit mode)', () => {
Expand Down

0 comments on commit 993489b

Please sign in to comment.