diff --git a/lib/links/linkTypes/lib/smartArguments.js b/lib/links/linkTypes/lib/smartArguments.js index b1169390..b8b34841 100644 --- a/lib/links/linkTypes/lib/smartArguments.js +++ b/lib/links/linkTypes/lib/smartArguments.js @@ -9,7 +9,7 @@ export default new (class { /** * Extracts the ids of object(s) or strings and returns an array. * @param {Grapher.IdOption} what - * @param {Grapher.SmartArgumentsOptions} options + * @param {Grapher.SmartArgumentsOptions} [options] * @returns {Promise} */ async getIds(what, options) { @@ -32,10 +32,10 @@ export default new (class { /** * * @param {Grapher.IdSingleOption} what - * @param {Grapher.SmartArgumentsOptions} options + * @param {Grapher.SmartArgumentsOptions} [options] * @returns {Promise} */ - async getId(what, options) { + async getId(what, options = {}) { if (typeof what === 'string') { return what; } diff --git a/lib/links/linker.js b/lib/links/linker.js index dc89921d..863c3551 100644 --- a/lib/links/linker.js +++ b/lib/links/linker.js @@ -405,7 +405,7 @@ export default class Linker { if (!this.isVirtual()) { this.mainCollection.after.remove(async (userId, doc) => { - const ids = smartArguments.getIds(doc[this.linkStorageField]); + const ids = await smartArguments.getIds(doc[this.linkStorageField]); if (ids.length > 0) { await this.getLinkedCollection().removeAsync({ [this.foreignIdentityField]: { diff --git a/lib/links/tests/main.js b/lib/links/tests/main.js index c8564d2c..d5d12a03 100644 --- a/lib/links/tests/main.js +++ b/lib/links/tests/main.js @@ -287,7 +287,7 @@ describe('Collection Links', function () { assert.lengthOf(result, 1); }); - it.skip('Tests inversedBy findings', async function () { + it('Tests inversedBy findings', async function () { let postId = await PostCollection.insertAsync({ text: 'abc' }); let commentId = await CommentCollection.insertAsync({ text: 'abc' }); @@ -314,7 +314,7 @@ describe('Collection Links', function () { post = await PostCollection.findOneAsync(postId); const removeRes = await CommentCollection.removeAsync(comment._id); - // TODO(v3): not working, meteor-collection-hooks is not working + post = await PostCollection.findOneAsync(postId); assert.notInclude(post.commentIds, comment._id); }); @@ -344,8 +344,7 @@ describe('Collection Links', function () { assert.isObject(found); }); - // TODO(v3): collection hooks - it.skip('Should auto-remove some objects', async function () { + it('Should auto-remove some objects', async function () { let comment = { text: 'abc' }; let postId = await PostCollection.insertAsync({ text: 'hello' }); @@ -452,7 +451,7 @@ describe('Collection Links', function () { } }); - it.skip('Should work with autoremoval from inversed and direct link', async function () { + it('Should work with autoremoval from inversed and direct link', async function () { // autoremoval from direct side let postId = await PostCollection.insertAsync({ text: 'autoremove' }); const postAutoRemoveCommentsLink = await PostCollection.getLink( @@ -467,7 +466,6 @@ describe('Collection Links', function () { let commentId = comments[0]._id; assert.isObject(await CommentCollection.findOneAsync(commentId)); - // TODO(v3): collection hooks await PostCollection.removeAsync(postId); assert.isUndefined(await CommentCollection.findOneAsync(commentId)); @@ -573,14 +571,13 @@ describe('Collection Links', function () { assert.lengthOf(await inversedLink.find().fetchAsync(), 0); }); - it.skip('Auto-removes for foreign field - many', async function () { + it('Auto-removes for foreign field - many', async function () { await SCDCollection.insertAsync({ _id: '1', originalId: '1' }); await SCDCollection.insertAsync({ _id: '2', originalId: '1' }); await ReferenceCollection.insertAsync({ scdId: '1' }); // assert.equal(ReferenceCollection.find().count(), 0); - // TODO(v3): collection hooks await SCDCollection.removeAsync('1'); assert.equal(await ReferenceCollection.find().countAsync(), 0); @@ -611,13 +608,12 @@ describe('Collection Links', function () { assert.lengthOf(await inversedLink.find().fetchAsync(), 0); }); - it.skip('Auto-removes for foreign field - one', async function () { + it('Auto-removes for foreign field - one', async function () { await SCDCollection.insertAsync({ _id: '1', someId: '1' }); await ReferenceCollection.insertAsync({ some2Id: '1' }); await ReferenceCollection.insertAsync({ some2Id: '2' }); - // TODO(v3): collection hooks await SCDCollection.removeAsync('1'); assert.equal(await ReferenceCollection.find().countAsync(), 1);