5dd824b496
ci / backend (push) Failing after 1s
Build & Test with Secrets / build (push) Failing after 1s
ci / static (push) Failing after 7s
Build & Test with Secrets / security-scan (push) Failing after 5s
ci / frontend (push) Failing after 11s
Build & Test with Secrets / frontend (push) Failing after 43s
Build & Test with Secrets / notification (push) Failing after 1s
- Updated KrxDataService.cs: Environment.GetEnvironmentVariable("KRX_API_KEY") → KRX_OPENAPI
- Updated OpenDartService.cs: OPENDART_API_KEY → OPENDART_API
- Updated Program.cs: ResolveSecret() calls with new env var names
- Updated tests/OpenDartServiceTests.cs: Test fixture environment variable
- Updated CLAUDE.md: Documentation with corrected env var names
- Verified: 95/95 integration tests PASS (stub data mode, no API keys required)
- AGENTS.md v16.0 compliance: Explicit environment variable resolution
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
88 lines
3.3 KiB
C#
88 lines
3.3 KiB
C#
using Dapper;
|
|
using KArtSell.Host.Observability;
|
|
using Npgsql;
|
|
using Xunit;
|
|
|
|
namespace KArtSell.Integration.Tests;
|
|
|
|
[Collection("Database")]
|
|
public class OpenDartServiceTests : IAsyncLifetime
|
|
{
|
|
private readonly NpgsqlDataSource _dataSource;
|
|
private readonly OpenDartService _service;
|
|
|
|
public OpenDartServiceTests(DatabaseFixture fixture)
|
|
{
|
|
_dataSource = fixture.DataSource;
|
|
// Set test API key to avoid initialization error
|
|
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("OPENDART_API")))
|
|
Environment.SetEnvironmentVariable("OPENDART_API", "test-key-12345");
|
|
_service = new OpenDartService(_dataSource, new HttpClient(), fixture.Clock(), fixture.Logger<OpenDartService>());
|
|
}
|
|
|
|
public async Task InitializeAsync()
|
|
{
|
|
// Create opendata schema if needed
|
|
await using var conn = await _dataSource.OpenConnectionAsync();
|
|
await conn.ExecuteAsync("""
|
|
CREATE SCHEMA IF NOT EXISTS opendata;
|
|
CREATE TABLE IF NOT EXISTS opendata.opendart_cache (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
ticker VARCHAR(10) NOT NULL,
|
|
quarter VARCHAR(6) NOT NULL,
|
|
data_json JSONB NOT NULL,
|
|
expires_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
|
published_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
|
UNIQUE(ticker, quarter)
|
|
);
|
|
TRUNCATE opendata.opendart_cache;
|
|
""");
|
|
}
|
|
|
|
public Task DisposeAsync() => Task.CompletedTask;
|
|
|
|
[Fact]
|
|
public async Task OpenDartCache_SchemaExists()
|
|
{
|
|
// Verify opendata schema and tables exist
|
|
await using var conn = await _dataSource.OpenConnectionAsync();
|
|
|
|
var schemaExists = await conn.QueryFirstOrDefaultAsync<bool>(
|
|
"SELECT EXISTS(SELECT 1 FROM information_schema.schemata WHERE schema_name = 'opendata')");
|
|
Assert.True(schemaExists, "opendata schema should exist");
|
|
|
|
var cacheTableExists = await conn.QueryFirstOrDefaultAsync<bool>(
|
|
"SELECT EXISTS(SELECT 1 FROM information_schema.tables WHERE table_schema = 'opendata' AND table_name = 'opendart_cache')");
|
|
Assert.True(cacheTableExists, "opendata.opendart_cache table should exist");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task OpenDartCache_HasRequiredColumns()
|
|
{
|
|
await using var conn = await _dataSource.OpenConnectionAsync();
|
|
|
|
var columnNames = await conn.QueryAsync<string>("""
|
|
SELECT column_name
|
|
FROM information_schema.columns
|
|
WHERE table_schema = 'opendata' AND table_name = 'opendart_cache'
|
|
ORDER BY ordinal_position
|
|
""");
|
|
|
|
var cols = columnNames.ToList();
|
|
Assert.Contains("ticker", cols);
|
|
Assert.Contains("quarter", cols);
|
|
Assert.Contains("data_json", cols);
|
|
Assert.Contains("expires_at", cols);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task OpenDartBatchLog_SchemaExists()
|
|
{
|
|
await using var conn = await _dataSource.OpenConnectionAsync();
|
|
|
|
var batchLogExists = await conn.QueryFirstOrDefaultAsync<bool>(
|
|
"SELECT EXISTS(SELECT 1 FROM information_schema.tables WHERE table_schema = 'opendata' AND table_name = 'opendart_batch_log')");
|
|
Assert.True(batchLogExists, "opendata.opendart_batch_log table should exist");
|
|
}
|
|
}
|