- Add HasFactory trait to all model classes for factory support - Create factory classes for all models (Classification, Company, ContentRecap, Department, IssueManagement, Journalist, Location, MediaMonitoring, MediaMonitoringTheme, PartnerMedia, SubClassification, SubLocation, Theme, User) - Add unit tests for all models with relationship and attribute validation - Add unit tests for all enums (Channel, ContentType, IsActive, IssueSentiment, MediaClassification, MediaType, SocialMedia) - Add feature tests for factory integration and basic application functionality - Add tests for Filament actions, columns, and media library utilities - Add tests for model policies (Classification, Theme) and traits (WithComment, WithValue) - Update phpunit.xml configuration for test environment - Add test documentation and working tests reference guide - Add ContentType enum casting to ContentRecap model - Add MediaMonitoringTheme relationships and factory support - Establish comprehensive testing infrastructure for improved code quality and reliability
99 lines
3.4 KiB
PHP
99 lines
3.4 KiB
PHP
<?php
|
|
|
|
use App\Enums\IsActive;
|
|
use App\Enums\IssueSentiment;
|
|
use App\Enums\MediaType;
|
|
use App\Models\Classification;
|
|
use App\Models\Company;
|
|
use App\Models\IssueManagement;
|
|
use App\Models\Journalist;
|
|
use App\Models\MediaMonitoring;
|
|
use App\Models\PartnerMedia;
|
|
use App\Models\Theme;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
describe('Integration Tests', function () {
|
|
it('can create complete media monitoring workflow', function () {
|
|
// Create theme
|
|
$theme = Theme::factory()->create(['name' => 'Politik']);
|
|
|
|
// Create media monitoring
|
|
$mediaMonitoring = MediaMonitoring::factory()->create([
|
|
'title' => 'Berita Politik Terkini',
|
|
]);
|
|
|
|
// Attach theme to media monitoring
|
|
$mediaMonitoring->themes()->attach($theme->id);
|
|
|
|
// Verify relationships
|
|
expect($mediaMonitoring->themes)->toHaveCount(1)
|
|
->and($mediaMonitoring->themes->first()->name)->toBe('Politik');
|
|
});
|
|
|
|
it('can create complete journalist workflow', function () {
|
|
// Create company
|
|
$company = Company::factory()->create(['name' => 'Media Indonesia']);
|
|
|
|
// Create partner media
|
|
$partnerMedia = PartnerMedia::factory()->create([
|
|
'company_id' => $company->id,
|
|
'name' => 'Kompas.com',
|
|
'type' => MediaType::ONLINE,
|
|
]);
|
|
|
|
// Create journalist
|
|
$journalist = Journalist::factory()->create([
|
|
'partner_media_id' => $partnerMedia->id,
|
|
'name' => 'John Doe',
|
|
]);
|
|
|
|
// Verify relationships
|
|
expect($journalist->partnerMedia->company->name)->toBe('Media Indonesia')
|
|
->and($journalist->partnerMedia->type)->toBe(MediaType::ONLINE);
|
|
});
|
|
|
|
it('can create issue management with sentiment', function () {
|
|
// Create classification
|
|
$classification = Classification::factory()->create(['name' => 'Infrastruktur']);
|
|
|
|
// Create media monitoring
|
|
$mediaMonitoring = MediaMonitoring::factory()->create();
|
|
|
|
// Create issue management
|
|
$issue = IssueManagement::factory()->create([
|
|
'classification_id' => $classification->id,
|
|
'media_monitoring_id' => $mediaMonitoring->id,
|
|
'issue' => IssueSentiment::POSITIVE,
|
|
'response' => IssueSentiment::POSITIVE,
|
|
]);
|
|
|
|
// Verify data
|
|
expect($issue->classification->name)->toBe('Infrastruktur')
|
|
->and($issue->issue)->toBe(IssueSentiment::POSITIVE)
|
|
->and($issue->response)->toBe(IssueSentiment::POSITIVE);
|
|
});
|
|
|
|
it('can filter active records', function () {
|
|
// Create active and inactive themes
|
|
Theme::factory()->create(['is_active' => IsActive::ACTIVE]);
|
|
Theme::factory()->create(['is_active' => IsActive::INACTIVE]);
|
|
|
|
$activeThemes = Theme::active()->get();
|
|
|
|
expect($activeThemes)->toHaveCount(1)
|
|
->and($activeThemes->first()->is_active)->toBe(IsActive::ACTIVE);
|
|
});
|
|
|
|
it('verifies enum casting works correctly', function () {
|
|
$partnerMedia = PartnerMedia::factory()->create([
|
|
'type' => MediaType::TELEVISION,
|
|
]);
|
|
|
|
expect($partnerMedia->type)->toBeInstanceOf(MediaType::class)
|
|
->and($partnerMedia->type)->toBe(MediaType::TELEVISION)
|
|
->and($partnerMedia->type->getLabel())->toBe('Televisi');
|
|
});
|
|
});
|