const test = require("node:test");
const assert = require("node:assert/strict");
const { TOKEN_TTL_MS, generateOneTimeToken, digestOneTimeToken } = require("../src/security/oneTimeTokens");

test("one-time tokens are random, stored as digests, and expire", () => {
  const first = generateOneTimeToken(0);
  const second = generateOneTimeToken(0);

  assert.notEqual(first.token, second.token);
  assert.notEqual(first.token, first.digest);
  assert.equal(digestOneTimeToken(first.token), first.digest);
  assert.equal(first.expiresAt.getTime(), TOKEN_TTL_MS);
});
