import { test } from "node:test";
import assert from "node:assert/strict";
import { DatabaseSync } from "node:sqlite";
import {
backfillShortIds,
createAddress,
deleteExpiredAndRevoked,
getCounters,
listActiveAddresses,
revokeAddress,
} from "../src/core/db.ts";
import { resolveAddressIdentifier } from "../src/core/commands.ts";
import { createDispatcher } from "../src/core/dispatch.ts";
import { handleInboundEmail } from "../src/core/email.ts";
import type { MailAdapter } from "../src/core/types.ts";
import { migrationFile, owner, schemaSql, testDb } from "./helpers.ts";
const DAY = 86400;
const RAW_MAIL = "From: s@e.com\r\nTo: x\r\nSubject: t\r\n\r\nbody";
function capturingAdapter(): { adapter: MailAdapter; delivered: () => number } {
let count = 0;
return {
adapter: {
name: "discord",
deliver: async () => { count++; return { success: true }; },
notify: async () => ({ success: true }),
},
delivered: () => count,
};
}
test("counters", async (t) => {
await t.test("count real creations and torches only", async () => {
const { db } = testDb();
const a = await createAddress(db, owner("u1"), "ex.com", DAY, false, null);
await createAddress(db, owner("u1"), "ex.com", DAY, false, null);
assert.equal((await getCounters(db)).created, 2);
await revokeAddress(db, owner("u1"), a);