Skip to content

Commit

Permalink
Merge pull request #3 from MyParcelCOM/feature/qa-adjustments
Browse files Browse the repository at this point in the history
✨  Added redirect_url on setup request and PublishJob
  • Loading branch information
zwaans authored Jan 9, 2024
2 parents ed821da + a4595ba commit 8393692
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Http/SetupRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ public function authorize(): true
public function rules(): array
{
return [
'data.broker_id' => 'required|string|uuid',
'data.settings' => 'array',
'data.broker_id' => 'required|string|uuid',
'data.settings' => 'array',
'data.redirect_url' => 'url',
];
}

public function brokerId(): string
{
return $this->input('data.broker_id');
}

public function redirectUrl(): ?string
{
return $this->input('data.redirect_url');
}
}
31 changes: 31 additions & 0 deletions src/Sns/PublishJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace MyParcelCom\Payments\Providers\Sns;

use DateTimeInterface;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class PublishJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public function __construct(
private readonly string $topicArn,
private readonly string $myparcelcomPaymentId,
private readonly ?DateTimeInterface $paidAt = null,
) {
}

public function handle(Publisher $publisher): void
{
$publisher
->publish($this->topicArn, $this->myparcelcomPaymentId, $this->paidAt)
->wait();
}
}
45 changes: 45 additions & 0 deletions tests/Sns/PublishJobTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace Sns;

use Faker\Factory;
use GuzzleHttp\Promise\Promise;
use Mockery;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Mockery\MockInterface;
use MyParcelCom\Payments\Providers\Sns\Publisher;
use MyParcelCom\Payments\Providers\Sns\PublishJob;
use PHPUnit\Framework\TestCase;

class PublishJobTest extends TestCase
{
use MockeryPHPUnitIntegration;

public function test_it_handles_publish_job(): void
{
$faker = Factory::create();
$topicArn = "arn:aws:sns:eu-west-1:{$faker->randomNumber()}:{$faker->word}";
$myparcelcomPaymentId = $faker->uuid;
$paidAt = $faker->dateTime;

$snsPromise = Mockery::mock(Promise::class, function (MockInterface & Promise $mock) {
$mock->expects('wait');
});

$publisher = Mockery::mock(Publisher::class, function (MockInterface & Publisher $mock) use (
$snsPromise,
$topicArn,
$myparcelcomPaymentId,
$paidAt
) {
$mock->expects('publish')
->with($topicArn, $myparcelcomPaymentId, $paidAt)
->andReturns($snsPromise);
});

$job = new PublishJob($topicArn, $myparcelcomPaymentId, $paidAt);
$job->handle($publisher);
}
}

0 comments on commit 8393692

Please sign in to comment.