import { runMainSeed } from './seed';
import { seedTranslations } from './seeds/translation.seed';
import { seedIssueMatrixFromSource } from './seeds/issue-matrix.seed';
import type { PrismaClient } from '../src/generated/prisma/client';

jest.mock('./seeds/translation.seed', () => ({ seedTranslations: jest.fn() }));
jest.mock('./seeds/issue-matrix.seed', () => ({ seedIssueMatrixFromSource: jest.fn() }));

describe('main seed on an existing database', () => {
  afterEach(() => jest.restoreAllMocks());

  it('adds missing translations without running bootstrap writes', async () => {
    const db = { user: { count: jest.fn().mockResolvedValue(5) } };
    jest.mocked(seedTranslations).mockResolvedValue({ total: 194, created: 194, kept: 0, modules: [] });
    jest.mocked(seedIssueMatrixFromSource).mockResolvedValue({ created: [] } as never);
    const log = jest.spyOn(console, 'log').mockImplementation(() => undefined);

    await runMainSeed(db as unknown as PrismaClient);

    expect(seedTranslations).toHaveBeenCalledWith(db);
    expect(seedIssueMatrixFromSource).toHaveBeenCalledWith(db, true);
    expect(log).toHaveBeenCalledWith('Translation seed: total=194, created=194, kept=0');
    // Only user.count exists on this fake: any bootstrap write would fail.
    expect(db.user.count).toHaveBeenCalledTimes(1);
  });
});
