import { describe, test } from "node:test"; import assert from "node:assert"; import { sum } from "lodash"; import * as dateFns from "date-fns"; import { clickhouseClient, knex } from "./databases"; const oneHourAgo = dateFns.format( dateFns.subHours(new Date(), 1), "yyyy-MM-dd hh:mm:ss" ); describe("Events", () => { test("has inserted events", async () => { const { data } = (await ( await clickhouseClient.query({ query: knex("events") .count("") .where("created_at", ">", oneHourAgo) .toString(), }) ).json()) as any; assert.notEqual(Number.parseInt(data[0]["count()"], 10), 0); }); test("events have a country", async () => { const { data } = (await ( await clickhouseClient.query({ query: knex("events") .count() .where("created_at", ">", oneHourAgo) .groupBy("geo_ip_country") .toString(), format: "JSON", }) ).json()) as any; assert.notEqual(sum(data.map((d) => Number.parseInt(d["count()"], 10))), 0); }); });