/**
 * Unit tests for AnonymousAccountLoaderAdapter.
 *
 * Scenarios from spec.md:
 *   - loadById() resolves to the object produced by createAnonymousAccount()
 *   - loadById() ignores its argument (any accountId yields the same result)
 */

import { Test } from '@nestjs/testing';
import { createAnonymousAccount } from '../../../domain/anonymous-account';
import { AnonymousAccountLoaderAdapter } from './anonymous-account-loader.adapter';

describe('AnonymousAccountLoaderAdapter', () => {
  let adapter: AnonymousAccountLoaderAdapter;

  beforeEach(async () => {
    const moduleRef = await Test.createTestingModule({
      providers: [AnonymousAccountLoaderAdapter],
    }).compile();

    adapter = moduleRef.get(AnonymousAccountLoaderAdapter);
  });

  it('resolves to createAnonymousAccount() for any accountId', async () => {
    const result = await adapter.loadById('any-id');

    expect(result).toEqual(createAnonymousAccount());
  });

  it('ignores the accountId argument — returns the same anonymous account for different ids', async () => {
    const result1 = await adapter.loadById('id-1');
    const result2 = await adapter.loadById('id-2');
    const result3 = await adapter.loadById('');

    expect(result1).toEqual(createAnonymousAccount());
    expect(result2).toEqual(createAnonymousAccount());
    expect(result3).toEqual(createAnonymousAccount());
  });

  it('returns a fresh object per call (not a shared reference)', async () => {
    const result1 = await adapter.loadById('x');
    const result2 = await adapter.loadById('x');

    expect(result1).not.toBe(result2); // different object references
    expect(result1).toEqual(result2);  // same shape
  });
});
