Skip to content

Commit 2e8d257

Browse files
committed
fix: add tests
Signed-off-by: Muhammad Aaqil <[email protected]>
1 parent dfe831c commit 2e8d257

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/sql.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ describe('sql connector', function() {
256256
expect(orderBy).to.eql('ORDER BY `NAME`');
257257
});
258258

259+
it('builds group by with one field', function() {
260+
const groupBy = connector.buildGroupBy(['id']);
261+
expect(groupBy).to.eql('GROUP BY id');
262+
});
263+
259264
it('builds order by with two fields', function() {
260265
const orderBy = connector.buildOrderBy('customer', ['name', 'vip']);
261266
expect(orderBy).to.eql('ORDER BY `NAME`,`VIP`');
@@ -366,6 +371,28 @@ describe('sql connector', function() {
366371
});
367372
});
368373

374+
it('builds SELECT with groupBy, sum, avg, min, max & count', function() {
375+
const sql = connector.buildSelect('customer',
376+
{
377+
groupBy: ['name'],
378+
sum: 'salary',
379+
avg: 'salary',
380+
min: 'salary',
381+
max: 'salary',
382+
count: 'salary',
383+
});
384+
expect(sql.toJSON()).to.eql({
385+
sql: 'SELECT SUM(salary) as sumOfsalary, COUNT(salary) as countOfsalary,' +
386+
' AVG(salary) as avgOfsalary, MIN(salary) as minOfsalary,' +
387+
' MAX(salary) as maxOfsalary, `NAME`,`middle_name`,`LASTNAME`,`VIP`,' +
388+
'`primary_address`,`ADDRESS`' +
389+
' FROM `CUSTOMER`' +
390+
' GROUP BY name' +
391+
' ORDER BY `NAME`',
392+
params: [],
393+
});
394+
});
395+
369396
it('builds INSERT', function() {
370397
const sql = connector.buildInsert('customer', {name: 'John', vip: true});
371398
expect(sql.toJSON()).to.eql({

0 commit comments

Comments
 (0)