add decrement replies count on delete note and a test for that
This commit is contained in:
Ehsan Javadynia 2022-03-22 14:48:33 +01:00 committed by GitHub
parent ba9563b983
commit 08bace6c7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View File

@ -29,6 +29,10 @@ export default async function(user: User, note: Note, quiet = false) {
Notes.decrement({ id: note.renoteId }, 'score', 1); Notes.decrement({ id: note.renoteId }, 'score', 1);
} }
if (note.replyId) {
await Notes.decrement({ id: note.replyId }, 'repliesCount', 1);
}
if (!quiet) { if (!quiet) {
publishNoteStream(note.id, 'deleted', { publishNoteStream(note.id, 'deleted', {
deletedAt: deletedAt, deletedAt: deletedAt,

View File

@ -333,4 +333,36 @@ describe('Note', () => {
assert.strictEqual(res.status, 400); assert.strictEqual(res.status, 400);
})); }));
}); });
describe('notes/delete', () => {
it('delete a reply', async(async () => {
const mainNoteRes = await request('/notes/create', {
text: 'main post',
}, alice);
const replyOneRes = await request('/notes/create', {
text: 'reply one',
replyId: mainNoteRes.body.createdNote.id
}, alice);
const replyTwoRes = await request('/notes/create', {
text: 'reply two',
replyId: mainNoteRes.body.createdNote.id
}, alice);
const deleteOneRes = await request('/notes/delete', {
noteId: replyOneRes.body.createdNote.id,
}, alice);
assert.strictEqual(deleteOneRes.status, 204);
let mainNote = await Notes.findOne({id: mainNoteRes.body.createdNote.id});
assert.strictEqual(mainNote.repliesCount, 1);
const deleteTwoRes = await request('/notes/delete', {
noteId: replyTwoRes.body.createdNote.id,
}, alice);
assert.strictEqual(deleteTwoRes.status, 204);
mainNote = await Notes.findOne({id: mainNoteRes.body.createdNote.id});
assert.strictEqual(mainNote.repliesCount, 0);
}));
});
}); });