import { Test, TestingModule } from '@nestjs/testing';
import { ConfigService } from '@nestjs/config';
import { GeofencingService } from './geofencing.service';

describe('GeofencingService', () => {
  let service: GeofencingService;

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      providers: [
        GeofencingService,
        {
          provide: ConfigService,
          useValue: {
            get: (key: string) =>
              key === 'GEOFENCE_ARRIVAL_RADIUS_METERS' ? 100 : undefined,
          },
        },
      ],
    }).compile();

    service = module.get(GeofencingService);
  });

  it('uses configured arrival radius', () => {
    expect(service.arrivalRadiusMeters()).toBe(100);
  });

  it('allows arrival within radius', () => {
    const dest = { latitude: 28.6139, longitude: 77.209 };
    const near = { latitude: 28.614, longitude: 77.2091 };
    expect(service.canArrive(near, dest)).toBe(true);
  });
});
