111 lines
4.0 KiB
PHP
111 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\StoreModel;
|
|
use App\Models\UserModel;
|
|
|
|
/**
|
|
* 小程序门店设置:详情回显、联系人/电话/地址维护、
|
|
* 名称/编码/回款周期等字段不可通过小程序端修改
|
|
*/
|
|
class MiniStoreTest extends ProcurementTestCase
|
|
{
|
|
/** 门店详情:返回当前绑定门店信息(含只读回款周期) */
|
|
public function test_info_returns_bound_store(): void
|
|
{
|
|
$store = StoreModel::factory()->paymentCycle(7)->create([
|
|
'contact' => '张三',
|
|
'phone' => '13800138000',
|
|
'address' => '幸福路 1 号',
|
|
]);
|
|
$this->actingAsMiniUser(UserModel::factory()->forStore($store->id)->create());
|
|
|
|
$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->actingAsMiniUser(UserModel::factory()->forStore($store->id)->create());
|
|
|
|
$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 号');
|
|
|
|
$fresh = $store->fresh();
|
|
$this->assertSame('李四', $fresh->contact);
|
|
$this->assertSame('13900139000', $fresh->phone);
|
|
$this->assertSame('建设路 88 号', $fresh->address);
|
|
}
|
|
|
|
/** 白名单更新:名称 / 编码 / 回款周期等字段提交后被忽略 */
|
|
public function test_update_info_ignores_readonly_fields(): void
|
|
{
|
|
$store = StoreModel::factory()->paymentCycle(5)->create([
|
|
'name' => '原门店',
|
|
'code' => 'ST100',
|
|
]);
|
|
$this->actingAsMiniUser(UserModel::factory()->forStore($store->id)->create());
|
|
|
|
$this->putJson('/mini/store/info', [
|
|
'contact' => '王五',
|
|
'name' => '改名门店',
|
|
'code' => 'HACK',
|
|
'payment_cycle_days' => 99,
|
|
])
|
|
->assertOk()
|
|
->assertJsonPath('success', true);
|
|
|
|
$fresh = $store->fresh();
|
|
$this->assertSame('王五', $fresh->contact);
|
|
$this->assertSame('原门店', $fresh->name);
|
|
$this->assertSame('ST100', $fresh->code);
|
|
$this->assertSame(5, $fresh->payment_cycle_days);
|
|
}
|
|
|
|
/** 未绑定门店 → 拒绝访问 */
|
|
public function test_requires_bound_store(): void
|
|
{
|
|
$this->actingAsMiniUser(UserModel::factory()->create());
|
|
|
|
$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->actingAsMiniUser(UserModel::factory()->forStore($store->id)->create());
|
|
|
|
$this->putJson('/mini/store/info', ['contact' => str_repeat('长', 51)])
|
|
->assertOk()
|
|
->assertJsonPath('success', false)
|
|
->assertJsonPath('msg', '联系人最长 50 个字符');
|
|
|
|
$this->assertSame($store->contact, $store->fresh()->contact, '校验失败不应落库');
|
|
}
|
|
}
|