fix: Minor fixes in backlinks service (#1240)
This commit is contained in:
parent
9f8e7be755
commit
c41e6e0423
|
@ -72,17 +72,24 @@ export default class Backlinks {
|
|||
// delete any backlinks that were removed
|
||||
await Promise.all(
|
||||
removedLinkIds.map(async linkId => {
|
||||
const document = await Document.findByPk(linkId);
|
||||
await Backlink.destroy({
|
||||
where: {
|
||||
documentId: document.id,
|
||||
reverseDocumentId: event.documentId,
|
||||
},
|
||||
const document = await Document.findByPk(linkId, {
|
||||
paranoid: false,
|
||||
});
|
||||
if (document) {
|
||||
await Backlink.destroy({
|
||||
where: {
|
||||
documentId: document.id,
|
||||
reverseDocumentId: event.documentId,
|
||||
},
|
||||
});
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
if (currentRevision.title === previousRevision.title) {
|
||||
if (
|
||||
!previousRevision ||
|
||||
currentRevision.title === previousRevision.title
|
||||
) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,28 @@ beforeEach(flushdb);
|
|||
beforeEach(jest.resetAllMocks);
|
||||
|
||||
describe('documents.update', () => {
|
||||
test('should not fail on a document with no previous revisions', async () => {
|
||||
const otherDocument = await buildDocument();
|
||||
const document = await buildDocument({
|
||||
text: `[this is a link](${otherDocument.url})`,
|
||||
});
|
||||
|
||||
await Backlinks.on({
|
||||
name: 'documents.update',
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
actorId: document.createdById,
|
||||
data: { autosave: false },
|
||||
});
|
||||
|
||||
const backlinks = await Backlink.findAll({
|
||||
where: { reverseDocumentId: document.id },
|
||||
});
|
||||
|
||||
expect(backlinks.length).toBe(1);
|
||||
});
|
||||
|
||||
test('should create new backlink records', async () => {
|
||||
const otherDocument = await buildDocument();
|
||||
const document = await buildDocument();
|
||||
|
|
Reference in New Issue