import { readdirSync, readFileSync, statSync } from 'node:fs';
import { join } from 'node:path';
import { describe, expect, it } from 'vitest';

function sourceFiles(dir: string): string[] {
  return readdirSync(dir).flatMap((entry) => {
    const path = join(dir, entry);
    return statSync(path).isDirectory() ? sourceFiles(path) : path.endsWith('.ts') ? [path] : [];
  });
}

describe('cart persistence boundary', () => {
  it('stores no price, tax, discount or stock columns', () => {
    const migration = readFileSync(
      new URL('../../../../migrations/013_cart.js', import.meta.url),
      'utf8',
    );
    expect(migration).not.toMatch(/price|tax|vat|discount|stock/i);
  });

  it('does not import pricing or inventory internals', () => {
    const cartDir = new URL('..', import.meta.url);
    for (const file of sourceFiles(cartDir.pathname)) {
      const source = readFileSync(file, 'utf8');
      expect(source).not.toMatch(
        /modules\/(pricing|inventory)\/(api|application|domain|infrastructure|tests)/,
      );
    }
  });
});
