Skip to content

Commit

Permalink
test(countDistinct): countDistinctQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
afontainec committed Mar 7, 2021
1 parent 0d436c7 commit 782493e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/models/table/count/countDistinctQuery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* 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: countDistinctQuery', () => { // eslint-disable-line max-lines-per-function
before(async () => {
await knex.seed.run();
});

it('happy path', async () => {
const results = await Coffee.countDistinctQuery({}, { countDistinct: 'price' });
assert.deepEqual(results, [{ count: '3' }]);
});

it('With query', async () => {
const results = await Coffee.countDistinctQuery({ price: ['is not', null] }, { countDistinct: 'price' });
assert.deepEqual(results, [{ count: '2' }]);
});

it('options is undefined', () => {
try {
Coffee.countDistinctQuery({ price: ['is not', null] });
} catch (err) {
assert.equal(err.chinchayCode, 'missing_count_distinct');
}
});

it('options.countDistinct is undefined', () => {
try {
Coffee.countDistinctQuery({ price: ['is not', null] }, {});
} catch (err) {
assert.equal(err.chinchayCode, 'missing_count_distinct');
}
});
});

0 comments on commit 782493e

Please sign in to comment.