Add List Action
This commit is contained in:
parent
c593096bf9
commit
4786bd3a15
|
@ -13,7 +13,7 @@ class SettingIndexAction
|
|||
use AsAction;
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
* @return array<string, string|bool|null>
|
||||
*/
|
||||
public function handle(MailmanSettings $settings): array
|
||||
{
|
||||
|
|
|
@ -42,6 +42,9 @@ class SettingSaveAction
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function getValidationMessages(): array
|
||||
{
|
||||
return [
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mailman\Data;
|
||||
|
||||
use Spatie\LaravelData\Attributes\MapName;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
|
||||
|
||||
#[MapName(SnakeCaseMapper::class)]
|
||||
class MailingList extends Data
|
||||
{
|
||||
public function __construct(
|
||||
public string $description,
|
||||
public string $displayName,
|
||||
public string $fqdnListname,
|
||||
public string $listId,
|
||||
public string $listName,
|
||||
public string $mailHost,
|
||||
public int $memberCount,
|
||||
public string $selfLink,
|
||||
public int $volume,
|
||||
) {
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Mailman\Support;
|
||||
|
||||
use App\Mailman\Data\MailingList;
|
||||
use App\Mailman\Exceptions\MailmanServiceException;
|
||||
use Illuminate\Http\Client\ConnectionException;
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
|
@ -60,4 +61,22 @@ class MailmanService
|
|||
{
|
||||
return Http::withBasicAuth($this->username, $this->password)->withOptions(['base_uri' => $this->baseUrl]);
|
||||
}
|
||||
|
||||
public function getLists(): LazyCollection
|
||||
{
|
||||
return app(Paginator::class)->result(
|
||||
fn ($page) => $this->http()->get("/lists?page={$page}&count=10"),
|
||||
function ($response) {
|
||||
throw_unless($response->ok(), MailmanServiceException::class, 'Fetching lists failed.');
|
||||
/** @var array<int, array{email: string}>|null */
|
||||
$entries = data_get($response->json(), 'entries');
|
||||
throw_if(is_null($entries), MailmanServiceException::class, 'Failed getting lists from response');
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
yield MailingList::from($entry);
|
||||
}
|
||||
},
|
||||
fn ($response) => data_get($response->json(), 'total_size')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,10 +26,11 @@
|
|||
"monicahq/laravel-sabre": "^1.6",
|
||||
"nunomaduro/collision": "^6.1",
|
||||
"phake/phake": "^4.2",
|
||||
"spatie/laravel-data": "^1.4",
|
||||
"spatie/laravel-data": "^2.0",
|
||||
"spatie/laravel-ignition": "^1.0",
|
||||
"spatie/laravel-medialibrary": "^10.0",
|
||||
"spatie/laravel-settings": "^2.2",
|
||||
"worksome/request-factories": "^2.5",
|
||||
"zoomyboy/laravel-nami": "dev-master"
|
||||
},
|
||||
"require-dev": {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
27
phpstan.neon
27
phpstan.neon
|
@ -492,35 +492,16 @@ parameters:
|
|||
count: 1
|
||||
path: tests/Feature/Initialize/RequestTest.php
|
||||
|
||||
-
|
||||
message: "#^Call to an undefined method Phake\\\\Proxies\\\\VerifierProxy\\:\\:run\\(\\)\\.$#"
|
||||
count: 1
|
||||
path: tests/Feature/Initialize/RequestTest.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$mock of static method Phake\\:\\:verify\\(\\) expects Phake\\\\IMock, App\\\\Initialize\\\\Initializer given\\.$#"
|
||||
count: 1
|
||||
path: tests/Feature/Initialize/RequestTest.php
|
||||
|
||||
-
|
||||
message: "#^Call to an undefined method Phake\\\\Proxies\\\\StubberProxy\\:\\:check\\(\\)\\.$#"
|
||||
count: 2
|
||||
path: tests/Feature/Mailman/SettingTest.php
|
||||
message: "#^Call to an undefined method Phake\\\\Proxies\\\\StubberProxy.*#"
|
||||
|
||||
-
|
||||
message: "#^Call to an undefined method Phake\\\\Proxies\\\\StubberProxy\\:\\:setCredentials\\(\\)\\.$#"
|
||||
count: 2
|
||||
path: tests/Feature/Mailman/SettingTest.php
|
||||
|
||||
-
|
||||
message: "#^Call to an undefined method Phake\\\\Proxies\\\\VerifierProxy\\:\\:check\\(\\)\\.$#"
|
||||
count: 2
|
||||
path: tests/Feature/Mailman/SettingTest.php
|
||||
|
||||
-
|
||||
message: "#^Call to an undefined method Phake\\\\Proxies\\\\VerifierProxy\\:\\:setCredentials\\(\\)\\.$#"
|
||||
count: 2
|
||||
path: tests/Feature/Mailman/SettingTest.php
|
||||
message: "#^Call to an undefined method Phake\\\\Proxies\\\\VerifierProxy.*#"
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$mock of static method Phake\\:\\:verify\\(\\) expects Phake\\\\IMock, App\\\\Mailman\\\\Support\\\\MailmanService given\\.$#"
|
||||
|
@ -528,9 +509,7 @@ parameters:
|
|||
path: tests/Feature/Mailman/SettingTest.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\.\\.\\.\\$mocks of static method Phake\\:\\:verifyNoInteraction\\(\\) expects Phake\\\\IMock, App\\\\Mailman\\\\Support\\\\MailmanService given\\.$#"
|
||||
count: 1
|
||||
path: tests/Feature/Mailman/SettingTest.php
|
||||
message: "#verifyNoInteraction\\(\\) expects Phake\\\\IMock#"
|
||||
|
||||
-
|
||||
message: "#^Method Tests\\\\Feature\\\\Member\\\\StoreTest\\:\\:attributes\\(\\) has parameter \\$overwrites with no value type specified in iterable type array\\.$#"
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\RequestFactories;
|
||||
|
||||
use Worksome\RequestFactories\RequestFactory;
|
||||
|
||||
class MailmanListRequestFactory extends RequestFactory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'description' => $this->faker->words(5, true),
|
||||
'display_name' => $this->faker->words(5, true),
|
||||
'fqdn_listname' => $this->faker->safeEmail,
|
||||
'http_etag' => $this->faker->uuid(),
|
||||
'list_id' => str_replace('@', '.', $this->faker->safeEmail()),
|
||||
'list_name' => $this->faker->words(1, true),
|
||||
'mail_host' => $this->faker->safeEmailDomain(),
|
||||
'member_count' => $this->faker->numberBetween(0, 100),
|
||||
'self_link' => $this->faker->url(),
|
||||
'volume' => 1,
|
||||
];
|
||||
}
|
||||
}
|
|
@ -2,10 +2,12 @@
|
|||
|
||||
namespace Tests\Unit\Mailman;
|
||||
|
||||
use App\Mailman\Data\MailingList;
|
||||
use App\Mailman\Exceptions\MailmanServiceException;
|
||||
use App\Mailman\Support\MailmanService;
|
||||
use Generator;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\RequestFactories\MailmanListRequestFactory;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ServiceTest extends TestCase
|
||||
|
@ -67,6 +69,26 @@ class ServiceTest extends TestCase
|
|||
app(MailmanService::class)->setCredentials('http://mailman.test/api/', 'user', 'secret')->members('listid')->first();
|
||||
}
|
||||
|
||||
public function testItCanGetLists(): void
|
||||
{
|
||||
Http::fake([
|
||||
'http://mailman.test/api/lists?page=1&count=10' => Http::sequence()
|
||||
->push(json_encode([
|
||||
'entries' => [
|
||||
MailmanListRequestFactory::new()->create(['display_name' => 'Eltern', 'fqdn_listname' => 'eltern@example.com']),
|
||||
MailmanListRequestFactory::new()->create(['display_name' => 'Eltern2', 'fqdn_listname' => 'eltern2@example.com']),
|
||||
],
|
||||
'start' => 0,
|
||||
'total_size' => 2,
|
||||
]), 200),
|
||||
]);
|
||||
|
||||
$lists = app(MailmanService::class)->setCredentials('http://mailman.test/api/', 'user', 'secret')->getLists()->all();
|
||||
$this->assertCount(2, $lists);
|
||||
$this->assertInstanceOf(MailingList::class, $lists[0]);
|
||||
$this->assertEquals('Eltern', $lists[0]->displayName);
|
||||
}
|
||||
|
||||
public function listDataProvider(): Generator
|
||||
{
|
||||
foreach (range(3, 40) as $i) {
|
||||
|
|
Loading…
Reference in New Issue