/**
* Live tests against https://api.ird.ro. Skipped unless IRD_API_KEY is set
* (environment or ./.env); run with `npm run test:live`. Only read-only GET
* endpoints are exercised — nothing here mutates the account or charges
* credits beyond metered reads.
*/
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { createClient, credits, domains, ipfs, isApiError, p2p, sharing, vps } from '../../src/index.js';
import { caught, readApiKey } from '../helpers.js';
test('anonymous domain check', async () => {
const resp = await domains.check(createClient(), 'example.ro');
assert.equal(resp.domain, 'example.ro');
assert.equal(typeof resp.status, 'string');
});
test('authenticated read endpoints', async (t) => {
const key = await readApiKey();
if (!key) return t.skip('IRD_API_KEY not set');
const client = createClient({ apiKey: key });
await t.test('credits balance and prices', async () => {
const balance = await credits.balance(client);
assert.equal(typeof balance.total, 'string', 'money is a decimal string, never a JSON number');
assert.equal(typeof (await credits.prices(client)), 'object');
});
await t.test('domain check with key', async () => {
assert.equal((await domains.check(client, 'ird.ro')).status, 'registered');
});
await t.test('vps tiers and ipfs usage', async () => {
assert.ok(Array.isArray((await vps.listTiers(client)).tiers));
assert.equal(typeof (await ipfs.usage(client)), 'object');
});
await t.test('gateway domains carry their served-pin count', async () => {
const { domains: gateways } = await ipfs.listDomains(client);
assert.ok(Array.isArray(gateways));
for (const d of gateways) assert.ok(Number.isInteger(d.pin_count), d.domain);
const first = gateways[0];
if (!first) return;
const page = await ipfs.listDomainPins(client, first.id, { limit: 1 });
assert.ok(Number.isInteger(page.total));
assert.ok(Array.isArray(page.pins));
assert.equal(page.total, (await ipfs.listAllDomainPins(client, first.id)).length);
const e = await caught(() => ipfs.listDomainPins(client, '00000000-0000-0000-0000-000000000000'));
assert.ok(isApiError(e));
assert.equal(e.status, 404, 'an unknown gateway domain is a 404, not a silent empty page');
});
await t.test('p2p apps report their mailbox state', async () => {
for (const app of (await p2p.listApps(client)).apps) {
assert.equal(typeof app.mailbox_enabled, 'boolean', app.name);
assert.equal(typeof app.mailbox_open_mint, 'boolean', app.name);
assert.ok(app.mailbox_url === null || typeof app.mailbox_url === 'string');
}
const { usage } = await p2p.usage(client);
assert.ok(Number.isInteger(usage.cached_bytes));
assert.ok(Number.isInteger(usage.mailbox_bytes_total));
assert.equal(typeof usage.per_mb_hour_cached, 'string');
});
await t.test('a JWT-only endpoint answers an api error to an API key', async () => {
const e = await caught(() => sharing.listGrants(client));
assert.ok(isApiError(e));
assert.equal(e.status, 401);
});
});