Skip to content

fix: ignore undefined and null params on modifiers #403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
meteor: [1.12.2, 2.6.1, 2.7.3, 2.8.1, 2.12]
meteor: [1.12.2, 2.8.1, 2.12, 2.15]
redis-version: [4, 5, 6, 7]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Start Redis
uses: supercharge/[email protected]
Expand All @@ -26,7 +26,7 @@ jobs:
run: |
meteor create --release ${{ matrix.meteor }} --bare test
cd test
meteor npm i --save [email protected] simpl-schema chai
meteor npm i --save [email protected] simpl-schema@1.13.1 chai
- name: Test
working-directory: ./test
run: METEOR_PACKAGE_DIRS="../" TEST_BROWSER_DRIVER=puppeteer meteor test-packages --raw-logs --once --driver-package meteortesting:mocha ../
4 changes: 3 additions & 1 deletion lib/utils/getFields.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import isNil from "./isNil";

/**
* Taken from: https://github.com/Meteor-Community-Packages/meteor-collection-hooks/blob/master/collection-hooks.js#L194 and modified.
* @param mutator
Expand All @@ -7,7 +9,7 @@ export default function getFields(mutator) {
var fields = [];
var topLevelFields = [];

Object.entries(mutator).forEach(function ([op, params]) {
Object.entries(mutator).filter(([_, params]) => !isNil(params)).forEach(function ([op, params]) {
if (op[0] == '$') {
Object.keys(params).forEach(function (field) {
// record the field we are trying to change
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/isNil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function isNil(value) {
return value === null || value === undefined;
}
22 changes: 21 additions & 1 deletion lib/utils/testing/getFields.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,24 @@ describe('Unit # getFields', function () {
it('Should properly detected top level fields', function () {
// TODO
})
});

it('Should ignore null or undefined params', function () {
let fields = run({
$set: {
a: {
d: 1
},
'profile.test': 1
},
$inc: {
b: 1
},
$addToSet: undefined
}).fields;

assert.lengthOf(fields, 3);
assert.include(fields, 'a');
assert.include(fields, 'b');
assert.include(fields, 'profile.test');
})
});
3 changes: 2 additions & 1 deletion lib/utils/testing/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import './getFields.test';
import './extractIdsFromSelector.test';
import './extractIdsFromSelector.test';
import './isNil.test';
13 changes: 13 additions & 0 deletions lib/utils/testing/isNil.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { assert } from 'chai';
import run from '../isNil';

describe('Unit # isNil', function () {
it('Should work', function () {
assert.isTrue(run(null));
assert.isTrue(run(undefined));
assert.isFalse(run(1));
assert.isFalse(run('1'));
assert.isFalse(run({}));
assert.isFalse(run([]));
});
});
4 changes: 2 additions & 2 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'cultofcoders:redis-oplog',
version: '2.2.1',
version: '2.2.2',
// Brief, one-line summary of the package.
summary: "Replacement for Meteor's MongoDB oplog implementation",
// URL to the Git repository containing the source code for this package.
Expand All @@ -17,7 +17,7 @@ Npm.depends({
});

Package.onUse(function(api) {
api.versionsFrom(['1.12.2', '2.8.1', '2.12']);
api.versionsFrom(['1.12.2', '2.8.1', '2.13', '2.15']);
api.use([
'underscore',
'ecmascript',
Expand Down
Loading