mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-nostr.git
synced 2026-01-28 07:43:18 +00:00
🗑️ Remove outdated migration files for einundzwanzig_plebs and pulse tables, restructure directory, and update testing suite with new factories and Livewire tests.
This commit is contained in:
110
tests/Feature/Livewire/Association/NewsTest.php
Normal file
110
tests/Feature/Livewire/Association/NewsTest.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\AssociationStatus;
|
||||
use App\Enums\NewsCategory;
|
||||
use App\Models\EinundzwanzigPleb;
|
||||
use App\Models\Notification;
|
||||
use App\Support\NostrAuth;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Livewire;
|
||||
|
||||
beforeEach(function () {
|
||||
Storage::fake('public');
|
||||
});
|
||||
|
||||
it('denies access when pleb has insufficient association status', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create([
|
||||
'association_status' => AssociationStatus::PASSIVE,
|
||||
]);
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.news')
|
||||
->assertSet('isAllowed', false);
|
||||
});
|
||||
|
||||
it('denies access when pleb has not paid for current year', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create([
|
||||
'association_status' => AssociationStatus::ACTIVE,
|
||||
]);
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.news')
|
||||
->assertSet('isAllowed', false);
|
||||
});
|
||||
|
||||
it('grants access when pleb is active and has paid', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->active()->withPaidCurrentYear()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.news')
|
||||
->assertSet('isAllowed', true);
|
||||
});
|
||||
|
||||
it('allows board member to edit news', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->boardMember()->withPaidCurrentYear()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.news')
|
||||
->assertSet('canEdit', true);
|
||||
});
|
||||
|
||||
it('can create news entry with pdf', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->boardMember()->withPaidCurrentYear()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
$file = UploadedFile::fake()->create('document.pdf', 100);
|
||||
|
||||
Livewire::test('association.news')
|
||||
->set('file', $file)
|
||||
->set('form.category', NewsCategory::ORGANISATION->value)
|
||||
->set('form.name', 'Test News')
|
||||
->set('form.description', 'Test Description')
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect(Notification::where('name', 'Test News')->exists())->toBeTrue();
|
||||
});
|
||||
|
||||
it('validates news entry creation', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->boardMember()->withPaidCurrentYear()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.news')
|
||||
->call('save')
|
||||
->assertHasErrors(['file', 'form.category', 'form.name']);
|
||||
});
|
||||
|
||||
it('can delete news entry', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->boardMember()->withPaidCurrentYear()->create();
|
||||
$news = Notification::factory()->create([
|
||||
'einundzwanzig_pleb_id' => $pleb->id,
|
||||
]);
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.news')
|
||||
->call('delete', $news->id)
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect(Notification::find($news->id))->toBeNull();
|
||||
});
|
||||
|
||||
it('displays news list', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->active()->withPaidCurrentYear()->create();
|
||||
$news1 = Notification::factory()->create();
|
||||
$news2 = Notification::factory()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.news')
|
||||
->assertSet('isAllowed', true)
|
||||
->assertSee($news1->name)
|
||||
->assertSee($news2->name);
|
||||
});
|
||||
Reference in New Issue
Block a user