import assert from 'node:assert/strict';
import test from 'node:test';
import { assertFileExists, readText } from './helpers.ts';

test('reset and reseed APIs exist', () => {
  for (const route of [
    'src/app/api/setup/reset/preview/route.ts',
    'src/app/api/setup/reset/execute/route.ts',
    'src/app/api/setup/reseed/preview/route.ts',
    'src/app/api/setup/reseed/execute/route.ts'
  ]) {
    assertFileExists(route);
  }
});

test('reset guard blocks production and requires preview token semantics', () => {
  const guards = readText('src/features/setup/server/reset-guards.ts');
  const reset = readText('src/features/setup/server/reset.service.ts');

  assert.match(guards, /NODE_ENV=production/);
  assert.match(guards, /production-like database/);
  assert.match(reset, /validateConfirmationToken/);
  assert.match(reset, /confirmationPhrase/);
});

test('unsafe reset scopes are intentionally blocked', () => {
  const reset = readText('src/features/setup/server/reset.service.ts');

  for (const phrase of ['Full reset is not exposed', 'Demo/UAT reset requires', 'CSV import rollback requires']) {
    assert.match(reset, new RegExp(phrase));
  }
});
