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

Consistent SQL query formatting

This commit is contained in:
2022-02-25 14:44:35 +00:00
parent 2fac6e7aba
commit 57af81cc98
4 changed files with 87 additions and 23 deletions

View File

@@ -14,7 +14,13 @@ describe('DatabaseConnectionPool', () => {
test('Non prepared query should not execute with params', () => {
const dbp = new DatabaseConnectionPool();
const sql = `SELECT * FROM class;`;
const sql = `
select
*
from
class;
`;
dbp.runQuery(sql);
expect(dbp.runQuery.mock.results[0].value).toEqual({
@@ -25,7 +31,15 @@ describe('DatabaseConnectionPool', () => {
test('Prepared query should execute along with params', () => {
const dbp = new DatabaseConnectionPool();
const sql = `SELECT * FROM class where name = ?;`;
const sql = `
select
*
from
class
where
name = ?;
`;
const params = [ 'bob' ];
dbp.runQuery(sql, params);
@@ -38,7 +52,15 @@ describe('DatabaseConnectionPool', () => {
test('Query without trailing ; should throw error', () => {
const dbp = new DatabaseConnectionPool();
const sql = `SELECT * FROM class where name = ?`;
const sql = `
select
*
from
class
where
name = ?
`;
const params = [ 'bob' ];
expect(() => dbp.runQuery(sql, params)).toThrow();
@@ -47,7 +69,12 @@ describe('DatabaseConnectionPool', () => {
test('Query with whitespace after ; should not fail', ()=> {
const dbp = new DatabaseConnectionPool();
const sql = `SELECT * FROM class; `;
const sql = `
select
*
from
class;
`;
expect(() => dbp.runQuery(sql)).not.toThrow();
});
@@ -55,7 +82,14 @@ describe('DatabaseConnectionPool', () => {
test('Prepared query should fail if no params are given', () => {
const dbp = new DatabaseConnectionPool();
const sql = `SELECT * FROM class where name = ?;`;
const sql = `
select
*
from
class
where
name = ?;
`;
expect(() => dbp.runQuery(sql)).toThrow();
});
@@ -63,7 +97,14 @@ describe('DatabaseConnectionPool', () => {
test('Prepared query should fail if too many params given', () => {
const dbp = new DatabaseConnectionPool();
const sql = `SELECT * FROM class where name = ?;`;
const sql = `
select
*
from
class
where
name = ?;
`;
const params = [ 'bob', 'jim' ];
expect(() => dbp.runQuery(sql, params)).toThrow();
@@ -72,8 +113,16 @@ describe('DatabaseConnectionPool', () => {
test('Prepared query should fail if too few params given', () => {
const dbp = new DatabaseConnectionPool();
const sql = `SELECT * FROM class where name = ?
and classId = ? and subjectId = ?;`;
const sql = `
select
*
from
class
where
name = ?
and classId = ?
and subjectId = ?;
`;
const params = [ 'bob' ];
@@ -83,7 +132,12 @@ describe('DatabaseConnectionPool', () => {
test('Non-prepared query should fail if params given', () => {
const dbp = new DatabaseConnectionPool();
const sql = `SELECT * FROM class;`;
const sql = `
select
*
from
class;
`;
const params = [ 'bob', 'jim' ];