import { createAnonymousAccount } from './anonymous-account';

describe('createAnonymousAccount', () => {
  it('returns an object with username "anonymous"', () => {
    const account = createAnonymousAccount();
    expect(account.username).toBe('anonymous');
  });

  it('returns an object with isActive true', () => {
    const account = createAnonymousAccount();
    expect(account.isActive).toBe(true);
  });

  it('returns dPermissions.all as an empty array', () => {
    const account = createAnonymousAccount();
    expect(account.dPermissions.all).toEqual([]);
  });

  it('returns empty arrays for scopes, dApplicationCodes, dTenants, roles, tenants', () => {
    const account = createAnonymousAccount();
    expect(account.scopes).toEqual([]);
    expect(account.dApplicationCodes).toEqual([]);
    expect(account.dTenants).toEqual([]);
    expect(account.roles).toEqual([]);
    expect(account.tenants).toEqual([]);
  });

  it('returns sentinel string "anonymous" for id and null for other nullable fields', () => {
    const account = createAnonymousAccount();
    expect(account.id).toBe('anonymous');
    expect(account.clientId).toBeNull();
    expect(account.email).toBeNull();
    expect(account.meta).toBeNull();
    expect(account.user).toBeNull();
    expect(account.createdAt).toBeNull();
    expect(account.updatedAt).toBeNull();
    expect(account.deletedAt).toBeNull();
  });

  it('returns a fresh object on every call (not a shared reference)', () => {
    const a = createAnonymousAccount();
    const b = createAnonymousAccount();
    expect(a).not.toBe(b);
    // Mutating one should not affect the other
    a.dPermissions.all.push('some.permission');
    expect(b.dPermissions.all).toEqual([]);
  });

  it('conforms to the AuthenticatedAccount interface shape', () => {
    const account = createAnonymousAccount();
    // Verify all required fields are present
    expect(account).toHaveProperty('id');
    expect(account).toHaveProperty('clientId');
    expect(account).toHaveProperty('email');
    expect(account).toHaveProperty('username');
    expect(account).toHaveProperty('isActive');
    expect(account).toHaveProperty('scopes');
    expect(account).toHaveProperty('dApplicationCodes');
    expect(account).toHaveProperty('dPermissions');
    expect(account).toHaveProperty('dTenants');
    expect(account).toHaveProperty('meta');
    expect(account).toHaveProperty('roles');
    expect(account).toHaveProperty('tenants');
    expect(account).toHaveProperty('user');
    expect(account).toHaveProperty('createdAt');
    expect(account).toHaveProperty('updatedAt');
    expect(account).toHaveProperty('deletedAt');
  });
});
