describe('AddNotificationTables1785600000000', () => {
  it('creates the notification and notification_recipient tables with their indexes and foreign keys', async () => {
    const migrationModule = require('./1785600000000-AddNotificationTables');
    const migration = new migrationModule.AddNotificationTables1785600000000();
    const queryRunner = { query: jest.fn() } as any;

    await migration.up(queryRunner);

    const calls: string[] = queryRunner.query.mock.calls.map((c: any) => c[0]);
    expect(calls).toHaveLength(7);
    expect(calls.some((sql) => sql.includes('CREATE TABLE "notification"'))).toBe(true);
    expect(calls.some((sql) => sql.includes('CREATE TABLE "notification_recipient"'))).toBe(
      true,
    );
    expect(calls.some((sql) => sql.includes('IDX_notification_team_id'))).toBe(true);
    expect(
      calls.some((sql) => sql.includes('IDX_notification_recipient_notification_id')),
    ).toBe(true);
    expect(calls.some((sql) => sql.includes('IDX_notification_recipient_user_id'))).toBe(
      true,
    );
    expect(calls.some((sql) => sql.includes('FK_notification_team'))).toBe(true);
    expect(calls.some((sql) => sql.includes('FK_notification_recipient_notification'))).toBe(
      true,
    );
  });

  it('drops both tables on down, recipient first to respect the foreign key', async () => {
    const migrationModule = require('./1785600000000-AddNotificationTables');
    const migration = new migrationModule.AddNotificationTables1785600000000();
    const queryRunner = { query: jest.fn() } as any;

    await migration.down(queryRunner);

    const calls: string[] = queryRunner.query.mock.calls.map((c: any) => c[0]);
    expect(calls).toEqual(['DROP TABLE "notification_recipient"', 'DROP TABLE "notification"']);
  });
});
