Files
wekan/tests/attachmentDeleteGuard.test.cjs
T

47 lines
1.7 KiB
JavaScript

'use strict';
// Plain-Node regression guard (no Meteor) for issue #5282: deleting an
// attachment could log a client-side "Removed nonexistent document" exception
// even though the delete itself succeeded — the same publication-churn class
// as the fixed #3252 for comments and checklists, whose guards attachments
// never got.
// Run: node tests/attachmentDeleteGuard.test.cjs
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const repoRoot = path.resolve(__dirname, '..');
const read = rel => fs.readFileSync(path.join(repoRoot, rel), 'utf8');
const attachments = read('client/components/cards/attachments.js');
const comments = read('client/components/activities/comments.js');
let passed = 0;
function test(name, fn) {
fn();
passed += 1;
console.log(' ok -', name);
}
test('attachment delete only calls the server when the doc is still in the local cache', () => {
assert.ok(
/if \(this\._id && ReactiveCache\.getAttachment\(this\._id\)\) \{\s*\n\s*await Meteor\.callAsync\('removeAttachment', this\._id\);/.test(attachments),
'server removal must be guarded by a Minimongo presence check',
);
});
test('negative: no direct client collection removal remains in the delete handler', () => {
const handler = attachments.match(/'click \.js-confirm-delete'[\s\S]*?\n \}\),/);
assert.ok(handler, 'delete handler found');
const body = handler[0];
assert.doesNotMatch(body, /Attachments\.removeAsync/);
assert.strictEqual((body.match(/Meteor\.callAsync\('removeAttachment'/g) || []).length, 1);
});
test('the sibling #3252 guard for comments is still in place (same bug class)', () => {
assert.ok(/CardComments\.findOne\(commentId\)/.test(comments));
});
console.log(`\n${passed} tests passed`);