Skip to content

Commit 9bb866d

Browse files
committed
chore: add test for ai comments
1 parent 715aa24 commit 9bb866d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

functions-v2/test/on-document-tagged.test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,33 @@ describe("onDocumentTagged", () => {
5151
});
5252
});
5353

54+
// Currently, the AI system writes to a comments collection under an empty document whose ID is the same as the
55+
// document key. This test should be removed (or updated) when the AI system is modified to write to a comments
56+
// collection under a complete metadata document like comments from human users are.
57+
test("should add new values when a new AI-generated comment is made", async () => {
58+
const wrapped = fft.wrap(onDocumentTagged);
59+
const commentRef = documentCollection.doc("doc-key").collection("comments").doc("ai-comment-1");
60+
61+
await commentRef.set({tags: ["ai-tag-1", "ai-tag-2"]});
62+
const event = {
63+
params: {
64+
root: "demo",
65+
space: "test",
66+
documentId: "doc-key",
67+
commentId: "ai-comment-1",
68+
},
69+
};
70+
await wrapped(event);
71+
72+
const docSnapshot = await documentCollection.doc("1234").get();
73+
const docData = docSnapshot.data();
74+
75+
expect(docData).toEqual({
76+
key: "doc-key",
77+
strategies: ["ai-tag-1", "ai-tag-2"],
78+
});
79+
});
80+
5481
test("should remove values from a document's strategies array when an existing comment is deleted", async () => {
5582
const wrapped = fft.wrap(onDocumentTagged);
5683
const commentRef1 = documentCollection.doc("1234").collection("comments").doc("5678");

0 commit comments

Comments
 (0)