Skip to content

Commit

Permalink
fix: argument checking
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeIbberson committed Mar 4, 2022
1 parent b219afa commit 50ac4b9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
31 changes: 15 additions & 16 deletions .github/workflows/nodejs.yml
Expand Up @@ -5,20 +5,19 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [8.x, 10.x, 12.x]
node-version: [12.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: yarn install, lint and test
run: |
yarn install
yarn lint
yarn test
- name: Coveralls
uses: coverallsapp/github-action@v1.0.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: yarn install, lint and test
run: |
yarn install
yarn lint
yarn test
- name: Coveralls
uses: coverallsapp/github-action@v1.0.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
16 changes: 16 additions & 0 deletions lib/__tests__/comparison.test.js
Expand Up @@ -264,4 +264,20 @@ describe('Comparison', () => {
});
});
});

describe('isAcceptableParam', () => {
it('should accept', () => {
expect(Comparison.isAcceptableParam('foo')).toBeFalsy();
expect(Comparison.isAcceptableParam(['foo'])).toBeTruthy();
expect(
Comparison.isAcceptableParam(['foo', { operand: '$or' }]),
).toBeTruthy();
expect(
Comparison.isAcceptableParam({ operand: '$or' }),
).toBeTruthy();
expect(
Comparison.isAcceptableParam(['foo', ['bar']]),
).toBeTruthy();
});
});
});
5 changes: 4 additions & 1 deletion lib/index.js
Expand Up @@ -129,7 +129,10 @@ class Comparison {

static isAcceptableParam(item) {
return (
(Array.isArray(item) && item.every((rule) => isString(rule))) ||
(Array.isArray(item) &&
item.every(
(rule) => isString(rule) || this.isAcceptableParam(rule),
)) ||
(isObject(item) && 'operand' in item)
);
}
Expand Down

0 comments on commit 50ac4b9

Please sign in to comment.