Skip to content

Commit

Permalink
test(coverage): increase to 100% lines in table
Browse files Browse the repository at this point in the history
  • Loading branch information
afontainec committed Mar 1, 2021
1 parent 6f19e1a commit d87e56d
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 4 deletions.
6 changes: 2 additions & 4 deletions models/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,12 @@ class Table {
return this.buildQuery('count', search, 'all', options);
}

// // TODO: USE ADD WHERE AND ADD ADVANCE TO DO THIS QUERY
countGroupBy(groupBy, search, columns, options) {
countGroupBy(groupBy, search, options) {
options = options || {};
options.groupBy = groupBy;
return this.count(search, columns, options);
return this.count(search, options);
}

// // TODO: USE ADD WHERE AND ADD ADVANCE TO DO THIS QUERY
countIn(target, validOptions, query, options) {
query = query || {};
if (Array.isArray(validOptions)) query[target] = ['in', validOptions];
Expand Down
34 changes: 34 additions & 0 deletions test/models/table/count/countGroupBy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* global describe, it, before */
process.env.NODE_ENV = 'test';

// Require the dev-dependencies
const { assert } = require('chai');
const knex = require('../../../../knex');
const Coffee = require('../../../../models/coffee-example');


// Our parent block
describe('TABLE GATEWAY: countGroupBy', () => { // eslint-disable-line
before(async () => {
await knex.seed.run();
});

it('happy path', async () => {
const results = await Coffee.countGroupBy('price', { name: 'expensive' });
const expected = [
{ price: 110, count: 1 },
];
assert.deepEqual(results, expected);
});

it('options is defined', async () => {
const results = await Coffee.countGroupBy('price', {}, { orderBy: ['price', 'desc'] });
const expected = [
{ price: null, count: 1 },
{ price: 110, count: 1 },
{ price: 100, count: 2 },
];
assert.deepEqual(results, expected);
});

});
30 changes: 30 additions & 0 deletions test/models/table/count/countIn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* global describe, it, before */
process.env.NODE_ENV = 'test';

// Require the dev-dependencies
const { assert } = require('chai');
const knex = require('../../../../knex');
const Coffee = require('../../../../models/coffee-example');


// Our parent block
describe('TABLE GATEWAY: countIn', () => { // eslint-disable-line
before(async () => {
await knex.seed.run();
});

it('validOptions is not array', async () => {
const results = await Coffee.countIn('price', 110);
assert.equal(results, '1');
});

it('validOptions is array', async () => {
const results = await Coffee.countIn('price', [110, 100]);
assert.equal(results, '3');
});

it('hasQuery', async () => {
const results = await Coffee.countIn('price', [110, 100], { name: 'expensive' });
assert.equal(results, '1');
});
});
17 changes: 17 additions & 0 deletions test/models/table/toString.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* global describe, it */
process.env.NODE_ENV = 'test';

// Require the dev-dependencies
const { assert } = require('chai');
const Coffee = require('../../../models/coffee-example');


// Our parent block
describe('TABLE GATEWAY: countGroupBy', () => { // eslint-disable-line

it('happy path', async () => {
assert.equal(Coffee.toString(), 'coffee');
});


});

0 comments on commit d87e56d

Please sign in to comment.