Files
saasshop/tests/Feature/AdminPlatformOrderCreateTest.php

108 lines
3.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderCreateTest extends TestCase
{
use RefreshDatabase;
protected function loginAsPlatformAdmin(): void
{
$this->seed();
$this->post('/admin/login', [
'email' => 'platform.admin@demo.local',
'password' => 'Platform@123456',
])->assertRedirect('/admin');
}
public function test_platform_admin_can_open_create_platform_order_form(): void
{
$this->loginAsPlatformAdmin();
// 需要至少一个套餐供选择
Plan::query()->create([
'code' => 'create_order_plan_01',
'name' => '创建订单测试套餐',
'billing_cycle' => 'monthly',
'price' => 100,
'list_price' => 100,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$res = $this->get('/admin/platform-orders/create');
$res->assertOk();
$res->assertSee('新建平台订单');
$res->assertSee('站点');
$res->assertSee('套餐');
$res->assertSee('创建订单');
}
public function test_platform_admin_can_create_platform_order_and_see_it_in_show_page(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'create_order_plan_02',
'name' => '创建订单测试套餐2',
'billing_cycle' => 'monthly',
'price' => 199,
'list_price' => 199,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$res = $this->post('/admin/platform-orders', [
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_type' => 'new_purchase',
'quantity' => 2,
'discount_amount' => 10,
'payment_channel' => 'offline',
'remark' => '线下补单',
]);
$res->assertRedirect();
$order = PlatformOrder::query()->latest('id')->first();
$this->assertNotNull($order);
$this->assertSame($merchant->id, $order->merchant_id);
$this->assertSame($plan->id, $order->plan_id);
$this->assertSame('pending', $order->status);
$this->assertSame('unpaid', $order->payment_status);
$this->assertSame('offline', $order->payment_channel);
// 金额口径list_amount=price*quantitypayable=list-discount
$this->assertSame(398.0, (float) $order->list_amount);
$this->assertSame(10.0, (float) $order->discount_amount);
$this->assertSame(388.0, (float) $order->payable_amount);
$show = $this->get('/admin/platform-orders/' . $order->id);
$show->assertOk();
$show->assertSee($order->order_no);
$show->assertSee('平台订单详情');
$show->assertSee('待处理');
$show->assertSee('未支付');
}
public function test_guest_cannot_open_create_platform_order_form(): void
{
$this->seed();
$this->get('/admin/platform-orders/create')
->assertRedirect('/admin/login');
}
}