summaryrefslogtreecommitdiff
path: root/tests/FundLab.Api.Tests
diff options
context:
space:
mode:
authorSomhairle H. Marisol <[email protected]>2026-09-20 22:59:00 +0800
committerSomhairle H. Marisol <[email protected]>2026-09-20 22:59:00 +0800
commitc60905e9e7f992a7f8c79c3812e92a44b2d606f5 (patch)
treea895bc6f0ebe669407ffe4d1a11439e03a6fe0d4 /tests/FundLab.Api.Tests
downloadfund-lab-c60905e9e7f992a7f8c79c3812e92a44b2d606f5.tar.gz
feat(core): 建立 fund-lab 可运行基线
[变更性质] - 本提交冻结当前可构建、可测试的应用基线,不包含 PostgreSQL 持久化。 [新增功能] - 建立 F# Domain、API、Worker、Web 及测试项目。 - 增加 Bearer 认证、健康检查、账本领域模型和中文空状态页面。 [实现方案] - 使用环境变量模板注入认证配置,并排除数据、凭证和构建产物。 - 保留 19 个 Domain 测试和 5 个 API 测试作为后续变更基准。 [影响范围] - 为后续 3a PostgreSQL FOF 创建/读取切片提供可回滚基线。 - 当前仍不接入真实基金数据、真实交易或数据库。
Diffstat (limited to 'tests/FundLab.Api.Tests')
-rw-r--r--tests/FundLab.Api.Tests/ApiTests.fs24
-rw-r--r--tests/FundLab.Api.Tests/FundLab.Api.Tests.fsproj25
-rw-r--r--tests/FundLab.Api.Tests/Program.fs5
3 files changed, 54 insertions, 0 deletions
diff --git a/tests/FundLab.Api.Tests/ApiTests.fs b/tests/FundLab.Api.Tests/ApiTests.fs
new file mode 100644
index 0000000..a46d330
--- /dev/null
+++ b/tests/FundLab.Api.Tests/ApiTests.fs
@@ -0,0 +1,24 @@
+namespace FundLab.Api.Tests
+
+module ApiTests =
+
+ open Xunit
+ open FundLab.Api
+
+ [<Theory>]
+ [<InlineData("")>]
+ [<InlineData("Basic secret")>]
+ [<InlineData("Bearer wrong")>]
+ let ``missing or wrong bearer token is unauthorized`` header =
+ Assert.Equal(AuthDecision.Unauthorized, Authentication.authorize "secret" header)
+
+ [<Fact>]
+ let ``matching bearer token is authorized`` () =
+ Assert.Equal(AuthDecision.Authorized, Authentication.authorize "secret" "Bearer secret")
+
+ [<Fact>]
+ let ``health payload is non-sensitive`` () =
+ let payload = Health.payload "fund-lab-api"
+
+ Assert.Contains("\"status\":\"ok\"", payload)
+ Assert.DoesNotContain("secret", payload)
diff --git a/tests/FundLab.Api.Tests/FundLab.Api.Tests.fsproj b/tests/FundLab.Api.Tests/FundLab.Api.Tests.fsproj
new file mode 100644
index 0000000..ef9f063
--- /dev/null
+++ b/tests/FundLab.Api.Tests/FundLab.Api.Tests.fsproj
@@ -0,0 +1,25 @@
+<Project Sdk="Microsoft.NET.Sdk">
+ <PropertyGroup>
+ <TargetFramework>net8.0</TargetFramework>
+ <OutputType>Library</OutputType>
+ <IsPackable>false</IsPackable>
+ <IsTestProject>true</IsTestProject>
+ <GenerateProgramFile>false</GenerateProgramFile>
+ <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
+ </PropertyGroup>
+ <ItemGroup>
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
+ <PackageReference Include="xunit" Version="2.9.2" />
+ <PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
+ <PrivateAssets>all</PrivateAssets>
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+ </PackageReference>
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\src\FundLab.Api\FundLab.Api.fsproj" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="ApiTests.fs" />
+ <Compile Include="Program.fs" />
+ </ItemGroup>
+</Project>
diff --git a/tests/FundLab.Api.Tests/Program.fs b/tests/FundLab.Api.Tests/Program.fs
new file mode 100644
index 0000000..a139996
--- /dev/null
+++ b/tests/FundLab.Api.Tests/Program.fs
@@ -0,0 +1,5 @@
+module FundLab.Api.Tests.Program
+
+[<EntryPoint>]
+let main _argv =
+ 0