91 lines
2.5 KiB
PHP
91 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Tests;
|
|
|
|
use Tests\TestCase;
|
|
use App\Models\ShopAuth;
|
|
use App\Models\Platform;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
class ModulesTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
/** @test */
|
|
public function shop_auth_module_works()
|
|
{
|
|
// 测试店铺授权模型
|
|
$shopAuth = ShopAuth::create([
|
|
'platform' => 'taobao',
|
|
'shop_name' => '测试店铺',
|
|
'access_token' => 'test_token',
|
|
'refresh_token' => 'test_refresh_token',
|
|
'expires_at' => now()->addDays(30),
|
|
'status' => 'active',
|
|
]);
|
|
|
|
$this->assertDatabaseHas('shop_auths', [
|
|
'platform' => 'taobao',
|
|
'shop_name' => '测试店铺',
|
|
'status' => 'active',
|
|
]);
|
|
|
|
// 测试状态标签
|
|
$this->assertEquals('已授权', $shopAuth->status_label);
|
|
}
|
|
|
|
/** @test */
|
|
public function platform_module_works()
|
|
{
|
|
// 先创建店铺授权
|
|
$shopAuth = ShopAuth::create([
|
|
'platform' => 'taobao',
|
|
'shop_name' => '测试店铺',
|
|
'access_token' => 'test_token',
|
|
'refresh_token' => 'test_refresh_token',
|
|
'expires_at' => now()->addDays(30),
|
|
'status' => 'active',
|
|
]);
|
|
|
|
// 测试平台商品模型
|
|
$platform = Platform::create([
|
|
'shop_auth_id' => $shopAuth->id,
|
|
'platform_product_id' => '123456789',
|
|
'title' => '测试商品',
|
|
'price' => 99.99,
|
|
'stock' => 100,
|
|
'status' => 'on_sale',
|
|
'sync_status' => 'pending',
|
|
]);
|
|
|
|
$this->assertDatabaseHas('platforms', [
|
|
'platform_product_id' => '123456789',
|
|
'title' => '测试商品',
|
|
'price' => 99.99,
|
|
'status' => 'on_sale',
|
|
]);
|
|
|
|
// 测试关联关系
|
|
$this->assertEquals($shopAuth->id, $platform->shopAuth->id);
|
|
|
|
// 测试状态标签
|
|
$this->assertEquals('在售', $platform->status_label);
|
|
$this->assertEquals('待同步', $platform->sync_status_label);
|
|
}
|
|
|
|
/** @test */
|
|
public function platform_routes_exist()
|
|
{
|
|
// 测试平台商品路由是否存在
|
|
$response = $this->get('/api/platforms');
|
|
$response->assertStatus(200);
|
|
}
|
|
|
|
/** @test */
|
|
public function shop_auth_routes_exist()
|
|
{
|
|
// 测试店铺授权路由是否存在
|
|
$response = $this->get('/api/shops');
|
|
$response->assertStatus(200);
|
|
}
|
|
} |