import { AssignedPayerDTO, EntityDTOContainerOfPayerDTO } from '@swagger/crm';
import { AssignedPayerHelper } from './assigned-payer.helper';

describe('AssignedPayerHelper', () => {
  describe('getDefaultAssignedPayer', () => {
    it('should return undefined if the parameter is not an array', () => {
      let result = AssignedPayerHelper.getDefaultAssignedPayer(undefined);
      expect(result).toBeUndefined();
    });

    it('should return undefined if it is called with an empty array', () => {
      let result = AssignedPayerHelper.getDefaultAssignedPayer([]);
      expect(result).toBeUndefined();
    });

    it('should return the object with the latest Date in the isDefault Property', () => {
      let assignedPayers: AssignedPayerDTO[] = [
        { payer: { data: { id: 1 } } as EntityDTOContainerOfPayerDTO, isDefault: '2021-01-12T13:32:55.295Z' },
        { payer: { data: { id: 2 } } as EntityDTOContainerOfPayerDTO },
        { payer: { data: { id: 3 } } as EntityDTOContainerOfPayerDTO, isDefault: '2021-01-12T13:34:42.336Z' },
      ];

      let result = AssignedPayerHelper.getDefaultAssignedPayer(assignedPayers);
      expect(result.payer.data.id).toBe(3);
    });
  });
});
