feat: add bus-only travel mailing lists
This commit is contained in:
1 parent
f5894a6bef
commit
2705401393
15 files changed
+335
-60
No files matched your search
@@ -7,6 +7,7 @@ namespace App\Tests\BpnConnect;
|
||||
use App\BpnConnect\Exception\BpnConnectException;
|
||||
use App\BpnConnect\Model\TravelMailingRecipient;
|
||||
use App\BpnConnect\TravelsClient;
|
||||
use App\Enum\BusLeg;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\NullLogger;
|
||||
use Symfony\Component\HttpClient\MockHttpClient;
|
||||
@@ -35,12 +36,49 @@ class TravelsClientTest extends TestCase
|
||||
self::assertSame('https://bpn-connect.test/api/v1/travels/mailing?travelCode=LPJMP281126', $requests[0][1]);
|
||||
self::assertContains('X-API-KEY: secret', $requests[0][2]['headers']);
|
||||
self::assertSame('LPJMP281126', $response->travelCode);
|
||||
self::assertNull($response->busLeg);
|
||||
self::assertEquals([
|
||||
new TravelMailingRecipient('[email protected]', 'Erika', 'Muster'),
|
||||
new TravelMailingRecipient('[email protected]', 'Max', 'Muster'),
|
||||
], $response->data);
|
||||
}
|
||||
|
||||
public function testGetMailingRecipientsPassesTheBusLegAndAcceptsItsEcho(): void
|
||||
{
|
||||
$requests = [];
|
||||
$http = new MockHttpClient(function (string $method, string $url) use (&$requests): MockResponse {
|
||||
$requests[] = $url;
|
||||
|
||||
return $this->jsonResponse([
|
||||
'meta' => ['travel_code' => 'LPJMP281126', 'bus_leg' => 'outbound', 'row_count' => 1, 'execution_time_ms' => 12],
|
||||
'data' => [
|
||||
['email' => '[email protected]', 'first_name' => 'Erika', 'last_name' => 'Muster'],
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
$response = $this->client($http)->getMailingRecipients('LPJMP281126', BusLeg::Outbound);
|
||||
|
||||
self::assertSame(['https://bpn-connect.test/api/v1/travels/mailing?travelCode=LPJMP281126&busLeg=outbound'], $requests);
|
||||
self::assertSame(BusLeg::Outbound, $response->busLeg);
|
||||
self::assertCount(1, $response->data);
|
||||
}
|
||||
|
||||
public function testABusLegTheServerDidNotApplyIsRejected(): void
|
||||
{
|
||||
// What a bpn-connect without the filter answers: everyone, and no bus_leg in meta.
|
||||
$http = new MockHttpClient($this->jsonResponse([
|
||||
'meta' => ['travel_code' => 'LPJMP281126', 'row_count' => 1, 'execution_time_ms' => 12],
|
||||
'data' => [
|
||||
['email' => '[email protected]', 'first_name' => 'Erika', 'last_name' => 'Muster'],
|
||||
],
|
||||
]));
|
||||
|
||||
$this->expectException(BpnConnectException::class);
|
||||
|
||||
$this->client($http)->getMailingRecipients('LPJMP281126', BusLeg::Outbound);
|
||||
}
|
||||
|
||||
public function testAnUnknownTravelCodeYieldsAnEmptyList(): void
|
||||
{
|
||||
$http = new MockHttpClient($this->jsonResponse([
|
||||
|
||||
Reference in new issue
Block a user