Deploy Ladill Woo Manager / deploy (push) Successful in 1m5s
Surfaces actionable controls in Ladill instead of status-only cards: sync catalogs via the plugin proxy, show channel metrics, and link to orders/labels for fulfillment. Co-authored-by: Cursor <cursoragent@cursor.com>
273 lines
11 KiB
PHP
273 lines
11 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\User;
|
|
use App\Models\WooStore;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Tests\TestCase;
|
|
|
|
class WooIntegrationsTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_guest_is_redirected_from_integrations(): void
|
|
{
|
|
$this->get(route('woo.integrations.index'))
|
|
->assertRedirect(route('sso.connect', ['redirect' => route('woo.integrations.index')]));
|
|
}
|
|
|
|
public function test_integrations_page_without_store_shows_catalog(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$this->actingAs($user)
|
|
->get(route('woo.integrations.index'))
|
|
->assertOk()
|
|
->assertSee('Integrations')
|
|
->assertSee('Google for WooCommerce')
|
|
->assertSee('Pinterest for WooCommerce')
|
|
->assertSee('Snapchat for WooCommerce')
|
|
->assertSee('TikTok for WooCommerce')
|
|
->assertSee('Reddit for WooCommerce')
|
|
->assertSee('Meta for WooCommerce')
|
|
->assertSee('Connect a WooCommerce store');
|
|
}
|
|
|
|
public function test_integrations_page_fetches_status_from_plugin(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
$store = WooStore::create([
|
|
'user_id' => $user->id,
|
|
'site_url' => 'https://shop.example.com',
|
|
'site_name' => 'Example Shop',
|
|
'status' => WooStore::STATUS_ACTIVE,
|
|
'connected_at' => now(),
|
|
'public_id' => 'store-public-id',
|
|
]);
|
|
|
|
Http::fake([
|
|
'https://shop.example.com/wp-json/ladill-woo/v1/integrations/status' => Http::response([
|
|
'integrations' => [
|
|
'shipping' => [
|
|
'state' => 'connected',
|
|
'installed' => true,
|
|
'connected' => true,
|
|
'manage_url' => 'https://shop.example.com/wp-admin/admin.php?page=wc-settings&tab=shipping',
|
|
'summary' => '2 zones, 4 methods',
|
|
'details' => ['zones' => 2, 'methods' => 4],
|
|
],
|
|
'google' => [
|
|
'state' => 'needs_setup',
|
|
'installed' => true,
|
|
'connected' => false,
|
|
'manage_url' => 'https://shop.example.com/wp-admin/admin.php?page=wc-admin&path=/google/start',
|
|
'summary' => 'Installed — finish setup in WordPress.',
|
|
'details' => [],
|
|
'metrics' => ['available' => true, 'published_products' => 42],
|
|
],
|
|
'pinterest' => [
|
|
'state' => 'not_installed',
|
|
'installed' => false,
|
|
'connected' => false,
|
|
'manage_url' => null,
|
|
'summary' => 'Extension is not installed on this store.',
|
|
'details' => [],
|
|
],
|
|
'snapchat' => [
|
|
'state' => 'connected',
|
|
'installed' => true,
|
|
'connected' => true,
|
|
'manage_url' => 'https://shop.example.com/wp-admin/admin.php?page=wc-admin&path=/snapchat/setup',
|
|
'summary' => 'Connected and ready.',
|
|
'details' => [],
|
|
],
|
|
],
|
|
], 200),
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->get(route('woo.integrations.index'))
|
|
->assertOk()
|
|
->assertSee('Example Shop')
|
|
->assertSee('2 zones, 4 methods')
|
|
->assertSee('Needs setup')
|
|
->assertSee('Not installed')
|
|
->assertSee('Connected')
|
|
->assertSee('Manage in WordPress');
|
|
|
|
Http::assertSentCount(1);
|
|
}
|
|
|
|
public function test_integrations_status_is_cached_until_refresh(): void
|
|
{
|
|
config(['woo.integrations_cache_ttl_seconds' => 300]);
|
|
|
|
$user = User::factory()->create();
|
|
$store = WooStore::create([
|
|
'user_id' => $user->id,
|
|
'site_url' => 'https://shop.example.com',
|
|
'site_name' => 'Example Shop',
|
|
'status' => WooStore::STATUS_ACTIVE,
|
|
'connected_at' => now(),
|
|
'public_id' => 'store-public-id',
|
|
]);
|
|
|
|
Http::fake([
|
|
'https://shop.example.com/wp-json/ladill-woo/v1/integrations/status' => Http::response([
|
|
'integrations' => [
|
|
'shipping' => [
|
|
'state' => 'connected',
|
|
'installed' => true,
|
|
'connected' => true,
|
|
'manage_url' => 'https://shop.example.com/wp-admin/admin.php?page=wc-settings&tab=shipping',
|
|
'summary' => '1 zone, 2 methods',
|
|
'details' => ['zones' => 1, 'methods' => 2],
|
|
],
|
|
],
|
|
], 200),
|
|
]);
|
|
|
|
$this->actingAs($user)->get(route('woo.integrations.index'))->assertOk();
|
|
$this->actingAs($user)->get(route('woo.integrations.index'))->assertOk();
|
|
|
|
Http::assertSentCount(1);
|
|
|
|
$this->actingAs($user)
|
|
->post(route('woo.integrations.refresh'))
|
|
->assertRedirect(route('woo.integrations.index'));
|
|
|
|
$this->actingAs($user)->get(route('woo.integrations.index'))->assertOk();
|
|
|
|
Http::assertSentCount(2);
|
|
$this->assertTrue(Cache::has('woo.integrations.'.$store->id));
|
|
}
|
|
|
|
public function test_integrations_refresh_survives_store_connection_timeout(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
WooStore::create([
|
|
'user_id' => $user->id,
|
|
'site_url' => 'https://shop.example.com',
|
|
'site_name' => 'Example Shop',
|
|
'status' => WooStore::STATUS_ACTIVE,
|
|
'connected_at' => now(),
|
|
'public_id' => 'store-public-id',
|
|
]);
|
|
|
|
Http::fake([
|
|
'https://shop.example.com/wp-json/ladill-woo/v1/integrations/status' => function () {
|
|
throw new \Illuminate\Http\Client\ConnectionException(
|
|
new \Exception('cURL error 28: Operation timed out')
|
|
);
|
|
},
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->from(route('woo.integrations.index'))
|
|
->post(route('woo.integrations.refresh'))
|
|
->assertRedirect(route('woo.integrations.index'))
|
|
->assertSessionHas('success');
|
|
}
|
|
|
|
public function test_catalog_sync_posts_to_plugin_and_refreshes_cache(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
$store = WooStore::create([
|
|
'user_id' => $user->id,
|
|
'site_url' => 'https://shop.example.com',
|
|
'site_name' => 'Example Shop',
|
|
'status' => WooStore::STATUS_ACTIVE,
|
|
'connected_at' => now(),
|
|
'public_id' => 'store-public-id',
|
|
]);
|
|
|
|
Cache::put('woo.integrations.'.$store->id, ['integrations' => []], 300);
|
|
|
|
Http::fake([
|
|
'https://shop.example.com/wp-json/ladill-woo/v1/integrations/google/sync' => Http::response([
|
|
'success' => true,
|
|
'message' => 'Catalog sync started on your store.',
|
|
], 200),
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->from(route('woo.integrations.index'))
|
|
->post(route('woo.integrations.sync', 'google'))
|
|
->assertRedirect(route('woo.integrations.index'))
|
|
->assertSessionHas('success', 'Catalog sync started on your store.');
|
|
|
|
$this->assertFalse(Cache::has('woo.integrations.'.$store->id));
|
|
|
|
Http::assertSent(function ($request) {
|
|
return $request->url() === 'https://shop.example.com/wp-json/ladill-woo/v1/integrations/google/sync'
|
|
&& $request->method() === 'POST'
|
|
&& $request->hasHeader('X-Ladill-Store', 'store-public-id');
|
|
});
|
|
}
|
|
|
|
public function test_integrations_page_shows_catalog_metrics(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
WooStore::create([
|
|
'user_id' => $user->id,
|
|
'site_url' => 'https://shop.example.com',
|
|
'site_name' => 'Example Shop',
|
|
'status' => WooStore::STATUS_ACTIVE,
|
|
'connected_at' => now(),
|
|
'public_id' => 'store-public-id',
|
|
]);
|
|
|
|
Http::fake([
|
|
'https://shop.example.com/wp-json/ladill-woo/v1/integrations/status' => Http::response([
|
|
'integrations' => [
|
|
'google' => [
|
|
'state' => 'connected',
|
|
'installed' => true,
|
|
'connected' => true,
|
|
'manage_url' => 'https://shop.example.com/wp-admin/admin.php?page=wc-admin&path=/google/start',
|
|
'summary' => 'Connected and ready.',
|
|
'details' => [],
|
|
'metrics' => [
|
|
'available' => true,
|
|
'published_products' => 42,
|
|
'synced_products' => 40,
|
|
'pending_products' => 2,
|
|
'catalog_sync_status' => 'synced',
|
|
],
|
|
],
|
|
'shipping' => [
|
|
'state' => 'connected',
|
|
'installed' => true,
|
|
'connected' => true,
|
|
'manage_url' => 'https://shop.example.com/wp-admin/admin.php?page=wc-settings&tab=shipping',
|
|
'summary' => '1 zone, 2 methods',
|
|
'details' => [
|
|
'woocommerce_shipping' => true,
|
|
'labels_ready' => true,
|
|
'labels_manage_url' => 'https://shop.example.com/wp-admin/admin.php?page=wc-settings&tab=shipping§ion=woocommerce-services',
|
|
],
|
|
'metrics' => [
|
|
'available' => true,
|
|
'orders_awaiting_fulfillment' => 5,
|
|
'labeled_orders' => 12,
|
|
],
|
|
],
|
|
],
|
|
], 200),
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->get(route('woo.integrations.index'))
|
|
->assertOk()
|
|
->assertSee('Published products')
|
|
->assertSee('42')
|
|
->assertSee('Awaiting fulfillment')
|
|
->assertSee('Sync catalog')
|
|
->assertSee('View orders')
|
|
->assertSee('Manage labels');
|
|
}
|
|
}
|