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

import type { DataSource } from 'typeorm';

import { PaymentsWalletOrmMapper } from '../mappers/PaymentsWalletOrmMapper';
import { TypeOrmWalletRepository } from './TypeOrmWalletRepository';

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

    const repo = new TypeOrmWalletRepository(dataSource, mapper);

    expect(repo).toBeInstanceOf(TypeOrmWalletRepository);
    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 PaymentsWalletOrmMapper;

    const repo = new TypeOrmWalletRepository(dataSource, mapper);

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