feat: add commerce refunds and reconciliation persistence

This commit is contained in:
xiong
2026-07-26 05:53:16 +08:00
parent 4b59b493e1
commit 3eb9f111ed
7 changed files with 15247 additions and 5 deletions

View File

@@ -28,7 +28,7 @@ public sealed class PersistenceModelTests
.Select(entity => entity.GetTableName())
.ToHashSet(StringComparer.Ordinal);
Assert.Equal(100, tableNames.Count);
Assert.Equal(106, tableNames.Count);
Assert.Contains("tenants", tableNames);
Assert.Contains("tenant_settings", tableNames);
Assert.Contains("content_entries", tableNames);
@@ -86,6 +86,12 @@ public sealed class PersistenceModelTests
Assert.Contains("tenant_payment_accounts", tableNames);
Assert.Contains("tenant_subscriptions", tableNames);
Assert.Contains("tenant_usage_records", tableNames);
Assert.Contains("commerce_refund_requests", tableNames);
Assert.Contains("commerce_refund_events", tableNames);
Assert.Contains("commerce_reconciliation_batches", tableNames);
Assert.Contains("commerce_reconciliation_items", tableNames);
Assert.Contains("commerce_reconciliation_issues", tableNames);
Assert.Contains("commerce_reconciliation_issue_events", tableNames);
Assert.Contains("referral_tracks", tableNames);
Assert.Contains("referral_codes", tableNames);
Assert.Contains("referral_leads", tableNames);
@@ -484,6 +490,12 @@ public sealed class PersistenceModelTests
[InlineData(typeof(TenantPaymentAccount), nameof(TenantPaymentAccount.ConfigPublic), "'{}'::jsonb")]
[InlineData(typeof(TenantSubscription), nameof(TenantSubscription.Metadata), "'{}'::jsonb")]
[InlineData(typeof(TenantUsageRecord), nameof(TenantUsageRecord.Metadata), "'{}'::jsonb")]
[InlineData(typeof(CommerceRefundRequest), nameof(CommerceRefundRequest.Metadata), "'{}'::jsonb")]
[InlineData(typeof(CommerceRefundEvent), nameof(CommerceRefundEvent.Details), "'{}'::jsonb")]
[InlineData(typeof(CommerceReconciliationBatch), nameof(CommerceReconciliationBatch.Metadata), "'{}'::jsonb")]
[InlineData(typeof(CommerceReconciliationItem), nameof(CommerceReconciliationItem.Details), "'{}'::jsonb")]
[InlineData(typeof(CommerceReconciliationIssue), nameof(CommerceReconciliationIssue.Metadata), "'{}'::jsonb")]
[InlineData(typeof(CommerceReconciliationIssueEvent), nameof(CommerceReconciliationIssueEvent.Details), "'{}'::jsonb")]
public void Commerce_json_properties_are_mapped_to_jsonb(
Type entityType,
string propertyName,
@@ -509,11 +521,27 @@ public sealed class PersistenceModelTests
AssertHasUniqueIndex<TenantPaymentAccount>(
nameof(TenantPaymentAccount.TenantId),
nameof(TenantPaymentAccount.Provider));
AssertHasUniqueIndex<CommerceRefundRequest>(
nameof(CommerceRefundRequest.TenantId),
nameof(CommerceRefundRequest.RefundNo));
AssertHasUniqueIndex<CommerceReconciliationItem>(
nameof(CommerceReconciliationItem.BatchId),
nameof(CommerceReconciliationItem.RowNo));
AssertHasUniqueIndex<CommerceReconciliationIssue>(
nameof(CommerceReconciliationIssue.TenantId),
nameof(CommerceReconciliationIssue.IssueNo));
AssertHasUniqueIndex<CommerceReconciliationIssue>(
nameof(CommerceReconciliationIssue.TenantId),
nameof(CommerceReconciliationIssue.ItemId));
var amount = context.Model.FindEntityType(typeof(Order))!
.FindProperty(nameof(Order.AmountCents))!;
Assert.Equal(typeof(int), amount.ClrType);
var refundedAmount = context.Model.FindEntityType(typeof(Order))!
.FindProperty(nameof(Order.RefundedAmountCents))!;
Assert.Equal(typeof(int), refundedAmount.ClrType);
void AssertHasUniqueIndex<TEntity>(params string[] propertyNames)
{
var indexes = context.Model.FindEntityType(typeof(TEntity))!.GetIndexes();