import { afterEach, describe, mock, test } from 'node:test';
import assert from 'node:assert/strict';

import db from '@/db/models';
import { seedDefaultContentForTenant } from '@/services/content_catalog_seed';

afterEach(() => {
  mock.restoreAll();
});

describe('seedDefaultContentForTenant', () => {
  test('seeds dashboard content at organization scope', async () => {
    const createdRows: Array<Record<string, unknown>> = [];

    mock.method(db.content_catalog, 'findOne', (async () => null) as typeof db.content_catalog.findOne);
    mock.method(db.content_catalog, 'create', (async (payload: Record<string, unknown>) => {
      createdRows.push(payload);
      return payload;
    }) as typeof db.content_catalog.create);

    await seedDefaultContentForTenant({
      level: 'organization',
      organizationId: 'org-1',
    });

    const quoteRow = createdRows.find((row) =>
      row.content_type === 'dashboard-encouraging-quotes',
    );

    assert.ok(quoteRow);
    assert.equal(quoteRow.organizationId, 'org-1');
    assert.equal(quoteRow.schoolId, null);
    assert.equal(quoteRow.campusId, null);
    assert.equal(quoteRow.classId, null);
    assert.equal(quoteRow.active, true);
  });
});
