1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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("2013-10-14T16:07:01.000Z");
// Construct the URL with the desired parameters
const url = ConstructReadTangleUrl({ post_id: "6525827c68f969000134e052" });
// 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,
);
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 the filtered comments from innerAsyncFunction
};
return innerAsyncFunction();
})();
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
December 5, 2023