From d099e6999d9a709da48346610d081fdddac273eb Mon Sep 17 00:00:00 2001 From: Vardan Nadkarni Date: Wed, 25 Oct 2023 18:20:44 +0530 Subject: [PATCH] Added unit test to sqlite --- framework/tests/constants/transactionsSchema.js | 1 - framework/tests/unit/database/sqlite3.spec.js | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/framework/tests/constants/transactionsSchema.js b/framework/tests/constants/transactionsSchema.js index ecc16d0520..68129b7bab 100644 --- a/framework/tests/constants/transactionsSchema.js +++ b/framework/tests/constants/transactionsSchema.js @@ -16,7 +16,6 @@ module.exports = { tableName: 'transactions', primaryKey: 'id', - charset: 'utf8mb4', schema: { id: { type: 'string', null: false }, height: { type: 'integer', null: false }, diff --git a/framework/tests/unit/database/sqlite3.spec.js b/framework/tests/unit/database/sqlite3.spec.js index 319bbf5271..764ee4cf37 100644 --- a/framework/tests/unit/database/sqlite3.spec.js +++ b/framework/tests/unit/database/sqlite3.spec.js @@ -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(); }); @@ -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).toBe(transactionsTableConn); + }); }); describe('With IMPLICIT DB transaction (auto-commit mode)', () => {