fix: Error in backlinks service when updating an old document (pre v1)
This commit is contained in:
@@ -44,6 +44,14 @@ export default class Backlinks {
|
||||
order: [["createdAt", "desc"]],
|
||||
limit: 2,
|
||||
});
|
||||
|
||||
// before parsing document text we must make sure it's been migrated to
|
||||
// the latest version or the parser may fail on version differences
|
||||
await currentRevision.migrateVersion();
|
||||
if (previousRevision) {
|
||||
await previousRevision.migrateVersion();
|
||||
}
|
||||
|
||||
const previousLinkIds = previousRevision
|
||||
? parseDocumentIds(previousRevision.text)
|
||||
: [];
|
||||
|
||||
@@ -32,6 +32,32 @@ describe("documents.update", () => {
|
||||
expect(backlinks.length).toBe(1);
|
||||
});
|
||||
|
||||
test("should not fail when previous revision is different document version", async () => {
|
||||
const otherDocument = await buildDocument();
|
||||
const document = await buildDocument({
|
||||
version: null,
|
||||
text: `[ ] checklist item`,
|
||||
});
|
||||
|
||||
document.text = `[this is a link](${otherDocument.url})`;
|
||||
await document.save();
|
||||
|
||||
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
Block a user