1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 20:59:30 +00:00

Added a mock DatabaseConnectionPool object for testing

This commit is contained in:
2022-01-20 17:01:59 +00:00
parent 58350e032f
commit 822b6b3115

View File

@@ -0,0 +1,28 @@
'use strict';
const DatabaseConnectionPool = require('./DatabaseConnectionPool');
const mockRunQuery = jest.fn((sql, params) => {
if (sql.slice(-1) !== ';')
throw new Error('Invalid query, needs ;');
// Execute as non-prepared if no params are supplied
if (typeof params === 'undefined') {
return {
sql: sql
};
}
return {
sql: sql,
params: params
};
});
jest.mock('./DatabaseConnectionPool', () => {
return jest.fn().mockImplementation(() => {
return { runQuery: mockRunQuery };
});
});
module.exports = DatabaseConnectionPool;