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:
28
lib/__mocks__/DatabaseConnectionPool.js
Normal file
28
lib/__mocks__/DatabaseConnectionPool.js
Normal 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;
|
||||||
Reference in New Issue
Block a user