Fixed mailman test
This commit is contained in:
parent
904ec829c1
commit
8f3cc95300
|
@ -6,6 +6,7 @@ use Spatie\LaravelData\Attributes\MapName;
|
|||
use Spatie\LaravelData\Attributes\MapOutputName;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
|
||||
use Tests\RequestFactories\MailinglistFactory;
|
||||
|
||||
#[MapName(SnakeCaseMapper::class)]
|
||||
class MailingList extends Data
|
||||
|
@ -24,4 +25,9 @@ class MailingList extends Data
|
|||
public int $volume,
|
||||
) {
|
||||
}
|
||||
|
||||
public static function factory(): MailinglistFactory
|
||||
{
|
||||
return MailinglistFactory::new();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ class Member extends Data
|
|||
{
|
||||
public function __construct(
|
||||
public string $email,
|
||||
public string $listId,
|
||||
public string $memberId,
|
||||
) {
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\RequestFactories;
|
||||
|
||||
use App\Mailman\Data\MailingList;
|
||||
use Worksome\RequestFactories\RequestFactory;
|
||||
|
||||
class MailinglistFactory extends RequestFactory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'description' => $this->faker->words(5, true),
|
||||
'displayName' => $this->faker->words(5, true),
|
||||
'fqdnListname' => $this->faker->safeEmail(),
|
||||
'listId' => $this->faker->domainName(),
|
||||
'listName' => $this->faker->words(5, true),
|
||||
'mailHost' => $this->faker->domainName(),
|
||||
'memberCount' => $this->faker->numberBetween(10, 100),
|
||||
'selfLink' => $this->faker->url(),
|
||||
'volume' => 1,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $attributes
|
||||
*/
|
||||
public function toData(array $attributes = []): MailingList
|
||||
{
|
||||
return MailingList::from($this->create($attributes));
|
||||
}
|
||||
|
||||
public function id(string $id): self
|
||||
{
|
||||
return $this->state([
|
||||
'list_id' => $id,
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -45,16 +45,16 @@ class ServiceTest extends TestCase
|
|||
Http::fake([
|
||||
'http://mailman.test/api/lists/listid/roster/member?page=1&count=10' => Http::response(json_encode([
|
||||
'entries' => [
|
||||
['email' => 'test@example.com'],
|
||||
['email' => 'test2@example.com'],
|
||||
['email' => 'test@example.com', 'self_link' => 'https://example.com/994'],
|
||||
],
|
||||
'total_size' => 2,
|
||||
]), 200),
|
||||
]);
|
||||
|
||||
$result = app(MailmanService::class)->setCredentials('http://mailman.test/api/', 'user', 'secret')->members('listid');
|
||||
$result = app(MailmanService::class)->setCredentials('http://mailman.test/api/', 'user', 'secret')->members(MailingList::factory()->id('listid')->toData())->first();
|
||||
|
||||
$this->assertEquals(['test@example.com', 'test2@example.com'], $result->toArray());
|
||||
$this->assertEquals(994, $result->memberId);
|
||||
$this->assertEquals('test@example.com', $result->email);
|
||||
Http::assertSentCount(1);
|
||||
Http::assertSent(fn ($request) => 'GET' === $request->method() && 'http://mailman.test/api/lists/listid/roster/member?page=1&count=10' === $request->url() && $request->header('Authorization') === ['Basic '.base64_encode('user:secret')]);
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ class ServiceTest extends TestCase
|
|||
'http://mailman.test/api/lists/listid/roster/member?page=1&count=10' => Http::response('', 401),
|
||||
]);
|
||||
|
||||
app(MailmanService::class)->setCredentials('http://mailman.test/api/', 'user', 'secret')->members('listid')->first();
|
||||
app(MailmanService::class)->setCredentials('http://mailman.test/api/', 'user', 'secret')->members(MailingList::factory()->id('listid')->toData())->first();
|
||||
}
|
||||
|
||||
public function testItCanGetLists(): void
|
||||
|
@ -94,7 +94,7 @@ class ServiceTest extends TestCase
|
|||
foreach (range(3, 40) as $i) {
|
||||
yield [
|
||||
collect(range(1, $i))
|
||||
->map(fn ($num) => ['email' => 'test'.$num.'@example.com'])
|
||||
->map(fn ($num) => ['email' => 'test'.$num.'@example.com', 'self_link' => 'https://example.com/994'])
|
||||
->toArray(),
|
||||
];
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ class ServiceTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
$result = app(MailmanService::class)->setCredentials('http://mailman.test/api/', 'user', 'secret')->members('listid');
|
||||
$result = app(MailmanService::class)->setCredentials('http://mailman.test/api/', 'user', 'secret')->members(MailingList::factory()->id('listid')->toData());
|
||||
|
||||
$this->assertCount($totals->count(), $result->toArray());
|
||||
Http::assertSentCount($totals->chunk(10)->count());
|
||||
|
|
Loading…
Reference in New Issue