Skip to content

Commit

Permalink
Complete lib/query.js tests (#186)
Browse files Browse the repository at this point in the history
* Add query.js tests

* Istanbul ignore branch

The else path will never be taken because callbackToPromise which wraps
this function call will ensure there is always a `done` function.

* Remove unused if

callbackToPromise ensures there will always be a `done` function.

* Remove test for unused error code path

There is error checking for a plain object at `lib/table.js:63` and
`Query` is meant to be a private interface so this code path will never
be hit.

* Remove param validation from Query constructor

It is not used because validation id done with Query.validateParams in
`lib/table.js`.

* Remove checking that Query is a plain object

This checking is done in `lib/table.js` so it isn't needed here.

* Remove test for cellFormat

Move use of cellFormat into select test so that query.test.js can be
remove.
  • Loading branch information
PeterPan627 committed Jun 23, 2020
1 parent 29529e8 commit 4de934b
Show file tree
Hide file tree
Showing 2 changed files with 408 additions and 21 deletions.
25 changes: 6 additions & 19 deletions lib/query.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// istanbul ignore file
'use strict';

var isPlainObject = require('lodash/isPlainObject');
Expand All @@ -19,19 +18,11 @@ var has = require('./has');
/**
* Builds a query object. Won't fetch until `firstPage` or
* or `eachPage` is called.
*
* Params should be validated prior to being passed to Query
* with `Query.validateParams`.
*/
function Query(table, params) {
if (!isPlainObject(params)) {
throw new Error('Expected query options to be an object');
}

forEach(keys(params), function(key) {
var value = params[key];
if (!Query.paramValidators[key] || !Query.paramValidators[key](value).pass) {
throw new Error('Invalid parameter for Query: ' + key);
}
});

this._table = table;
this._params = params;

Expand Down Expand Up @@ -93,9 +84,7 @@ function eachPage(pageCallback, done) {
next = inner;
} else {
next = function() {
if (done) {
done(null);
}
done(null);
};
}

Expand Down Expand Up @@ -174,16 +163,14 @@ Query.paramValidators = {
/**
* Validates the parameters for passing to the Query constructor.
*
* @params {object} params parameters to validate
*
* @return an object with two keys:
* validParams: the object that should be passed to the constructor.
* ignoredKeys: a list of keys that will be ignored.
* errors: a list of error messages.
*/
Query.validateParams = function validateParams(params) {
if (!isPlainObject(params)) {
throw new Error('Expected query params to be an object');
}

var validParams = {};
var ignoredKeys = [];
var errors = [];
Expand Down
Loading

0 comments on commit 4de934b

Please sign in to comment.