110 lines
4.2 KiB
PHP
110 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Business;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
class ProductCostPendingDetailsTest extends FeatureTestCase
|
|
{
|
|
public function test_pending_details_use_current_filters_and_include_both_unresolved_reasons(): void
|
|
{
|
|
$mirror = DB::connection('business_mirror');
|
|
$mirror->table('store_receipt_product_cost_rows')->insert([
|
|
$this->row('pending-both', 'HX-A', null, null, 2, null),
|
|
$this->row('pending-price', 'HX-B', '崔桥工厂仓', null, 3, null),
|
|
$this->row('pending-warehouse', 'HX-C', '', 10, 1, 10),
|
|
$this->row('valid', 'HX-D', '崔桥工厂仓', 10, 1, 10),
|
|
$this->row('other-store', 'OTHER', null, null, 1, null, '其他店铺'),
|
|
$this->row('other-month', 'OLD', null, null, 1, null, '京东-HX旗舰店104', '2026-08-01'),
|
|
]);
|
|
|
|
$response = $this->loginAs()->getJson(route(
|
|
'business.financial-operations.product-costs.pending-details',
|
|
[
|
|
'month' => '2026-09',
|
|
'store_name' => 'HX',
|
|
],
|
|
));
|
|
|
|
$response
|
|
->assertOk()
|
|
->assertJsonPath('summary.pending_cost_rows', 2)
|
|
->assertJsonPath('summary.pending_cost_quantity', 5)
|
|
->assertJsonPath('summary.missing_warehouse_rows', 2)
|
|
->assertJsonPath('pagination.total', 3)
|
|
->assertJsonPath('pagination.page', 1);
|
|
|
|
$cacheControl = (string) $response->headers->get('Cache-Control');
|
|
$this->assertStringContainsString('private', $cacheControl);
|
|
$this->assertStringContainsString('no-store', $cacheControl);
|
|
|
|
$rows = collect($response->json('rows'))->keyBy('online_order_no');
|
|
$this->assertCount(3, $rows);
|
|
$this->assertSame(['商品单价缺失', '仓库简称未匹配'], $rows['HX-A']['reasons']);
|
|
$this->assertSame(['商品单价缺失'], $rows['HX-B']['reasons']);
|
|
$this->assertSame(['仓库简称未匹配'], $rows['HX-C']['reasons']);
|
|
$this->assertFalse($rows->has('HX-D'));
|
|
}
|
|
|
|
public function test_repaired_row_disappears_when_modal_data_is_reloaded(): void
|
|
{
|
|
$mirror = DB::connection('business_mirror');
|
|
$mirror->table('store_receipt_product_cost_rows')->insert(
|
|
$this->row('repair-me', 'REPAIR-1', null, null, 1, null)
|
|
);
|
|
$this->loginAs();
|
|
$url = route('business.financial-operations.product-costs.pending-details', [
|
|
'month' => '2026-09',
|
|
]);
|
|
|
|
$this->getJson($url)
|
|
->assertOk()
|
|
->assertJsonPath('pagination.total', 1)
|
|
->assertJsonPath('rows.0.online_order_no', 'REPAIR-1');
|
|
|
|
$mirror->table('store_receipt_product_cost_rows')
|
|
->where('row_key', 'repair-me')
|
|
->update([
|
|
'warehouse_short_name' => '崔桥工厂仓',
|
|
'unit_price' => 10,
|
|
'product_cost' => 10,
|
|
]);
|
|
|
|
$this->getJson($url)
|
|
->assertOk()
|
|
->assertJsonPath('summary.pending_cost_rows', 0)
|
|
->assertJsonPath('summary.missing_warehouse_rows', 0)
|
|
->assertJsonPath('pagination.total', 0)
|
|
->assertJsonCount(0, 'rows');
|
|
}
|
|
|
|
private function row(
|
|
string $rowKey,
|
|
string $onlineOrderNo,
|
|
?string $warehouseShortName,
|
|
int|float|null $unitPrice,
|
|
int|float $quantity,
|
|
int|float|null $productCost,
|
|
string $storeName = '京东-HX旗舰店104',
|
|
string $reportMonth = '2026-09-01'
|
|
): array {
|
|
return [
|
|
'report_month' => $reportMonth,
|
|
'row_key' => $rowKey,
|
|
'platform' => '京东账单',
|
|
'occurred_date' => $reportMonth,
|
|
'store_name' => $storeName,
|
|
'online_order_no' => $onlineOrderNo,
|
|
'warehouse' => '简尚-崔桥工厂仓',
|
|
'warehouse_short_name' => $warehouseShortName,
|
|
'product_code' => 'SKU-' . $rowKey,
|
|
'product_quantity' => $quantity,
|
|
'unit_price' => $unitPrice,
|
|
'product_cost' => $productCost,
|
|
'remark' => null,
|
|
'imported_at' => now(),
|
|
];
|
|
}
|
|
}
|