2025-08-02 03:48:06 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
|
|
use App\Models\Article;
|
|
|
|
|
use App\Models\Feed;
|
|
|
|
|
use App\Models\PlatformAccount;
|
|
|
|
|
use App\Models\PlatformChannel;
|
|
|
|
|
use App\Models\Route;
|
|
|
|
|
use App\Models\Setting;
|
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
2025-08-02 15:20:09 +02:00
|
|
|
use Illuminate\Support\Facades\Event;
|
2025-08-02 03:48:06 +02:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
|
|
class ApiEndpointRegressionTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
use RefreshDatabase;
|
|
|
|
|
|
|
|
|
|
public function test_homepage_loads_successfully(): void
|
|
|
|
|
{
|
|
|
|
|
$response = $this->get('/');
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_onboarding_platform_page_loads(): void
|
|
|
|
|
{
|
|
|
|
|
$response = $this->get('/onboarding/platform');
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_onboarding_feed_page_loads(): void
|
|
|
|
|
{
|
|
|
|
|
$response = $this->get('/onboarding/feed');
|
2025-08-02 15:20:09 +02:00
|
|
|
|
|
|
|
|
// Accept both successful response and redirects for onboarding flow
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
$response->isSuccessful() || $response->isRedirect(),
|
|
|
|
|
"Expected successful response or redirect, got status: " . $response->getStatusCode()
|
|
|
|
|
);
|
2025-08-02 03:48:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_onboarding_channel_page_loads(): void
|
|
|
|
|
{
|
|
|
|
|
$response = $this->get('/onboarding/channel');
|
2025-08-02 15:20:09 +02:00
|
|
|
|
|
|
|
|
// Accept both successful response and redirects for onboarding flow
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
$response->isSuccessful() || $response->isRedirect(),
|
|
|
|
|
"Expected successful response or redirect, got status: " . $response->getStatusCode()
|
|
|
|
|
);
|
2025-08-02 03:48:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_onboarding_complete_page_loads(): void
|
|
|
|
|
{
|
|
|
|
|
$response = $this->get('/onboarding/complete');
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_articles_page_loads_successfully(): void
|
|
|
|
|
{
|
|
|
|
|
$response = $this->get('/articles');
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_articles_approve_endpoint_works(): void
|
|
|
|
|
{
|
2025-08-02 15:20:09 +02:00
|
|
|
Event::fake(); // Disable events to prevent side effects
|
|
|
|
|
|
2025-08-02 03:48:06 +02:00
|
|
|
$feed = Feed::factory()->create();
|
|
|
|
|
$article = Article::factory()->create([
|
|
|
|
|
'feed_id' => $feed->id,
|
|
|
|
|
'approval_status' => 'pending'
|
|
|
|
|
]);
|
2025-08-02 15:20:09 +02:00
|
|
|
|
|
|
|
|
// Ensure article exists in database
|
|
|
|
|
$this->assertDatabaseHas('articles', [
|
|
|
|
|
'id' => $article->id,
|
|
|
|
|
'approval_status' => 'pending'
|
|
|
|
|
]);
|
2025-08-02 03:48:06 +02:00
|
|
|
|
2025-08-02 15:20:09 +02:00
|
|
|
$response = $this->withoutMiddleware()
|
|
|
|
|
->post("/articles/{$article->id}/approve");
|
|
|
|
|
|
2025-08-02 03:48:06 +02:00
|
|
|
$response->assertRedirect();
|
|
|
|
|
|
2025-08-02 15:20:09 +02:00
|
|
|
// Check database directly
|
|
|
|
|
$this->assertDatabaseHas('articles', [
|
|
|
|
|
'id' => $article->id,
|
|
|
|
|
'approval_status' => 'approved'
|
|
|
|
|
]);
|
|
|
|
|
|
2025-08-02 03:48:06 +02:00
|
|
|
$article->refresh();
|
2025-08-02 15:20:09 +02:00
|
|
|
$this->assertEquals('approved', $article->approval_status, 'Article status should be approved after calling approve endpoint');
|
2025-08-02 03:48:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_articles_reject_endpoint_works(): void
|
|
|
|
|
{
|
|
|
|
|
$feed = Feed::factory()->create();
|
|
|
|
|
$article = Article::factory()->create([
|
|
|
|
|
'feed_id' => $feed->id,
|
|
|
|
|
'approval_status' => 'pending'
|
|
|
|
|
]);
|
|
|
|
|
|
2025-08-02 15:20:09 +02:00
|
|
|
$response = $this->withoutMiddleware()
|
|
|
|
|
->post("/articles/{$article->id}/reject");
|
2025-08-02 03:48:06 +02:00
|
|
|
$response->assertRedirect();
|
|
|
|
|
|
|
|
|
|
$article->refresh();
|
|
|
|
|
$this->assertEquals('rejected', $article->approval_status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_logs_page_loads_successfully(): void
|
|
|
|
|
{
|
|
|
|
|
$response = $this->get('/logs');
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_settings_page_loads_successfully(): void
|
|
|
|
|
{
|
|
|
|
|
$response = $this->get('/settings');
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_settings_update_endpoint_works(): void
|
|
|
|
|
{
|
|
|
|
|
Setting::factory()->create([
|
|
|
|
|
'key' => 'test_setting',
|
|
|
|
|
'value' => 'old_value'
|
|
|
|
|
]);
|
|
|
|
|
|
2025-08-02 15:20:09 +02:00
|
|
|
$response = $this->withoutMiddleware()
|
|
|
|
|
->put('/settings', [
|
|
|
|
|
'test_setting' => 'new_value'
|
|
|
|
|
]);
|
2025-08-02 03:48:06 +02:00
|
|
|
|
|
|
|
|
$response->assertRedirect();
|
|
|
|
|
$this->assertEquals('new_value', Setting::where('key', 'test_setting')->first()->value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_platforms_index_loads_successfully(): void
|
|
|
|
|
{
|
|
|
|
|
$response = $this->get('/platforms');
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_platforms_create_loads_successfully(): void
|
|
|
|
|
{
|
|
|
|
|
$response = $this->get('/platforms/create');
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_platforms_show_loads_successfully(): void
|
|
|
|
|
{
|
|
|
|
|
$platform = PlatformAccount::factory()->create();
|
|
|
|
|
|
|
|
|
|
$response = $this->get("/platforms/{$platform->id}");
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_platforms_edit_loads_successfully(): void
|
|
|
|
|
{
|
|
|
|
|
$platform = PlatformAccount::factory()->create();
|
|
|
|
|
|
|
|
|
|
$response = $this->get("/platforms/{$platform->id}/edit");
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_platforms_set_active_endpoint_works(): void
|
|
|
|
|
{
|
|
|
|
|
$platform = PlatformAccount::factory()->create(['is_active' => false]);
|
|
|
|
|
|
2025-08-02 15:20:09 +02:00
|
|
|
$response = $this->withoutMiddleware()
|
|
|
|
|
->post("/platforms/{$platform->id}/set-active");
|
2025-08-02 03:48:06 +02:00
|
|
|
$response->assertRedirect();
|
|
|
|
|
|
|
|
|
|
$platform->refresh();
|
|
|
|
|
$this->assertTrue($platform->is_active);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_channels_index_loads_successfully(): void
|
|
|
|
|
{
|
|
|
|
|
$response = $this->get('/channels');
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_channels_create_loads_successfully(): void
|
|
|
|
|
{
|
|
|
|
|
$response = $this->get('/channels/create');
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_channels_show_loads_successfully(): void
|
|
|
|
|
{
|
|
|
|
|
$channel = PlatformChannel::factory()->create();
|
|
|
|
|
|
|
|
|
|
$response = $this->get("/channels/{$channel->id}");
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_channels_edit_loads_successfully(): void
|
|
|
|
|
{
|
|
|
|
|
$channel = PlatformChannel::factory()->create();
|
|
|
|
|
|
|
|
|
|
$response = $this->get("/channels/{$channel->id}/edit");
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_channels_toggle_endpoint_works(): void
|
|
|
|
|
{
|
|
|
|
|
$channel = PlatformChannel::factory()->create(['is_active' => false]);
|
|
|
|
|
|
2025-08-02 15:20:09 +02:00
|
|
|
$response = $this->withoutMiddleware()
|
|
|
|
|
->post("/channels/{$channel->id}/toggle");
|
2025-08-02 03:48:06 +02:00
|
|
|
$response->assertRedirect();
|
|
|
|
|
|
|
|
|
|
$channel->refresh();
|
|
|
|
|
$this->assertTrue($channel->is_active);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_feeds_index_loads_successfully(): void
|
|
|
|
|
{
|
|
|
|
|
$response = $this->get('/feeds');
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_feeds_create_loads_successfully(): void
|
|
|
|
|
{
|
|
|
|
|
$response = $this->get('/feeds/create');
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_feeds_show_loads_successfully(): void
|
|
|
|
|
{
|
|
|
|
|
$feed = Feed::factory()->create();
|
|
|
|
|
|
|
|
|
|
$response = $this->get("/feeds/{$feed->id}");
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_feeds_edit_loads_successfully(): void
|
|
|
|
|
{
|
|
|
|
|
$feed = Feed::factory()->create();
|
|
|
|
|
|
|
|
|
|
$response = $this->get("/feeds/{$feed->id}/edit");
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_feeds_toggle_endpoint_works(): void
|
|
|
|
|
{
|
|
|
|
|
$feed = Feed::factory()->create(['is_active' => false]);
|
|
|
|
|
|
2025-08-02 15:20:09 +02:00
|
|
|
$response = $this->withoutMiddleware()
|
|
|
|
|
->post("/feeds/{$feed->id}/toggle");
|
2025-08-02 03:48:06 +02:00
|
|
|
$response->assertRedirect();
|
|
|
|
|
|
|
|
|
|
$feed->refresh();
|
|
|
|
|
$this->assertTrue($feed->is_active);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_routing_index_loads_successfully(): void
|
|
|
|
|
{
|
|
|
|
|
$response = $this->get('/routing');
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_routing_create_loads_successfully(): void
|
|
|
|
|
{
|
|
|
|
|
$response = $this->get('/routing/create');
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_routing_edit_loads_successfully(): void
|
|
|
|
|
{
|
|
|
|
|
$feed = Feed::factory()->create();
|
|
|
|
|
$channel = PlatformChannel::factory()->create();
|
|
|
|
|
Route::factory()->create([
|
|
|
|
|
'feed_id' => $feed->id,
|
|
|
|
|
'platform_channel_id' => $channel->id
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->get("/routing/{$feed->id}/{$channel->id}/edit");
|
|
|
|
|
$response->assertSuccessful();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_routing_toggle_endpoint_works(): void
|
|
|
|
|
{
|
|
|
|
|
$feed = Feed::factory()->create();
|
|
|
|
|
$channel = PlatformChannel::factory()->create();
|
|
|
|
|
$route = Route::factory()->create([
|
|
|
|
|
'feed_id' => $feed->id,
|
|
|
|
|
'platform_channel_id' => $channel->id,
|
|
|
|
|
'is_active' => false
|
|
|
|
|
]);
|
|
|
|
|
|
2025-08-02 15:20:09 +02:00
|
|
|
$response = $this->withoutMiddleware()
|
|
|
|
|
->post("/routing/{$feed->id}/{$channel->id}/toggle");
|
2025-08-02 03:48:06 +02:00
|
|
|
$response->assertRedirect();
|
|
|
|
|
|
|
|
|
|
$route->refresh();
|
|
|
|
|
$this->assertTrue($route->is_active);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_all_get_routes_return_successful_status(): void
|
|
|
|
|
{
|
|
|
|
|
// Create necessary test data
|
|
|
|
|
$feed = Feed::factory()->create();
|
|
|
|
|
$channel = PlatformChannel::factory()->create();
|
|
|
|
|
$platform = PlatformAccount::factory()->create();
|
|
|
|
|
Route::factory()->create([
|
|
|
|
|
'feed_id' => $feed->id,
|
|
|
|
|
'platform_channel_id' => $channel->id
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$routes = [
|
|
|
|
|
'/',
|
|
|
|
|
'/onboarding/platform',
|
|
|
|
|
'/onboarding/feed',
|
|
|
|
|
'/onboarding/channel',
|
|
|
|
|
'/onboarding/complete',
|
|
|
|
|
'/articles',
|
|
|
|
|
'/logs',
|
|
|
|
|
'/settings',
|
|
|
|
|
'/platforms',
|
|
|
|
|
'/platforms/create',
|
|
|
|
|
"/platforms/{$platform->id}",
|
|
|
|
|
"/platforms/{$platform->id}/edit",
|
|
|
|
|
'/channels',
|
|
|
|
|
'/channels/create',
|
|
|
|
|
"/channels/{$channel->id}",
|
|
|
|
|
"/channels/{$channel->id}/edit",
|
|
|
|
|
'/feeds',
|
|
|
|
|
'/feeds/create',
|
|
|
|
|
"/feeds/{$feed->id}",
|
|
|
|
|
"/feeds/{$feed->id}/edit",
|
|
|
|
|
'/routing',
|
|
|
|
|
'/routing/create',
|
|
|
|
|
"/routing/{$feed->id}/{$channel->id}/edit",
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach ($routes as $route) {
|
|
|
|
|
$response = $this->get($route);
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
$response->isSuccessful(),
|
|
|
|
|
"Route {$route} failed with status {$response->getStatusCode()}"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|