145 lines
4.5 KiB
PHP
145 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use App\Models\Merchant;
|
|
use App\Models\Plan;
|
|
use App\Models\PlatformOrder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class PlatformOrderRefundInconsistentTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_refund_total_can_fallback_to_refund_receipts_sum_when_refund_summary_missing(): void
|
|
{
|
|
$merchant = Merchant::query()->create([
|
|
'name' => '单测站点',
|
|
'slug' => 'unit-test-merchant',
|
|
'status' => 'active',
|
|
]);
|
|
|
|
$plan = Plan::query()->create([
|
|
'code' => 'unit_test_plan_refund_total',
|
|
'name' => '单测套餐',
|
|
'billing_cycle' => 'monthly',
|
|
'price' => 10,
|
|
'list_price' => 10,
|
|
'status' => 'active',
|
|
'sort' => 10,
|
|
'published_at' => now(),
|
|
]);
|
|
|
|
$order = PlatformOrder::query()->create([
|
|
'merchant_id' => $merchant->id,
|
|
'plan_id' => $plan->id,
|
|
'order_no' => 'PO_UNIT_REFUND_TOTAL_0001',
|
|
'order_type' => 'subscription',
|
|
'status' => 'activated',
|
|
'payment_status' => 'paid',
|
|
'plan_name' => 'Unit Test Plan',
|
|
'billing_cycle' => 'monthly',
|
|
'period_months' => 1,
|
|
'quantity' => 1,
|
|
'payable_amount' => 10,
|
|
'paid_amount' => 10,
|
|
'placed_at' => now(),
|
|
'meta' => [
|
|
'refund_receipts' => [
|
|
['amount' => 3.20],
|
|
['amount' => 1.30],
|
|
],
|
|
],
|
|
]);
|
|
|
|
$this->assertEquals(4.50, $order->refundTotal());
|
|
}
|
|
|
|
public function test_is_refund_inconsistent_when_status_refunded_but_refund_total_is_less_than_paid_amount(): void
|
|
{
|
|
$merchant = Merchant::query()->create([
|
|
'name' => '单测站点2',
|
|
'slug' => 'unit-test-merchant-2',
|
|
'status' => 'active',
|
|
]);
|
|
|
|
$plan = Plan::query()->create([
|
|
'code' => 'unit_test_plan_refund_inconsistent_1',
|
|
'name' => '单测套餐2',
|
|
'billing_cycle' => 'monthly',
|
|
'price' => 10,
|
|
'list_price' => 10,
|
|
'status' => 'active',
|
|
'sort' => 10,
|
|
'published_at' => now(),
|
|
]);
|
|
|
|
$order = PlatformOrder::query()->create([
|
|
'merchant_id' => $merchant->id,
|
|
'plan_id' => $plan->id,
|
|
'order_no' => 'PO_UNIT_REFUND_INCONSISTENT_0001',
|
|
'order_type' => 'subscription',
|
|
'status' => 'activated',
|
|
'payment_status' => 'refunded',
|
|
'plan_name' => 'Unit Test Plan',
|
|
'billing_cycle' => 'monthly',
|
|
'period_months' => 1,
|
|
'quantity' => 1,
|
|
'payable_amount' => 10,
|
|
'paid_amount' => 10,
|
|
'placed_at' => now(),
|
|
'meta' => [
|
|
'refund_summary' => [
|
|
'total_amount' => 9.98,
|
|
],
|
|
],
|
|
]);
|
|
|
|
$this->assertTrue($order->isRefundInconsistent());
|
|
}
|
|
|
|
public function test_is_refund_inconsistent_when_status_not_refunded_but_refund_total_reaches_paid_amount(): void
|
|
{
|
|
$merchant = Merchant::query()->create([
|
|
'name' => '单测站点3',
|
|
'slug' => 'unit-test-merchant-3',
|
|
'status' => 'active',
|
|
]);
|
|
|
|
$plan = Plan::query()->create([
|
|
'code' => 'unit_test_plan_refund_inconsistent_2',
|
|
'name' => '单测套餐3',
|
|
'billing_cycle' => 'monthly',
|
|
'price' => 10,
|
|
'list_price' => 10,
|
|
'status' => 'active',
|
|
'sort' => 10,
|
|
'published_at' => now(),
|
|
]);
|
|
|
|
$order = PlatformOrder::query()->create([
|
|
'merchant_id' => $merchant->id,
|
|
'plan_id' => $plan->id,
|
|
'order_no' => 'PO_UNIT_REFUND_INCONSISTENT_0002',
|
|
'order_type' => 'subscription',
|
|
'status' => 'activated',
|
|
'payment_status' => 'paid',
|
|
'plan_name' => 'Unit Test Plan',
|
|
'billing_cycle' => 'monthly',
|
|
'period_months' => 1,
|
|
'quantity' => 1,
|
|
'payable_amount' => 10,
|
|
'paid_amount' => 10,
|
|
'placed_at' => now(),
|
|
'meta' => [
|
|
'refund_summary' => [
|
|
'total_amount' => 10.00,
|
|
],
|
|
],
|
|
]);
|
|
|
|
$this->assertTrue($order->isRefundInconsistent());
|
|
}
|
|
}
|