withoutExceptionHandling()->login()->loginNami(); $typeParams = MailmanTypeRequest::new()->state(['url' => 'https://mailman.example.com', 'user' => 'user', 'password' => 'password', 'owner' => 'owner']); $mailgateway = Mailgateway::factory()->type($typeParams->toData())->create(['name' => '::name::', 'domain' => 'example.com']); Livewire::test(Form::class, ['id' => $mailgateway->id]) ->assertSet('model', fn ($m) => $m->is($mailgateway)) ->assertSet('name', '::name::') ->assertSet('domain', 'example.com') ->assertSet( 'type', fn ($type) => $type instanceof MailmanType && $type->url === 'https://mailman.example.com' && $type->user === 'user' && $type->password === 'password' && $type->owner === 'owner' ); }); it('test it sets attributes for local', function () { test()->withoutExceptionHandling()->login()->loginNami(); $mailgateway = Mailgateway::factory()->create(['name' => '::name::', 'domain' => 'example.com']); Livewire::test(Form::class, ['id' => $mailgateway->id]) ->assertSet('name', '::name::') ->assertSet('domain', 'example.com') ->assertSet('type', fn ($type) => $type instanceof LocalType); }); it('test it validates type', function () { test()->withoutExceptionHandling()->login()->loginNami(); $mailgateway = Mailgateway::factory()->type(LocalType::class, [])->create(['name' => '::name::', 'domain' => 'example.com']); Livewire::test(Form::class, ['id' => $mailgateway->id]) ->set('cls', '') ->assertHasErrors(['cls' => 'required']); }); it('test it updates a mailman gateway without updating password', function () { test()->withoutExceptionHandling()->login()->loginNami(); $typeParams = MailmanTypeRequest::new()->succeeds()->create(['url' => 'https://mailman.example.com', 'user' => 'user', 'password' => 'password', 'owner' => 'owner@example.com']); $mailgateway = Mailgateway::factory()->type(MailmanType::class, $typeParams)->create(['name' => '::name::', 'domain' => 'example.com']); Livewire::test(Form::class, ['id' => $mailgateway->id]) ->set('name', '::newname::') ->call('onSave') ->assertHasNoErrors() ->assertDispatched('closeModal') ->assertDispatched('refresh-page') ->assertDispatched('success'); $this->assertDatabaseCount('mailgateways', 1); $this->assertDatabaseHas('mailgateways', [ 'name' => '::newname::', 'type' => json_encode(['cls' => MailmanType::class, 'params' => $typeParams]), ]); }); it('test it updates a mailman gateway with password', function () { test()->withoutExceptionHandling()->login()->loginNami(); $typeParams = MailmanTypeRequest::new()->create(['url' => 'https://mailman.example.com', 'user' => 'user', 'password' => 'password', 'owner' => 'owner@example.com']); $newTypeParams = MailmanTypeRequest::new()->succeeds()->create(['url' => 'https://mailman.example.com', 'user' => 'newuser', 'password' => 'password', 'owner' => 'owner@example.com']); $mailgateway = Mailgateway::factory()->type(MailmanType::class, $typeParams)->create(); Livewire::test(Form::class, ['id' => $mailgateway->id]) ->set('params.user', 'newuser') ->call('onSave') ->assertHasNoErrors(); $this->assertDatabaseCount('mailgateways', 1); $this->assertDatabaseHas('mailgateways', [ 'type' => json_encode(['cls' => MailmanType::class, 'params' => $newTypeParams]), ]); }); it('test it checks mailgateway connection when updating', function () { test()->withoutExceptionHandling()->login()->loginNami(); $typeParams = MailmanTypeRequest::new()->create(['url' => 'https://mailman.example.com', 'user' => 'user', 'password' => 'password', 'owner' => 'owner@example.com']); MailmanTypeRequest::new()->fails()->create(['url' => 'https://mailman.example.com', 'user' => 'newuser', 'password' => 'password', 'owner' => 'owner@example.com']); $mailgateway = Mailgateway::factory()->type(MailmanType::class, $typeParams)->create(); Livewire::test(Form::class, ['id' => $mailgateway->id]) ->set('params.user', 'newuser') ->call('onSave') ->assertHasErrors('connection'); });