小程序用户改用门店登录
This commit is contained in:
@@ -3,23 +3,23 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\StoreModel;
|
||||
use App\Models\UserModel;
|
||||
|
||||
/**
|
||||
* 小程序门店设置:详情回显、联系人/电话/地址维护、
|
||||
* 名称/编码/回款周期等字段不可通过小程序端修改
|
||||
* (门店即用户:登录主体就是门店,操作对象即当前登录门店)
|
||||
*/
|
||||
class MiniStoreTest extends ProcurementTestCase
|
||||
{
|
||||
/** 门店详情:返回当前绑定门店信息(含只读回款周期) */
|
||||
public function test_info_returns_bound_store(): void
|
||||
/** 门店详情:返回当前门店信息(含只读回款周期) */
|
||||
public function test_info_returns_current_store(): void
|
||||
{
|
||||
$store = StoreModel::factory()->paymentCycle(7)->create([
|
||||
'contact' => '张三',
|
||||
'phone' => '13800138000',
|
||||
'address' => '幸福路 1 号',
|
||||
]);
|
||||
$this->actingAsMiniUser(UserModel::factory()->forStore($store->id)->create());
|
||||
$this->actingAsMiniStore($store);
|
||||
|
||||
$this->getJson('/mini/store/info')
|
||||
->assertOk()
|
||||
@@ -35,7 +35,7 @@ class MiniStoreTest extends ProcurementTestCase
|
||||
public function test_update_info(): void
|
||||
{
|
||||
$store = StoreModel::factory()->create();
|
||||
$this->actingAsMiniUser(UserModel::factory()->forStore($store->id)->create());
|
||||
$this->actingAsMiniStore($store);
|
||||
|
||||
$this->putJson('/mini/store/info', [
|
||||
'contact' => '李四',
|
||||
@@ -48,10 +48,10 @@ class MiniStoreTest extends ProcurementTestCase
|
||||
->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);
|
||||
$store->refresh();
|
||||
$this->assertSame('李四', $store->contact);
|
||||
$this->assertSame('13900139000', $store->phone);
|
||||
$this->assertSame('建设路 88 号', $store->address);
|
||||
}
|
||||
|
||||
/** 白名单更新:名称 / 编码 / 回款周期等字段提交后被忽略 */
|
||||
@@ -61,7 +61,7 @@ class MiniStoreTest extends ProcurementTestCase
|
||||
'name' => '原门店',
|
||||
'code' => 'ST100',
|
||||
]);
|
||||
$this->actingAsMiniUser(UserModel::factory()->forStore($store->id)->create());
|
||||
$this->actingAsMiniStore($store);
|
||||
|
||||
$this->putJson('/mini/store/info', [
|
||||
'contact' => '王五',
|
||||
@@ -72,22 +72,23 @@ class MiniStoreTest extends ProcurementTestCase
|
||||
->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);
|
||||
$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_requires_bound_store(): void
|
||||
/** 停用门店 → 拒绝访问 */
|
||||
public function test_disabled_store_rejected(): void
|
||||
{
|
||||
$this->actingAsMiniUser(UserModel::factory()->create());
|
||||
$store = StoreModel::factory()->disabled()->create();
|
||||
$this->actingAsMiniStore($store);
|
||||
|
||||
$this->getJson('/mini/store/info')
|
||||
->assertOk()
|
||||
->assertJsonPath('success', false)
|
||||
->assertJsonPath('msg', '尚未绑定门店,请联系客服处理');
|
||||
->assertJsonPath('msg', '账号不存在或已被停用');
|
||||
|
||||
$this->putJson('/mini/store/info', ['contact' => '路人'])
|
||||
->assertOk()
|
||||
@@ -98,13 +99,13 @@ class MiniStoreTest extends ProcurementTestCase
|
||||
public function test_update_info_validates_length(): void
|
||||
{
|
||||
$store = StoreModel::factory()->create();
|
||||
$this->actingAsMiniUser(UserModel::factory()->forStore($store->id)->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->fresh()->contact, '校验失败不应落库');
|
||||
$this->assertSame($store->contact, $store->refresh()->contact, '校验失败不应落库');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user