import { describe, it, expect } from 'vitest';
import { getRouteToCustomer } from './get-route-to-customer.helper';

describe('getRouteToCustomer', () => {
  it('should return route with tabId when provided', () => {
    const result = getRouteToCustomer(123);

    expect(result.path).toEqual([
      '/kunde',
      123,
      'customer',
      { outlets: { primary: 'search', side: 'search-customer-main' } },
    ]);
  });

  it('should filter out null tabId from path', () => {
    const result = getRouteToCustomer(null);

    expect(result.path).toEqual([
      '/kunde',
      'customer',
      { outlets: { primary: 'search', side: 'search-customer-main' } },
    ]);
    expect(result.path).not.toContain(null);
  });

  it('should always include customer type filter in query params', () => {
    const result = getRouteToCustomer(123);

    expect(result.queryParams).toEqual({
      filter_customertype: 'webshop&loyalty;loyalty&!webshop',
    });
  });

  it('should have consistent structure regardless of tabId', () => {
    const withTabId = getRouteToCustomer(456);
    const withoutTabId = getRouteToCustomer(null);

    expect(withTabId).toHaveProperty('path');
    expect(withTabId).toHaveProperty('queryParams');
    expect(withoutTabId).toHaveProperty('path');
    expect(withoutTabId).toHaveProperty('queryParams');
  });

  it('should include outlets configuration in path', () => {
    const result = getRouteToCustomer(789);
    const outletsConfig = result.path[3] as { outlets: { primary: string; side: string } };

    expect(outletsConfig.outlets).toBeDefined();
    expect(outletsConfig.outlets.primary).toBe('search');
    expect(outletsConfig.outlets.side).toBe('search-customer-main');
  });
});
