package com.cloudhandson.vpdbackoffice.service;

import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.cloudhandson.vpdbackoffice.domain.setting.BackofficeSetting;
import com.cloudhandson.vpdbackoffice.mapper.SettingMapper;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.DefaultApplicationArguments;

class HmmRuntimeSettingsInitializerTest {

  @Test
  void removesOnlyTheRetiredKbOrdsSetting() {
    SettingMapper mapper = Mockito.mock(SettingMapper.class);
    when(mapper.findByKey(SettingService.ORDS_BASE_URL)).thenReturn(new BackofficeSetting(
        SettingService.ORDS_BASE_URL,
        "https://g329127dfd380ad-kbaipoc.adb.ap-osaka-1.oraclecloudapps.com/ords/"));

    new HmmRuntimeSettingsInitializer(mapper).run(new DefaultApplicationArguments());

    verify(mapper).deleteByKey(SettingService.ORDS_BASE_URL);
  }

  @Test
  void keepsAnOperatorConfiguredLegacyOrdsSetting() {
    SettingMapper mapper = Mockito.mock(SettingMapper.class);
    when(mapper.findByKey(SettingService.ORDS_BASE_URL)).thenReturn(new BackofficeSetting(
        SettingService.ORDS_BASE_URL, "https://ords.hmm.example/ords"));

    new HmmRuntimeSettingsInitializer(mapper).run(new DefaultApplicationArguments());

    verify(mapper, never()).deleteByKey(SettingService.ORDS_BASE_URL);
  }
}
