import { Organisation, User } from '../models/user.model';
import { CustomerMapping } from './customer.mapping';
import { TestBed } from '@angular/core/testing';
import { DatePipe } from '@angular/common';

fdescribe('CustomerMapping', () => {
  let mapper: CustomerMapping;
  const mockUser: User = {
    id: 123,
    first_name: 'Vorname',
    last_name: 'Nachname',
    title: 'Dr',
    gender: 'Herr',

    email: 'test@test.de',
    phone_number: '017012345678',
    mobile_number: '019998765432',

    organisation: {
      name: 'Mock Org',
      department: 'Mock Dept.',
      vatId: '123',
    },

    delivery_addres: {
      id: 456,
      first_name: 'Vorname Addresse',
      last_name: 'Nachname Addresse',
      street: 'Test Strasse',
      streetNo: 12,
      zip: '80636',
      city: 'Munich',
      country: 'Deutschland',
    },
  };

  beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [DatePipe, CustomerMapping],
    });

    mapper = TestBed.inject(CustomerMapping);
  });

  it('should be created', () => {
    expect(mapper instanceof CustomerMapping).toBeTruthy();
  });

  describe('fromOrganisationToOrganisationDTO', () => {
    const mockOrganisation: Organisation = mockUser.organisation;
    it('should map the provided organisation (Organisation) to OrganisationDTO', () => {
      const result = mapper.fromOrganisationToOrganisationDTO(mockOrganisation);

      expect(result.vatId).toEqual(mockOrganisation.vatId);
      expect(result.department).toEqual(mockOrganisation.department);
      expect(result.name).toEqual(mockOrganisation.name);
    });
  });

  describe('fromUserToCommunicationDetails', () => {
    it('should map the provided user (User) to communication details (CommunicationDetailsDTO)', () => {
      const result = mapper.fromUserToCommunicationDetails(mockUser);

      expect(result.phone).toEqual(mockUser.phone_number);
      expect(result.mobile).toEqual(mockUser.mobile_number);
      expect(result.email).toEqual(mockUser.email);
    });
  });

  describe('fromUserToShippingAddressDTO', () => {
    it('should map the provided user (User) to shipping address (ShippingAddressDTO)', () => {
      const result = mapper.fromUserToShippingAddressDTO(mockUser);

      expect(result.title).toEqual(mockUser.delivery_addres.title);
      expect(result.gender).toEqual(2);
      expect(result.firstName).toEqual(mockUser.delivery_addres.first_name);
      expect(result.lastName).toEqual(mockUser.delivery_addres.last_name);
      expect(result.source).toEqual(mockUser.delivery_addres.id);
    });
  });
});
