Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico Gallinal committed Aug 13, 2022
1 parent 1257e97 commit f7aa16c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/getParanoidSql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ test('queries with union', () => {
);
});

test('queries with union sum', () => {
strictEqual(
getParanoidSql(
'SELECT SUM(v.qty) FROM (SELECT t.qty FROM t UNION ALL SELECT u.qty FROM u) AS v',
),
'SELECT SUM(`v`.`qty`) FROM (SELECT `t`.`qty` FROM `t` WHERE `t`.`deletedAt` IS NULL UNION ALL SELECT `u`.`qty` FROM `u` WHERE `u`.`deletedAt` IS NULL) AS `v`',
);
});

test('query with cte', () => {
strictEqual(
getParanoidSql(
Expand All @@ -92,6 +101,15 @@ test('arithmetic between queries', () => {
);
});

test('select case', () => {
strictEqual(
getParanoidSql(
`SELECT u.name, (SELECT CASE t.type WHEN 'a' THEN 1 WHEN 'b' THEN 2 ELSE 0 END FROM (SELECT u.type) AS t) AS code FROM u`,
),
"SELECT `u`.`name`, (SELECT CASE `t`.`type` WHEN 'a' THEN 1 WHEN 'b' THEN 2 ELSE 0 END FROM (SELECT `u`.`type`) AS `t`) AS `code` FROM `u` WHERE `u`.`deletedAt` IS NULL",
);
});

test('select case when exists', () => {
strictEqual(
getParanoidSql('SELECT CASE WHEN EXISTS (SELECT 1 FROM t) THEN 1 ELSE 0 END'),
Expand Down

0 comments on commit f7aa16c

Please sign in to comment.