import { ConstructReadTangleUrl } from "https://esm.town/v/willthereader/ConstructReadTangleUrl";
import { fetchComments } from "https://esm.town/v/willthereader/fetchComments";
import { FilterCommentsVal } from "https://esm.town/v/willthereader/FilterCommentsVal";
import { logMessage } from "https://esm.town/v/willthereader/logMessage";
export const testFilteringCommentsVal = (() => {
const innerAsyncFunction = async () => {
logMessage("debug", "Initialization of innerAsyncFunction");
const lastRunAt = new Date("2013-10-14T16:07:01.000Z");
const url = ConstructReadTangleUrl({ post_id: "6525827c68f969000134e052" });
logMessage("info", "Fetching comments from the server");
const comments = await fetchComments(url);
const filteredComments = await FilterCommentsVal.filterComments(
comments,
lastRunAt,
);
if (
comments.length > 0 && comments.every((comment) => new Date(comment.date).getTime() >= lastRunAt.getTime())
) {
console.log("Test passed: Comments were filtered correctly.");
}
else {
console.error("Test failed: Comments were not filtered correctly.");
}
try {
const invalidComments = await FilterCommentsVal.filterComments(
null,
);
console.error(
"Test failed: An error should have been thrown for a null lastRunAt.",
);
}
catch (error) {
console.log(
"Test passed: Error was thrown correctly for a null lastRunAt.",
);
}
return filteredComments;
};
return innerAsyncFunction();
})();