-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(countDistinct): countDistinctQuery
- Loading branch information
1 parent
0d436c7
commit 782493e
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
}); | ||
}); |