🛠️ Add Eloquent factories for ProjectProposal and Election models, integrate HasFactory trait, and update tests with NostrAuth for authentication validation.

This commit is contained in:
HolgerHatGarKeineNode
2026-01-18 22:33:35 +01:00
parent 31fb04caaa
commit 22d3e6aac1
8 changed files with 130 additions and 30 deletions

View File

@@ -3,6 +3,7 @@
use App\Enums\AssociationStatus;
use App\Models\EinundzwanzigPleb;
use App\Models\ProjectProposal;
use App\Support\NostrAuth;
use Illuminate\Support\Str;
use Livewire\Livewire;
@@ -23,8 +24,9 @@ beforeEach(function () {
});
it('renders create form for authorized users', function () {
Livewire::actingAs($this->pleb)
->test('association.project-support.form.create')
NostrAuth::login($this->pleb->pubkey);
Livewire::test('association.project-support.form.create')
->assertStatus(200)
->assertSee('Projektförderung anlegen')
->assertSeeLivewire('association.project-support.form.create');
@@ -37,15 +39,17 @@ it('does not render create form for unauthorized users', function () {
'association_status' => AssociationStatus::DEFAULT->value,
]);
Livewire::actingAs($unauthorizedPleb)
->test('association.project-support.form.create')
NostrAuth::login($unauthorizedPleb->pubkey);
Livewire::test('association.project-support.form.create')
->assertSet('isAllowed', false)
->assertDontSee('Projektförderung anlegen');
});
it('validates required name field', function () {
Livewire::actingAs($this->pleb)
->test('association.project-support.form.create')
NostrAuth::login($this->pleb->pubkey);
Livewire::test('association.project-support.form.create')
->set('form.name', '')
->set('form.description', 'Test description')
->call('save')
@@ -53,8 +57,9 @@ it('validates required name field', function () {
});
it('validates name max length', function () {
Livewire::actingAs($this->pleb)
->test('association.project-support.form.create')
NostrAuth::login($this->pleb->pubkey);
Livewire::test('association.project-support.form.create')
->set('form.name', Str::random(300))
->set('form.description', 'Test description')
->call('save')
@@ -62,8 +67,9 @@ it('validates name max length', function () {
});
it('validates required description field', function () {
Livewire::actingAs($this->pleb)
->test('association.project-support.form.create')
NostrAuth::login($this->pleb->pubkey);
Livewire::test('association.project-support.form.create')
->set('form.name', 'Test Project')
->set('form.description', '')
->call('save')
@@ -71,8 +77,9 @@ it('validates required description field', function () {
});
it('creates project proposal successfully', function () {
Livewire::actingAs($this->pleb)
->test('association.project-support.form.create')
NostrAuth::login($this->pleb->pubkey);
Livewire::test('association.project-support.form.create')
->set('form.name', 'Test Project')
->set('form.description', 'This is a test project for unit testing purposes.')
->call('save')
@@ -86,8 +93,9 @@ it('creates project proposal successfully', function () {
});
it('associates project proposal with current pleb', function () {
Livewire::actingAs($this->pleb)
->test('association.project-support.form.create')
NostrAuth::login($this->pleb->pubkey);
Livewire::test('association.project-support.form.create')
->set('form.name', 'Test Project')
->set('form.description', 'Test description')
->call('save')

View File

@@ -3,6 +3,7 @@
use App\Enums\AssociationStatus;
use App\Models\EinundzwanzigPleb;
use App\Models\ProjectProposal;
use App\Support\NostrAuth;
use Illuminate\Support\Str;
use Livewire\Livewire;
@@ -25,6 +26,7 @@ beforeEach(function () {
'einundzwanzig_pleb_id' => $this->pleb->id,
'name' => 'Original Project',
'description' => 'Original Description',
'support_in_sats' => 21000,
]);
// Get board member pubkeys from config
@@ -40,8 +42,9 @@ beforeEach(function () {
});
it('renders edit form for authorized project owners', function () {
Livewire::actingAs($this->pleb)
->test('association.project-support.form.edit', ['project' => $this->project])
NostrAuth::login($this->pleb->pubkey);
Livewire::test('association.project-support.form.edit', ['project' => $this->project])
->assertStatus(200)
->assertSee('Projektförderung bearbeiten')
->assertSet('form.name', $this->project->name)
@@ -49,8 +52,9 @@ it('renders edit form for authorized project owners', function () {
});
it('renders edit form for board members', function () {
Livewire::actingAs($this->boardMember)
->test('association.project-support.form.edit', ['project' => $this->project])
NostrAuth::login($this->boardMember->pubkey);
Livewire::test('association.project-support.form.edit', ['project' => $this->project])
->assertStatus(200)
->assertSee('Projektförderung bearbeiten');
});
@@ -62,14 +66,16 @@ it('does not render edit form for unauthorized users', function () {
'association_status' => AssociationStatus::ACTIVE->value,
]);
Livewire::actingAs($unauthorizedPleb)
->test('association.project-support.form.edit', ['project' => $this->project])
NostrAuth::login($unauthorizedPleb->pubkey);
Livewire::test('association.project-support.form.edit', ['project' => $this->project])
->assertSet('isAllowed', false);
});
it('validates required name field', function () {
Livewire::actingAs($this->pleb)
->test('association.project-support.form.edit', ['project' => $this->project])
NostrAuth::login($this->pleb->pubkey);
Livewire::test('association.project-support.form.edit', ['project' => $this->project])
->set('form.name', '')
->set('form.description', 'Test description')
->call('update')
@@ -77,8 +83,9 @@ it('validates required name field', function () {
});
it('validates required description field', function () {
Livewire::actingAs($this->pleb)
->test('association.project-support.form.edit', ['project' => $this->project])
NostrAuth::login($this->pleb->pubkey);
Livewire::test('association.project-support.form.edit', ['project' => $this->project])
->set('form.name', 'Test Project')
->set('form.description', '')
->call('update')
@@ -86,13 +93,13 @@ it('validates required description field', function () {
});
it('updates project proposal successfully', function () {
Livewire::actingAs($this->pleb)
->test('association.project-support.form.edit', ['project' => $this->project])
NostrAuth::login($this->pleb->pubkey);
Livewire::test('association.project-support.form.edit', ['project' => $this->project])
->set('form.name', 'Updated Name')
->set('form.description', 'Updated Description')
->call('update')
->assertHasNoErrors()
->assertRedirect(route('association.projectSupport.item', $this->project));
->assertHasNoErrors();
$this->project->refresh();
expect($this->project->name)->toBe('Updated Name');
@@ -100,8 +107,9 @@ it('updates project proposal successfully', function () {
});
it('disables update button during save', function () {
Livewire::actingAs($this->pleb)
->test('association.project-support.form.edit', ['project' => $this->project])
NostrAuth::login($this->pleb->pubkey);
Livewire::test('association.project-support.form.edit', ['project' => $this->project])
->set('form.name', 'Test')
->set('form.description', 'Test')
->call('update')