Skip to content

Commit

Permalink
v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sethsandaru committed May 12, 2024
1 parent 52ec506 commit 36a8896
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Http/Controllers/InboxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ShipSaasInboxProcess\Http\Controllers;

use Illuminate\Container\Container;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Database\QueryException;
use Illuminate\Http\JsonResponse;
Expand All @@ -26,6 +27,8 @@ public function handle(
* @var AbstractInboxRequest $inboxRequest
*/
$inboxRequest = InboxProcessSetup::getRequest($topic)::createFrom($request);
$inboxRequest->setContainer(Container::getInstance());
$inboxRequest->setRedirector(Container::getInstance()->get('redirect'));

// to ensure we have legit data before inserting
// - authorize
Expand Down
2 changes: 1 addition & 1 deletion src/Routes/inbox_routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use ShipSaasInboxProcess\Http\Controllers\InboxController;

if (config('inbox.uses_default_inbox_route')) {
$routePath = config('inbox.route_path');
$routePath = config('inbox.route_path', 'inbox');

Route::post($routePath . '/{topic}', [InboxController::class, 'handle'])
->name('inbox.topic');
Expand Down
77 changes: 77 additions & 0 deletions tests/Integration/Http/InboxControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,81 @@ public function getInboxExternalId(): string
$body
)->assertStatus(400);
}

public function testInboxWillNotRecordIfAuthorizeReturnsFalse()
{
$body = json_decode(
file_get_contents(__DIR__ . '/../__fixtures__/stripe_invoice_payment_succeed.json'),
true
);

InboxProcessSetup::addRequest('stripe', new class() extends AbstractInboxRequest {
public function authorize(): bool
{
return false;
}

public function getInboxExternalId(): string
{
return $this->input('id');
}
});

InboxProcessSetup::addResponse('stripe', function () {
return new JsonResponse('OK MAN');
});

$this->json(
'POST',
route('inbox.topic', ['topic' => 'stripe']),
$body
)->assertForbidden();

$this->assertDatabaseMissing('inbox_messages', [
'topic' => 'stripe',
'external_id' => 'evt_1NWX0RBGIr5C5v4TpncL2sCf',
]);
}

public function testInboxWillNotRecordIfValidatesFail()
{
$body = json_decode(
file_get_contents(__DIR__ . '/../__fixtures__/stripe_invoice_payment_succeed.json'),
true
);

InboxProcessSetup::addRequest('stripe', new class() extends AbstractInboxRequest {
public function authorize(): bool
{
return true;
}

public function rules(): array
{
return [
'this-is-a-fake-field-to-obtain-error' => 'required',
];
}

public function getInboxExternalId(): string
{
return $this->input('id');
}
});

InboxProcessSetup::addResponse('stripe', function () {
return new JsonResponse('OK MAN');
});

$this->json(
'POST',
route('inbox.topic', ['topic' => 'stripe']),
$body
)->assertUnprocessable();

$this->assertDatabaseMissing('inbox_messages', [
'topic' => 'stripe',
'external_id' => 'evt_1NWX0RBGIr5C5v4TpncL2sCf',
]);
}
}

0 comments on commit 36a8896

Please sign in to comment.