Add store button

This commit is contained in:
philipp lang 2023-06-07 21:40:58 +02:00 committed by Philipp Lang
parent 68ecce179e
commit a880333f35
5 changed files with 68 additions and 2 deletions

View File

@ -27,6 +27,7 @@ class MailgatewayResource extends JsonResource
'domain' => $this->domain,
'type_human' => $this->type::name(),
'works' => $this->type->works(),
'type' => $this->type->toResource(),
];
}
@ -34,7 +35,7 @@ class MailgatewayResource extends JsonResource
{
return [
'links' => [
'store' => route('api.mailgateway.store'),
'store' => route('mailgateway.store'),
],
'types' => app('mail-gateways')->map(fn ($gateway) => [
'id' => $gateway,

View File

@ -23,4 +23,12 @@ abstract class Type
$field['name'] => $field[$validator],
])->toArray();
}
public function toResource(): array
{
return [
'cls' => get_class($this),
'params' => get_object_vars($this),
];
}
}

View File

@ -54,7 +54,9 @@
:label="gateway.works ? 'Verbindung erfolgreich' : 'Verbindung fehlgeschlagen'"
></ui-boolean-display>
</td>
<td></td>
<td>
<a href="#" v-tooltip="`Bearbeiten`" @click.prevent="model = {...gateway}" class="inline-flex btn btn-warning btn-sm"><svg-sprite src="pencil"></svg-sprite></a>
</td>
</tr>
</table>

View File

@ -0,0 +1,38 @@
<?php
namespace Tests\Feature\Mailgateway;
use App\Mailgateway\Types\LocalType;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class LocalGatewayCreateTest extends TestCase
{
use DatabaseTransactions;
public function testItCanCreateALocalGateway(): void
{
$this->login()->loginNami();
$this->withoutExceptionHandling();
$response = $this->post('/api/mailgateway', [
'type' => [
'cls' => LocalType::class,
'params' => [],
],
'name' => 'lala',
'domain' => 'example.com',
]);
$response->assertOk();
$this->assertDatabaseHas('mailgateways', [
'name' => 'lala',
'domain' => 'example.com',
'type' => json_encode([
'cls' => LocalType::class,
'params' => [],
]),
]);
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace Tests\RequestFactories;
use Worksome\RequestFactories\RequestFactory;
class MailmanTypeRequest extends RequestFactory
{
public function definition(): array
{
return [
'url' => 'https://'.$this->faker->domainName(),
'user' => $this->faker->firstName(),
'password' => $this->faker->password(),
];
}
}