Back

Version 66

11/8/2023
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";

// File: TestFilteringCommentsVal.js
export const testFilteringCommentsVal = (() => {
const innerAsyncFunction = async () => {
logMessage("debug", "Initialization of innerAsyncFunction");
const lastRunAt = new Date("2023-10-14T16:07:01.000Z");
// Construct the URL with the desired parameters
const url = ConstructReadTangleUrl(5, ["created_at DESC", "id DESC"], { post_id: "6525827c68f969000134e052" }, 1);
// Fetch the comments using the constructed URL
logMessage("info", "Fetching comments from the server");
const comments = await fetchComments(url);
// Now filter the fetched comments
const filteredComments = await FilterCommentsVal.filterComments(
comments,
lastRunAt,
);
console.log(typeof new Date(comment.date).getTime()); // Check type of comment date
console.log(typeof lastRunAt.getTime()); // Check type of 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(
Updated: December 5, 2023