Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

2.0 KB
Raw Blame
import test from "node:test";
import assert from "node:assert/strict";

import {
  NotionAuthError,
  NotionNotFoundError,
  NotionRateLimitError,
  NotionValidationError,
  NotionServerError,
  NotionTimeoutError,
} from "../../src/lib/notion/api.ts";

test("NotionAuthError has correct name", () => {
  const err = new NotionAuthError("bad token");
  assert.equal(err.name, "NotionAuthError");
  assert.equal(err.message, "bad token");
});

test("NotionNotFoundError has correct name", () => {
  const err = new NotionNotFoundError("not found");
  assert.equal(err.name, "NotionNotFoundError");
});

test("NotionRateLimitError has retryAfter property", () => {
  const err = new NotionRateLimitError("rate limited", 5);
  assert.equal(err.retryAfter, 5);
  assert.equal(err.name, "NotionRateLimitError");
});

test("NotionValidationError has correct name", () => {
  const err = new NotionValidationError("invalid");
  assert.equal(err.name, "NotionValidationError");
});

test("NotionServerError has correct name", () => {
  const err = new NotionServerError("server error");
  assert.equal(err.name, "NotionServerError");
});

test("NotionTimeoutError has correct name", () => {
  const err = new NotionTimeoutError("timed out");
  assert.equal(err.name, "NotionTimeoutError");
});

test("createNotionClient returns object with expected methods", async () => {
  const { createNotionClient } = await import("../../src/lib/notion/api.ts");
  const client = createNotionClient("test-token");
  assert.deepEqual(Object.keys(client), [
    "searchPagesAndDatabases",
    "getPage",
    "listBlockChildren",
    "queryDatabase",
    "getDatabase",
    "appendBlocks",
  ]);
  assert.equal(typeof client.searchPagesAndDatabases, "function");
  assert.equal(typeof client.getPage, "function");
  assert.equal(typeof client.listBlockChildren, "function");
  assert.equal(typeof client.queryDatabase, "function");
  assert.equal(typeof client.getDatabase, "function");
  assert.equal(typeof client.appendBlocks, "function");
});