From 8c9d1e82bda4e5c5d26fe6b8d1af93a4e4c679ff Mon Sep 17 00:00:00 2001 From: doronrk Date: Sun, 3 Nov 2019 20:55:05 -0800 Subject: [PATCH 1/2] Add failing test --- lib/links/tests/client.test.js | 31 +++++++++++++++++++++++++++++++ package.js | 1 + 2 files changed, 32 insertions(+) create mode 100755 lib/links/tests/client.test.js diff --git a/lib/links/tests/client.test.js b/lib/links/tests/client.test.js new file mode 100755 index 00000000..fe7e2bd6 --- /dev/null +++ b/lib/links/tests/client.test.js @@ -0,0 +1,31 @@ +import { assert } from "chai"; + + +describe("Links Client Tests", function() { + + it("Test remove many", function() { + let PostCollection = new Mongo.Collection(null); + let CommentCollection = new Mongo.Collection(null); + + PostCollection.addLinks({ + comments: { + type: "many", + collection: CommentCollection, + field: "commentIds", + index: true, + } + }); + + let postId = PostCollection.insert({ text: "abc" }); + let commentId = CommentCollection.insert({ text: "abc" }); + + const link = PostCollection.getLink(postId, "comments"); + link.add(commentId); + assert.lengthOf(link.find().fetch(), 1); + + link.remove(commentId); + + assert.lengthOf(link.find().fetch(), 0); + }); + +}); diff --git a/package.js b/package.js index a7605d4b..1e076cb6 100755 --- a/package.js +++ b/package.js @@ -61,6 +61,7 @@ Package.onTest(function(api) { // LINKS api.addFiles("lib/links/tests/main.js", "server"); + api.addFiles("lib/links/tests/client.test.js", "client"); // EXPOSURE api.addFiles("lib/exposure/testing/server.js", "server"); From c65870c103ffd0618d396285eb3c2b17e439903e Mon Sep 17 00:00:00 2001 From: doronrk Date: Mon, 21 Oct 2019 14:28:24 -0700 Subject: [PATCH 2/2] Change LinkMany to use $pullAll instead of $pull This is a workaround for a limitation in the minimongo implementation of $pull that triggers an "Error: Unrecognized logical operator: $in" when removing an id from a list of ids. --- lib/links/linkTypes/linkMany.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/links/linkTypes/linkMany.js b/lib/links/linkTypes/linkMany.js index e47d46ba..273af2c5 100755 --- a/lib/links/linkTypes/linkMany.js +++ b/lib/links/linkTypes/linkMany.js @@ -72,8 +72,8 @@ export default class LinkMany extends Link { // update the db let modifier = { - $pull: { - [root]: nested.length > 0 ? {[nested.join('.')]: {$in: _ids}} : {$in: _ids}, + $pullAll: { + [root]: nested.length > 0 ? { [nested.join('.')]: _ids } : _ids, }, };