import { isRoadService, roadKmPrice } from './road.util';

describe('road.util', () => {
  describe('isRoadService', () => {
    it('treats ROAD/TRUCK codes (and prefixes) as road', () => {
      expect(isRoadService({ code: 'ROAD' })).toBe(true);
      expect(isRoadService({ code: 'TRUCK' })).toBe(true);
      expect(isRoadService({ code: 'ROAD_CONTAINER' })).toBe(true);
      expect(isRoadService({ code: 'truck_forwarding' })).toBe(true);
    });

    it('treats rail / unknown / missing services as not road', () => {
      expect(isRoadService({ code: 'RAIL_CONTAINER' })).toBe(false);
      expect(isRoadService({ code: 'OFFROADING' })).toBe(false);
      expect(isRoadService(null)).toBe(false);
      expect(isRoadService(undefined)).toBe(false);
    });
  });

  describe('roadKmPrice', () => {
    it('multiplies distance by the per-km rate', () => {
      expect(roadKmPrice(120, 5)).toBe(600);
    });

    it('returns 0 when km or rate is missing/non-positive', () => {
      expect(roadKmPrice(null, 5)).toBe(0);
      expect(roadKmPrice(120, null)).toBe(0);
      expect(roadKmPrice(0, 5)).toBe(0);
      expect(roadKmPrice(120, 0)).toBe(0);
    });
  });
});
