Skip to content

Commit

Permalink
Merge pull request #397 from TradeWing/minimongo-pull-fix
Browse files Browse the repository at this point in the history
LinkMany $pull fix
  • Loading branch information
theodorDiaconu authored Nov 4, 2019
2 parents 41405a0 + c65870c commit 87f5a2a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/links/linkTypes/linkMany.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};

Expand Down
31 changes: 31 additions & 0 deletions lib/links/tests/client.test.js
Original file line number Diff line number Diff line change
@@ -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);
});

});
1 change: 1 addition & 0 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 87f5a2a

Please sign in to comment.