package com.cloudhandson.vpdbackoffice.service;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;

import org.junit.jupiter.api.Test;
import org.springframework.jdbc.core.JdbcTemplate;

class StructuredDataServiceTest {

  private final StructuredDataService service = new StructuredDataService(mock(JdbcTemplate.class));

  @Test
  void exposesOnlyTheSevenApprovedStructuredTables() {
    assertThat(service.tables())
        .extracting(table -> table.tableName())
        .containsExactly(
            "KB_CUSTOMERS",
            "KB_PRODUCTS",
            "KB_CONTRACTS",
            "KB_COVERAGES",
            "KB_CLAIMS",
            "KB_EXTERNAL_HOLDINGS",
            "KB_STAKEHOLDERS");
  }

  @Test
  void rejectsAnyTableOutsideTheServerSideAllowlist() {
    assertThatThrownBy(() -> service.requireTable("KB_SECURITY_AUDIT_LOG"))
        .isInstanceOf(AppException.class)
        .hasMessage("선택할 수 없는 정형 데이터 테이블입니다.");
  }
}
