Add originalDocumentId to sourceMetadata when duplicating documents (#10215)

- Added originalDocumentId property to SourceMetadata type
- Updated documentDuplicator to set originalDocumentId for both parent and child documents
- Added comprehensive tests to verify the functionality works correctly
- Preserves existing sourceMetadata while adding the new property

Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com>
This commit is contained in:
codegen-sh[bot]
2025-09-20 08:34:28 -04:00
committed by GitHub
parent fec16346db
commit 38beca412e
4 changed files with 78 additions and 2 deletions
@@ -106,4 +106,70 @@ describe("documentDuplicator", () => {
expect(response[0].color).toEqual(original.color);
expect(response[0].publishedAt).toBeNull();
});
it("should set originalDocumentId in sourceMetadata when duplicating", async () => {
const user = await buildUser();
const original = await buildDocument({
userId: user.id,
teamId: user.teamId,
sourceMetadata: { fileName: "test.md", externalId: "ext123" },
});
const response = await sequelize.transaction((transaction) =>
documentDuplicator({
document: original,
collection: original.collection,
user,
ctx: createContext({ user, transaction }),
})
);
expect(response).toHaveLength(1);
expect(response[0].sourceMetadata).toEqual({
fileName: "test.md",
externalId: "ext123",
originalDocumentId: original.id,
});
});
it("should set originalDocumentId for child documents when duplicating recursively", async () => {
const user = await buildUser();
const original = await buildDocument({
userId: user.id,
teamId: user.teamId,
});
const childDocument = await buildDocument({
userId: user.id,
teamId: user.teamId,
parentDocumentId: original.id,
collection: original.collection,
sourceMetadata: { fileName: "child.md" },
});
const response = await sequelize.transaction((transaction) =>
documentDuplicator({
document: original,
collection: original.collection,
user,
recursive: true,
ctx: createContext({ user, transaction }),
})
);
expect(response).toHaveLength(2);
// Check parent document
const duplicatedParent = response.find((doc) => !doc.parentDocumentId);
expect(duplicatedParent?.sourceMetadata?.originalDocumentId).toEqual(
original.id
);
// Check child document
const duplicatedChild = response.find((doc) => doc.parentDocumentId);
expect(duplicatedChild?.sourceMetadata?.originalDocumentId).toEqual(
childDocument.id
);
expect(duplicatedChild?.sourceMetadata?.fileName).toEqual("child.md");
});
});
+8
View File
@@ -52,6 +52,10 @@ export default async function documentDuplicator({
DocumentHelper.toProsemirror(document),
["comment"]
),
sourceMetadata: {
...document.sourceMetadata,
originalDocumentId: document.id,
},
...sharedProperties,
});
@@ -85,6 +89,10 @@ export default async function documentDuplicator({
DocumentHelper.toProsemirror(childDocument),
["comment"]
),
sourceMetadata: {
...childDocument.sourceMetadata,
originalDocumentId: childDocument.id,
},
...sharedProperties,
});
+2
View File
@@ -257,6 +257,8 @@ export type SourceMetadata = {
externalName?: string;
/** Whether the item was created through a trial license. */
trial?: boolean;
/** The ID of the original document when this document was duplicated. */
originalDocumentId?: string;
};
export type CustomTheme = {
+2 -2
View File
@@ -4135,7 +4135,7 @@
"@smithy/types" "^4.5.0"
tslib "^2.6.2"
"@smithy/node-config-provider@^4.1.4", "@smithy/node-config-provider@^4.2.1":
"@smithy/node-config-provider@^4.2.1":
version "4.2.1"
resolved "https://registry.yarnpkg.com/@smithy/node-config-provider/-/node-config-provider-4.2.1.tgz#31be8865dbea9a9f23aee278a6728317d0ed0250"
integrity sha512-AIA0BJZq2h295J5NeCTKhg1WwtdTA/GqBCaVjk30bDgMHwniUETyh5cP9IiE9VrId7Kt8hS7zvREVMTv1VfA6g==
@@ -4238,7 +4238,7 @@
dependencies:
tslib "^2.6.2"
"@smithy/url-parser@^4.0.5", "@smithy/url-parser@^4.1.1":
"@smithy/url-parser@^4.1.1":
version "4.1.1"
resolved "https://registry.yarnpkg.com/@smithy/url-parser/-/url-parser-4.1.1.tgz#0e9a5e72b3cf9d7ab7305f9093af5528d9debaf6"
integrity sha512-bx32FUpkhcaKlEoOMbScvc93isaSiRM75pQ5IgIBaMkT7qMlIibpPRONyx/0CvrXHzJLpOn/u6YiDX2hcvs7Dg==