import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import request from 'supertest';
import { App } from 'supertest/types';
import { configureApplication } from '../app.config';
import { TravelController } from './travel.controller';
import { TravelService } from './travel.service';

describe('TravelController request validation', () => {
  let app: INestApplication<App>;

  beforeEach(async () => {
    const module = await Test.createTestingModule({
      controllers: [TravelController],
      providers: [
        {
          provide: TravelService,
          useValue: {
            startTravel: () => Promise.resolve({ status: 'TRAVELLING' }),
            completeTravelIfDue: () => Promise.resolve({ status: 'IDLE' }),
          },
        },
      ],
    }).compile();

    app = module.createNestApplication<App>();
    configureApplication(app);
    await app.init();
  });

  afterEach(async () => {
    await app.close();
  });

  it('rejects server-owned travel timing and duration fields', async () => {
    await request(app.getHttpServer())
      .post('/api/travel')
      .send({
        targetLocationId: BURNED_ROAD_ID,
        startedAt: '2026-08-18T10:00:00.000Z',
        arrivesAt: '2026-08-18T10:00:10.000Z',
        travelDurationSeconds: 10,
      })
      .expect(400);
  });
});

const BURNED_ROAD_ID = '20000000-0000-4000-8000-000000000002';
