Skip to content

Commit

Permalink
Updates for auto-removal, works with forked collection-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Bero committed Feb 24, 2024
1 parent 5518fec commit 25fdbcd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
6 changes: 3 additions & 3 deletions lib/links/linkTypes/lib/smartArguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]>}
*/
async getIds(what, options) {
Expand All @@ -32,10 +32,10 @@ export default new (class {
/**
*
* @param {Grapher.IdSingleOption} what
* @param {Grapher.SmartArgumentsOptions} options
* @param {Grapher.SmartArgumentsOptions} [options]
* @returns {Promise<string | undefined>}
*/
async getId(what, options) {
async getId(what, options = {}) {
if (typeof what === 'string') {
return what;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/links/linker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]: {
Expand Down
16 changes: 6 additions & 10 deletions lib/links/tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });

Expand All @@ -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);
});
Expand Down Expand Up @@ -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' });
Expand Down Expand Up @@ -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(
Expand All @@ -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));

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 25fdbcd

Please sign in to comment.