Files
stack/packages/cli/tests/org-delete.test.mjs
jason.woltje 047825460f Delete an organization after two confirmations
mosaic org delete ID --confirm ID --if-revision N, and POST /api/orgs/:id/delete,
mark the organization as deleting, stop its bus, move its files into
<dataRoot>/deleted/<ID>-<stamp>/ with a receipt, then drop it from the registry
and append deleted.log. A failure stops at its step and a rerun resumes. Bus
start refuses an organization that is being deleted. The settings page asks
twice: a panel that lists the effects, then typing the ID before Delete
permanently is enabled. Purge and remote revocation are follow-ups.
2026-11-07 22:22:05 -06:00

22 lines
1.6 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { chmodSync, mkdirSync, renameSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { fixture, tmp } from './helpers.mjs';
import { busStart, busStop, busStopForDelete } from '../src/org-bus.mjs';
import { createOrg, deleteOrg, templateRender } from '../../business/src/org-service.mjs';
test('deletion stops the recorded running bus before moving its runtime', { timeout: 60000 }, async t => {
const root = tmp(t, 'd-'), f = fixture(root), dir = join(root, '.config', 'mosaic-test');
mkdirSync(join(root, '.config'), { mode: 0o700 }); renameSync(join(root, 'config'), dir); chmodSync(dir, 0o700); chmodSync(join(dir, 'businesses'), 0o700);
writeFileSync(join(f.dataRoot, 'instance.json'), JSON.stringify({ instanceVersion: 1, name: 'test' }), { mode: 0o600 });
const env = { ...f.env, HOME: root, MOSAIC_CONFIG: join(dir, 'config.json') };
const ctx = { configDir: dir, dataRoot: f.dataRoot, instance: 'test', env, principal: { provider: 'local-dev', iss: 'local-dev', sub: 'local-dev-owner' } };
await createOrg(ctx, 'a', await templateRender('a'));
const started = await busStart(ctx, 'a', { detach: true, devLocalOwner: true, noLaunch: true });
t.after(async () => { try { await busStop(ctx, 'a'); } catch {} });
const receipt = await deleteOrg(ctx, 'a', { busStop: busStopForDelete, confirm: 'a', ifRevision: 1 });
assert.equal(receipt.bus.stopped, true); assert.equal(receipt.bus.pid, started.pid);
assert.ok(receipt.moves.some(move => move.from === started.root));
});