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:
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
it('returns a successful response', function () {
|
||||
$response = $this->get('/');
|
||||
use Livewire\Livewire;
|
||||
|
||||
$response->assertStatus(200);
|
||||
it('returns a successful response', function () {
|
||||
Livewire::test('association.profile')
|
||||
->assertStatus(200);
|
||||
});
|
||||
|
||||
145
tests/Feature/Livewire/Association/ElectionTest.php
Normal file
145
tests/Feature/Livewire/Association/ElectionTest.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
use App\Models\EinundzwanzigPleb;
|
||||
use App\Models\Election;
|
||||
use App\Support\NostrAuth;
|
||||
use Livewire\Livewire;
|
||||
|
||||
it('loads elections on mount', function () {
|
||||
$election1 = Election::factory()->create(['year' => 2024]);
|
||||
$election2 = Election::factory()->create(['year' => 2025]);
|
||||
|
||||
Livewire::test('association.election.index')
|
||||
->assertSet('elections', function ($elections) {
|
||||
return count($elections) >= 2;
|
||||
});
|
||||
});
|
||||
|
||||
it('denies access to unauthorized users in election index', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create();
|
||||
$election = Election::factory()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.election.index', ['election' => $election])
|
||||
->assertSet('isAllowed', false);
|
||||
});
|
||||
|
||||
it('grants access to authorized users in election index', function () {
|
||||
$allowedPubkey = '0adf67475ccc5ca456fd3022e46f5d526eb0af6284bf85494c0dd7847f3e5033';
|
||||
$pleb = EinundzwanzigPleb::factory()->create(['pubkey' => $allowedPubkey]);
|
||||
$election = Election::factory()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.election.index', ['election' => $election])
|
||||
->assertSet('isAllowed', true);
|
||||
});
|
||||
|
||||
// Election Admin Tests
|
||||
it('renders election admin component', function () {
|
||||
$election = Election::factory()->create();
|
||||
|
||||
Livewire::test('association.election.admin', ['election' => $election])
|
||||
->assertStatus(200);
|
||||
});
|
||||
|
||||
it('denies access to unauthorized users in election admin', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create();
|
||||
$election = Election::factory()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.election.admin', ['election' => $election])
|
||||
->assertSet('isAllowed', false);
|
||||
});
|
||||
|
||||
it('grants access to authorized users in election admin', function () {
|
||||
$allowedPubkey = '0adf67475ccc5ca456fd3022e46f5d526eb0af6284bf85494c0dd7847f3e5033';
|
||||
$pleb = EinundzwanzigPleb::factory()->create(['pubkey' => $allowedPubkey]);
|
||||
$election = Election::factory()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.election.admin', ['election' => $election])
|
||||
->assertSet('isAllowed', true);
|
||||
});
|
||||
|
||||
it('can save election candidates', function () {
|
||||
$allowedPubkey = '0adf67475ccc5ca456fd3022e46f5d526eb0af6284bf85494c0dd7847f3e5033';
|
||||
$pleb = EinundzwanzigPleb::factory()->create(['pubkey' => $allowedPubkey]);
|
||||
$election = Election::factory()->create([
|
||||
'candidates' => json_encode([['type' => 'presidency', 'c' => []]]),
|
||||
]);
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
$newCandidates = json_encode([['type' => 'presidency', 'c' => ['test-pubkey']]]);
|
||||
|
||||
Livewire::test('association.election.admin', ['election' => $election])
|
||||
->set('elections.0.candidates', $newCandidates)
|
||||
->call('saveElection', 0);
|
||||
|
||||
expect($election->fresh()->candidates)->toBe($newCandidates);
|
||||
});
|
||||
|
||||
// Election Show Tests
|
||||
it('renders election show component', function () {
|
||||
$election = Election::factory()->create();
|
||||
|
||||
Livewire::test('association.election.show', ['election' => $election])
|
||||
->assertStatus(200);
|
||||
});
|
||||
|
||||
it('loads election data on mount in show', function () {
|
||||
$election = Election::factory()->create();
|
||||
|
||||
Livewire::test('association.election.show', ['election' => $election])
|
||||
->assertSet('election.id', $election->id);
|
||||
});
|
||||
|
||||
it('handles search in election show', function () {
|
||||
$election = Election::factory()->create();
|
||||
$pleb1 = EinundzwanzigPleb::factory()->active()->create();
|
||||
$pleb2 = EinundzwanzigPleb::factory()->boardMember()->create();
|
||||
|
||||
Livewire::test('association.election.show', ['election' => $election])
|
||||
->set('search', $pleb1->pubkey)
|
||||
->assertSet('plebs', function ($plebs) use ($pleb1) {
|
||||
return collect($plebs)->contains('pubkey', $pleb1->pubkey);
|
||||
});
|
||||
});
|
||||
|
||||
it('can create vote event', function () {
|
||||
$election = Election::factory()->create();
|
||||
$pleb = EinundzwanzigPleb::factory()->active()->create();
|
||||
$candidatePubkey = 'test-candidate-pubkey';
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.election.show', ['election' => $election])
|
||||
->call('vote', $candidatePubkey, 'presidency', false)
|
||||
->assertSet('signThisEvent', function ($event) use ($candidatePubkey) {
|
||||
return str_contains($event, $candidatePubkey);
|
||||
});
|
||||
});
|
||||
|
||||
it('checks election closure status', function () {
|
||||
$election = Election::factory()->create([
|
||||
'end_time' => now()->subDay(),
|
||||
]);
|
||||
|
||||
Livewire::test('association.election.show', ['election' => $election])
|
||||
->call('checkElection')
|
||||
->assertSet('isNotClosed', false);
|
||||
});
|
||||
|
||||
it('displays log for authorized users', function () {
|
||||
$allowedPubkey = '0adf67475ccc5ca456fd3022e46f5d526eb0af6284bf85494c0dd7847f3e5033';
|
||||
$pleb = EinundzwanzigPleb::factory()->create(['pubkey' => $allowedPubkey]);
|
||||
$election = Election::factory()->create();
|
||||
|
||||
Livewire::test('association.election.show', ['election' => $election])
|
||||
->call('handleNostrLoggedIn', $allowedPubkey)
|
||||
->assertSet('showLog', true);
|
||||
});
|
||||
73
tests/Feature/Livewire/Association/Members/AdminTest.php
Normal file
73
tests/Feature/Livewire/Association/Members/AdminTest.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
use App\Models\EinundzwanzigPleb;
|
||||
use App\Support\NostrAuth;
|
||||
use Livewire\Livewire;
|
||||
|
||||
it('denies access to unauthorized users', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.members.admin')
|
||||
->assertSet('isAllowed', false)
|
||||
->assertSee('Du bist nicht berechtigt, Mitglieder zu bearbeiten.');
|
||||
});
|
||||
|
||||
it('grants access to authorized pubkeys', function () {
|
||||
$allowedPubkeys = [
|
||||
'0adf67475ccc5ca456fd3022e46f5d526eb0af6284bf85494c0dd7847f3e5033',
|
||||
'430169631f2f0682c60cebb4f902d68f0c71c498fd1711fd982f052cf1fd4279',
|
||||
'7acf30cf60b85c62b8f654556cc21e4016df8f5604b3b6892794f88bb80d7a1d',
|
||||
'f240be2b684f85cc81566f2081386af81d7427ea86250c8bde6b7a8500c761ba',
|
||||
'19e358b8011f5f4fc653c565c6d4c2f33f32661f4f90982c9eedc292a8774ec3',
|
||||
'acbcec475a1a4f9481939ecfbd1c3d111f5b5a474a39ae039bbc720fdd305bec',
|
||||
];
|
||||
|
||||
$pleb = EinundzwanzigPleb::factory()->create([
|
||||
'pubkey' => $allowedPubkeys[0],
|
||||
]);
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.members.admin')
|
||||
->assertSet('isAllowed', true);
|
||||
});
|
||||
|
||||
it('handles nostr login for authorized user', function () {
|
||||
$allowedPubkey = '0adf67475ccc5ca456fd3022e46f5d526eb0af6284bf85494c0dd7847f3e5033';
|
||||
$pleb = EinundzwanzigPleb::factory()->create([
|
||||
'pubkey' => $allowedPubkey,
|
||||
]);
|
||||
|
||||
Livewire::test('association.members.admin')
|
||||
->call('handleNostrLoggedIn', $allowedPubkey)
|
||||
->assertSet('isAllowed', true)
|
||||
->assertSet('currentPubkey', $allowedPubkey);
|
||||
});
|
||||
|
||||
it('handles nostr logout', function () {
|
||||
$allowedPubkey = '0adf67475ccc5ca456fd3022e46f5d526eb0af6284bf85494c0dd7847f3e5033';
|
||||
$pleb = EinundzwanzigPleb::factory()->create([
|
||||
'pubkey' => $allowedPubkey,
|
||||
]);
|
||||
|
||||
Livewire::test('association.members.admin')
|
||||
->call('handleNostrLoggedIn', $allowedPubkey)
|
||||
->call('handleNostrLoggedOut')
|
||||
->assertSet('isAllowed', false)
|
||||
->assertSet('currentPubkey', null);
|
||||
});
|
||||
|
||||
it('displays einundzwanzig pleb table when authorized', function () {
|
||||
$allowedPubkey = '0adf67475ccc5ca456fd3022e46f5d526eb0af6284bf85494c0dd7847f3e5033';
|
||||
$pleb = EinundzwanzigPleb::factory()->create([
|
||||
'pubkey' => $allowedPubkey,
|
||||
]);
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.members.admin')
|
||||
->assertSet('isAllowed', true)
|
||||
->assertSee('einundzwanzig-pleb-table');
|
||||
});
|
||||
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);
|
||||
});
|
||||
116
tests/Feature/Livewire/Association/ProfileTest.php
Normal file
116
tests/Feature/Livewire/Association/ProfileTest.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\AssociationStatus;
|
||||
use App\Models\EinundzwanzigPleb;
|
||||
use App\Support\NostrAuth;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Livewire\Livewire;
|
||||
|
||||
it('handles nostr login correctly', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create();
|
||||
|
||||
Livewire::test('association.profile')
|
||||
->call('handleNostrLoggedIn', $pleb->pubkey)
|
||||
->assertSet('currentPubkey', $pleb->pubkey)
|
||||
->assertSet('currentPleb.pubkey', $pleb->pubkey);
|
||||
});
|
||||
|
||||
it('handles nostr logout correctly', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create();
|
||||
|
||||
Livewire::test('association.profile')
|
||||
->call('handleNostrLoggedIn', $pleb->pubkey)
|
||||
->call('handleNostrLoggedOut')
|
||||
->assertSet('currentPubkey', null)
|
||||
->assertSet('currentPleb', null);
|
||||
});
|
||||
|
||||
it('can save email address', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.profile')
|
||||
->set('email', 'test@example.com')
|
||||
->call('saveEmail')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect($pleb->fresh()->email)->toBe('test@example.com');
|
||||
});
|
||||
|
||||
it('validates email format', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.profile')
|
||||
->set('email', 'invalid-email')
|
||||
->call('saveEmail')
|
||||
->assertHasErrors(['email']);
|
||||
});
|
||||
|
||||
it('can update no email preference', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.profile')
|
||||
->set('no', true)
|
||||
->assertSet('showEmail', false);
|
||||
|
||||
expect($pleb->fresh()->no_email)->toBeTrue();
|
||||
});
|
||||
|
||||
it('can save membership application', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create([
|
||||
'association_status' => AssociationStatus::DEFAULT,
|
||||
]);
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.profile')
|
||||
->set('form.check', true)
|
||||
->call('save', AssociationStatus::PASSIVE->value)
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect($pleb->fresh()->association_status)->toBe(AssociationStatus::PASSIVE);
|
||||
});
|
||||
|
||||
it('creates payment event when pleb becomes active', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->active()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.profile')
|
||||
->assertSet('amountToPay', config('app.env') === 'production' ? 21000 : 1);
|
||||
|
||||
expect($pleb->paymentEvents()->count())->toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('displays paid status for current year', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->active()->withPaidCurrentYear()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.profile')
|
||||
->call('listenForPayment')
|
||||
->assertSet('currentYearIsPaid', true);
|
||||
});
|
||||
|
||||
it('can initiate payment', function () {
|
||||
Http::fake([
|
||||
'pay.einundzwanzig.space/*' => Http::response([
|
||||
'id' => 'invoice123',
|
||||
'checkoutLink' => 'https://pay.einundzwanzig.space/checkout/invoice123',
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$pleb = EinundzwanzigPleb::factory()->active()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
$response = Livewire::test('association.profile')
|
||||
->call('pay', 'test-comment');
|
||||
|
||||
$response->assertRedirect();
|
||||
});
|
||||
228
tests/Feature/Livewire/Association/ProjectSupportTest.php
Normal file
228
tests/Feature/Livewire/Association/ProjectSupportTest.php
Normal file
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
|
||||
use App\Models\EinundzwanzigPleb;
|
||||
use App\Models\ProjectProposal;
|
||||
use App\Support\NostrAuth;
|
||||
use Livewire\Livewire;
|
||||
|
||||
it('loads projects on mount', function () {
|
||||
$project1 = ProjectProposal::factory()->create();
|
||||
$project2 = ProjectProposal::factory()->create();
|
||||
|
||||
Livewire::test('association.project-support.index')
|
||||
->assertSet('projects', function ($projects) {
|
||||
return $projects->count() >= 2;
|
||||
});
|
||||
});
|
||||
|
||||
it('can search projects', function () {
|
||||
$project = ProjectProposal::factory()->create(['name' => 'Unique Project Name']);
|
||||
|
||||
Livewire::test('association.project-support.index')
|
||||
->set('search', 'Unique')
|
||||
->assertSet('projects', function ($projects) use ($project) {
|
||||
return $projects->contains('id', $project->id);
|
||||
});
|
||||
});
|
||||
|
||||
it('can filter projects', function () {
|
||||
Livewire::test('association.project-support.index')
|
||||
->call('setFilter', 'new')
|
||||
->assertSet('activeFilter', 'new');
|
||||
});
|
||||
|
||||
it('can confirm delete', function () {
|
||||
$project = ProjectProposal::factory()->create();
|
||||
|
||||
Livewire::test('association.project-support.index')
|
||||
->call('confirmDelete', $project->id)
|
||||
->assertSet('confirmDeleteId', $project->id);
|
||||
});
|
||||
|
||||
it('can delete project', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->boardMember()->create();
|
||||
$project = ProjectProposal::factory()->create([
|
||||
'einundzwanzig_pleb_id' => $pleb->id,
|
||||
]);
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.project-support.index')
|
||||
->set('confirmDeleteId', $project->id)
|
||||
->call('delete');
|
||||
|
||||
expect(ProjectProposal::find($project->id))->toBeNull();
|
||||
});
|
||||
|
||||
it('handles nostr login', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create();
|
||||
|
||||
Livewire::test('association.project-support.index')
|
||||
->call('handleNostrLoggedIn', $pleb->pubkey)
|
||||
->assertSet('currentPubkey', $pleb->pubkey)
|
||||
->assertSet('isAllowed', true);
|
||||
});
|
||||
|
||||
it('handles nostr logout', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create();
|
||||
|
||||
Livewire::test('association.project-support.index')
|
||||
->call('handleNostrLoggedIn', $pleb->pubkey)
|
||||
->call('handleNostrLoggedOut')
|
||||
->assertSet('currentPubkey', null)
|
||||
->assertSet('isAllowed', false);
|
||||
});
|
||||
|
||||
it('denies access to create when not authenticated', function () {
|
||||
Livewire::test('association.project-support.form.create')
|
||||
->assertSet('isAllowed', false)
|
||||
->assertSee('Du bist nicht berechtigt, eine Projektförderung anzulegen.');
|
||||
});
|
||||
|
||||
it('denies access to create when pleb has not paid', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->active()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.project-support.form.create')
|
||||
->assertSet('isAllowed', false);
|
||||
});
|
||||
|
||||
it('grants access to create when pleb is active and paid', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->active()->withPaidCurrentYear()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.project-support.form.create')
|
||||
->assertSet('isAllowed', true);
|
||||
});
|
||||
|
||||
it('can create project proposal', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->active()->withPaidCurrentYear()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.project-support.form.create')
|
||||
->set('form.name', 'Test Project')
|
||||
->set('form.description', 'Test Description')
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect(ProjectProposal::where('name', 'Test Project')->exists())->toBeTrue();
|
||||
});
|
||||
|
||||
it('validates project proposal creation', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->active()->withPaidCurrentYear()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.project-support.form.create')
|
||||
->call('save')
|
||||
->assertHasErrors(['form.name', 'form.description']);
|
||||
});
|
||||
|
||||
// Project Support Edit Tests
|
||||
it('renders project support edit component', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create();
|
||||
$project = ProjectProposal::factory()->create([
|
||||
'einundzwanzig_pleb_id' => $pleb->id,
|
||||
]);
|
||||
|
||||
Livewire::test('association.project-support.form.edit', ['project' => $project])
|
||||
->assertStatus(200);
|
||||
});
|
||||
|
||||
it('denies access to edit when not owner', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create();
|
||||
$project = ProjectProposal::factory()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.project-support.form.edit', ['project' => $project])
|
||||
->assertSet('isAllowed', false);
|
||||
});
|
||||
|
||||
it('grants access to edit when owner', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create();
|
||||
$project = ProjectProposal::factory()->create([
|
||||
'einundzwanzig_pleb_id' => $pleb->id,
|
||||
]);
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.project-support.form.edit', ['project' => $project])
|
||||
->assertSet('isAllowed', true);
|
||||
});
|
||||
|
||||
it('can update project proposal', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create();
|
||||
$project = ProjectProposal::factory()->create([
|
||||
'einundzwanzig_pleb_id' => $pleb->id,
|
||||
'name' => 'Old Name',
|
||||
]);
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.project-support.form.edit', ['project' => $project])
|
||||
->set('form.name', 'New Name')
|
||||
->set('form.description', 'Updated Description')
|
||||
->call('update')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect($project->fresh()->name)->toBe('New Name');
|
||||
});
|
||||
|
||||
it('validates project proposal update', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create();
|
||||
$project = ProjectProposal::factory()->create([
|
||||
'einundzwanzig_pleb_id' => $pleb->id,
|
||||
]);
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.project-support.form.edit', ['project' => $project])
|
||||
->set('form.name', '')
|
||||
->call('update')
|
||||
->assertHasErrors(['form.name']);
|
||||
});
|
||||
|
||||
// Project Support Show Tests
|
||||
it('renders project support show component', function () {
|
||||
$project = ProjectProposal::factory()->create();
|
||||
|
||||
Livewire::test('association.project-support.show', ['project' => $project])
|
||||
->assertStatus(200);
|
||||
});
|
||||
|
||||
it('denies access to show when not authenticated', function () {
|
||||
$project = ProjectProposal::factory()->create();
|
||||
|
||||
Livewire::test('association.project-support.show', ['project' => $project])
|
||||
->assertSet('isAllowed', false)
|
||||
->assertSee('Du bist nicht berechtigt, die Projektförderung einzusehen.');
|
||||
});
|
||||
|
||||
it('grants access to show when authenticated', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create();
|
||||
$project = ProjectProposal::factory()->create();
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.project-support.show', ['project' => $project])
|
||||
->assertSet('isAllowed', true);
|
||||
});
|
||||
|
||||
it('displays project details', function () {
|
||||
$pleb = EinundzwanzigPleb::factory()->create();
|
||||
$project = ProjectProposal::factory()->create([
|
||||
'name' => 'Test Project Name',
|
||||
'description' => 'Test Project Description',
|
||||
]);
|
||||
|
||||
NostrAuth::login($pleb->pubkey);
|
||||
|
||||
Livewire::test('association.project-support.show', ['project' => $project])
|
||||
->assertSet('project.name', 'Test Project Name')
|
||||
->assertSee('Test Project Name')
|
||||
->assertSee('Test Project Description');
|
||||
});
|
||||
Reference in New Issue
Block a user