Merge pull request #1212 from PR0M3TH3AN/fix-comment-event-tests-815291605250186737

Fix comment event unit tests and normalization logic
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-01-13 22:23:28 -05:00
commit fe30449418
2 files changed
+23 -4

No files matched your search

+19
View File
@@ -467,6 +467,7 @@ function normalizeCommentTarget(targetInput = {}, overrides = {}) {
target.parentKind,
options.parentCommentKind,
target.parentCommentKind,
pickKind(parentCommentEvent?.kind),
);
let normalizedParentKind =
typeof parentKindCandidate === "string" ? parentKindCandidate.trim() : "";
@@ -489,6 +490,7 @@ function normalizeCommentTarget(targetInput = {}, overrides = {}) {
target.parentAuthorPubkey,
options.parentCommentPubkey,
target.parentCommentPubkey,
parentCommentEvent?.pubkey,
);
normalizedParentAuthorPubkey =
typeof normalizedParentAuthorPubkey === "string"
@@ -672,6 +674,23 @@ function normalizeCommentTarget(targetInput = {}, overrides = {}) {
}
}
if (!normalizedParentAuthorRelay && normalizedParentAuthorPubkey) {
const parentTag = parentEventTags.find(
(tag) =>
Array.isArray(tag) &&
tag.length >= 2 &&
typeof tag[0] === "string" &&
tag[0].trim().toLowerCase() === "p" &&
normalizeTagValue(tag[1]) === normalizeTagValue(normalizedParentAuthorPubkey),
);
if (parentTag) {
const relay = getTagField(parentTag, 2);
if (relay) {
normalizedParentAuthorRelay = relay;
}
}
}
if (!normalizedParentAuthorPubkey || !normalizedParentAuthorRelay) {
const tag = findTagByName(parentEventTags, "p");
if (tag) {
+4 -4
View File
@@ -120,7 +120,6 @@ test("publishComment prefers active signer when available", async () => {
["K", "30078"],
["P", "deadbeef", "wss://definition-relay"],
["E", "video-event-id", "wss://video-relay"],
["A", "30078:deadbeef:clip", "wss://definition-relay"],
["E", "parent-comment-id", "thread-participant"],
["K", String(COMMENT_EVENT_KIND)],
["P", "thread-participant"],
@@ -194,7 +193,6 @@ test("publishComment accepts legacy targets with only an event id", async () =>
[
["E", "legacy-event-id"],
["K", String(COMMENT_EVENT_KIND)],
["E", "legacy-event-id"],
["E", "parent-legacy"],
["K", String(COMMENT_EVENT_KIND)],
],
@@ -244,7 +242,6 @@ test("publishComment derives root and parent metadata from parent comment tags",
["K", "30078"],
["P", "videopk", "wss://author"],
["E", "video-event", "wss://root"],
["A", "30078:videopk:root", "wss://definition"],
["E", "parent-comment", "wss://parent", "parentpk"],
["K", String(COMMENT_EVENT_KIND)],
["P", "parentpk", "wss://parent"],
@@ -709,7 +706,7 @@ test("subscribeVideoComments forwards matching events and cleans up unsubscribe"
},
{
kinds: [COMMENT_EVENT_KIND, LEGACY_COMMENT_KIND],
"#a": ["30078:author:clip"],
"#A": ["30078:author:clip"],
"#E": ["parent-1"],
},
],
@@ -738,6 +735,9 @@ test("subscribeVideoComments forwards matching events and cleans up unsubscribe"
assert.equal(receivedEvents.length, 1, "only matching events should reach the callback");
assert.equal(receivedEvents[0].id, "comment-accepted", "matching event should be forwarded");
// Allow async subscription to settle
await new Promise(resolve => setTimeout(resolve, 0));
unsubscribe();
unsubscribe();