package com.malk.benteler.controller;

import com.malk.benteler.dto.EiamTestResult;
import com.malk.benteler.dto.FormInstanceRequest;
import com.malk.benteler.service.BentelerYidaTestService;
import org.junit.Test;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
 * {@link EiamTestController} 参数兼容验证。
 */
public class EiamTestControllerTest {

    @Test
    public void markResultSuccess_usesQueryParameterWhenBodyIsEmpty() {
        BentelerYidaTestService service = mock(BentelerYidaTestService.class);
        when(service.markResultSuccess(anyString())).thenReturn(EiamTestResult.builder().build());
        EiamTestController controller = new EiamTestController(service);

        controller.markResultSuccess(null, "FINST_QUERY");

        verify(service).markResultSuccess("FINST_QUERY");
    }

    @Test
    public void markResultSuccess_prefersBodyParameter() {
        BentelerYidaTestService service = mock(BentelerYidaTestService.class);
        when(service.markResultSuccess(anyString())).thenReturn(EiamTestResult.builder().build());
        EiamTestController controller = new EiamTestController(service);
        FormInstanceRequest request = new FormInstanceRequest();
        request.setFormInstanceId("FINST_BODY");

        controller.markResultSuccess(request, "FINST_QUERY");

        verify(service).markResultSuccess("FINST_BODY");
    }
}
