import { describe, expect, it } from 'vitest';

import type { DataSource } from 'typeorm';

import { PaymentsPaymentOrmMapper } from '../mappers/PaymentsPaymentOrmMapper';
import { TypeOrmPaymentRepository } from './TypeOrmPaymentRepository';

describe('TypeOrmPaymentRepository', () => {
  it('constructor requires injected mapper (no internal mapper instantiation)', () => {
    const dataSource = {} as unknown as DataSource;
    const mapper = {} as unknown as PaymentsPaymentOrmMapper;

    const repo = new TypeOrmPaymentRepository(dataSource, mapper);

    expect(repo).toBeInstanceOf(TypeOrmPaymentRepository);
    expect((repo as unknown as { mapper: unknown }).mapper).toBe(mapper);
  });

  it('works with mocked TypeORM DataSource (no DB required)', async () => {
    const findOne = async () => null;

    const dataSource = {
      getRepository: () => ({ findOne }),
    } as unknown as DataSource;

    const mapper = {
      toDomain: () => {
        throw new Error('should-not-be-called');
      },
    } as unknown as PaymentsPaymentOrmMapper;

    const repo = new TypeOrmPaymentRepository(dataSource, mapper);

    await expect(repo.findById('payment-1')).resolves.toBeNull();
  });
});
