112 lines
3.9 KiB
PHP
112 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\StoreModel;
|
|
|
|
/**
|
|
* 小程序门店设置:详情回显、联系人/电话/地址维护、
|
|
* 名称/编码/回款周期等字段不可通过小程序端修改
|
|
* (门店即用户:登录主体就是门店,操作对象即当前登录门店)
|
|
*/
|
|
class MiniStoreTest extends ProcurementTestCase
|
|
{
|
|
/** 门店详情:返回当前门店信息(含只读回款周期) */
|
|
public function test_info_returns_current_store(): void
|
|
{
|
|
$store = StoreModel::factory()->paymentCycle(7)->create([
|
|
'contact' => '张三',
|
|
'phone' => '13800138000',
|
|
'address' => '幸福路 1 号',
|
|
]);
|
|
$this->actingAsMiniStore($store);
|
|
|
|
$this->getJson('/mini/store/info')
|
|
->assertOk()
|
|
->assertJsonPath('success', true)
|
|
->assertJsonPath('data.id', $store->id)
|
|
->assertJsonPath('data.contact', '张三')
|
|
->assertJsonPath('data.phone', '13800138000')
|
|
->assertJsonPath('data.address', '幸福路 1 号')
|
|
->assertJsonPath('data.payment_cycle_days', 7);
|
|
}
|
|
|
|
/** 修改门店信息:联系人 / 电话 / 地址 */
|
|
public function test_update_info(): void
|
|
{
|
|
$store = StoreModel::factory()->create();
|
|
$this->actingAsMiniStore($store);
|
|
|
|
$this->putJson('/mini/store/info', [
|
|
'contact' => '李四',
|
|
'phone' => '13900139000',
|
|
'address' => '建设路 88 号',
|
|
])
|
|
->assertOk()
|
|
->assertJsonPath('success', true)
|
|
->assertJsonPath('data.contact', '李四')
|
|
->assertJsonPath('data.phone', '13900139000')
|
|
->assertJsonPath('data.address', '建设路 88 号');
|
|
|
|
$store->refresh();
|
|
$this->assertSame('李四', $store->contact);
|
|
$this->assertSame('13900139000', $store->phone);
|
|
$this->assertSame('建设路 88 号', $store->address);
|
|
}
|
|
|
|
/** 白名单更新:名称 / 编码 / 回款周期等字段提交后被忽略 */
|
|
public function test_update_info_ignores_readonly_fields(): void
|
|
{
|
|
$store = StoreModel::factory()->paymentCycle(5)->create([
|
|
'name' => '原门店',
|
|
'code' => 'ST100',
|
|
]);
|
|
$this->actingAsMiniStore($store);
|
|
|
|
$this->putJson('/mini/store/info', [
|
|
'contact' => '王五',
|
|
'name' => '改名门店',
|
|
'code' => 'HACK',
|
|
'payment_cycle_days' => 99,
|
|
])
|
|
->assertOk()
|
|
->assertJsonPath('success', true);
|
|
|
|
$store->refresh();
|
|
$this->assertSame('王五', $store->contact);
|
|
$this->assertSame('原门店', $store->name);
|
|
$this->assertSame('ST100', $store->code);
|
|
$this->assertSame(5, $store->payment_cycle_days);
|
|
}
|
|
|
|
/** 停用门店 → 拒绝访问 */
|
|
public function test_disabled_store_rejected(): void
|
|
{
|
|
$store = StoreModel::factory()->disabled()->create();
|
|
$this->actingAsMiniStore($store);
|
|
|
|
$this->getJson('/mini/store/info')
|
|
->assertOk()
|
|
->assertJsonPath('success', false)
|
|
->assertJsonPath('msg', '账号不存在或已被停用');
|
|
|
|
$this->putJson('/mini/store/info', ['contact' => '路人'])
|
|
->assertOk()
|
|
->assertJsonPath('success', false);
|
|
}
|
|
|
|
/** 字段长度校验:联系人超过 50 字符 → 校验失败 */
|
|
public function test_update_info_validates_length(): void
|
|
{
|
|
$store = StoreModel::factory()->create();
|
|
$this->actingAsMiniStore($store);
|
|
|
|
$this->putJson('/mini/store/info', ['contact' => str_repeat('长', 51)])
|
|
->assertOk()
|
|
->assertJsonPath('success', false)
|
|
->assertJsonPath('msg', '联系人最长 50 个字符');
|
|
|
|
$this->assertSame($store->contact, $store->refresh()->contact, '校验失败不应落库');
|
|
}
|
|
}
|