Skip to content

Commit

Permalink
UserQueued event (#8)
Browse files Browse the repository at this point in the history
* Added UserQueued event

* Added tests

* Removed incorrect emit
  • Loading branch information
jorbascrumps authored Sep 5, 2024
1 parent 947c22c commit 564f97c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Events/UserQueued.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Jorbascrumps\QueueIt\Events;

use QueueIT\KnownUserV3\SDK\RequestValidationResult;

class UserQueued
{
public RequestValidationResult $requestValidationResult;

/**
* Create a new event instance.
*/
public function __construct(RequestValidationResult $requestValidationResult)
{
$this->requestValidationResult = $requestValidationResult;
}
}
3 changes: 3 additions & 0 deletions src/Http/Middleware/InlineQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Illuminate\Http\Request;
use Jorbascrumps\QueueIt\Events\UserQueued;
use QueueIT\KnownUserV3\SDK\ActionTypes;
use QueueIT\KnownUserV3\SDK\KnownUser;
use QueueIT\KnownUserV3\SDK\KnownUserException;
Expand Down Expand Up @@ -73,6 +74,8 @@ public function handle(Request $request, Closure $next, ...$eventConfigParams)
);

if ($result->doRedirect()) {
event(new UserQueued($result));

return redirect($result->redirectUrl)->setCache($cacheHeaders);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Http/Middleware/KnownUserQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Jorbascrumps\QueueIt\Events\UserQueued;
use QueueIT\KnownUserV3\SDK\ActionTypes;
use QueueIT\KnownUserV3\SDK\KnownUser;
use QueueIT\KnownUserV3\SDK\KnownUserException;
Expand Down Expand Up @@ -41,6 +42,8 @@ public function handle(Request $request, Closure $next)
);

if ($result->doRedirect()) {
event(new UserQueued($result));

return redirect($result->redirectUrl)->setCache($cacheHeaders);
}

Expand Down
16 changes: 16 additions & 0 deletions tests/Http/Middleware/InlineQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Jorbascrumps\QueueIt\Test\Http\Middleware;

use Illuminate\Support\Facades\Event;
use Jorbascrumps\QueueIt\Events\UserQueued;
use Jorbascrumps\QueueIt\Http\Middleware\InlineQueue;
use Jorbascrumps\QueueIt\Test\TestCase;
use QueueIT\KnownUserV3\SDK\ActionTypes;
Expand Down Expand Up @@ -52,6 +54,20 @@ public function testIgnoresInvalidAction(): void
$response->assertOk();
}

public function testEmitsOnQueueRedirect(): void
{
Event::fake();

$userInQueueService = $this->mockQueueService();
$userInQueueService->validateQueueRequestResult = new RequestValidationResult(
ActionTypes::QueueAction, null, null, self::QUEUE_URL, null, null
);

$response = $this->get(self::PAGE_URL);

Event::assertDispatched(UserQueued::class);
}

/**
* @dataProvider aliasProvider
*/
Expand Down
18 changes: 18 additions & 0 deletions tests/Http/Middleware/KnownUserQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Jorbascrumps\QueueIt\Test\Http\Middleware;

use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Support\Facades\Event;
use Jorbascrumps\QueueIt\Events\UserQueued;
use Jorbascrumps\QueueIt\Http\Middleware\KnownUserQueue;
use Jorbascrumps\QueueIt\Test\TestCase;
use QueueIT\KnownUserV3\SDK\ActionTypes;
Expand Down Expand Up @@ -75,4 +77,20 @@ public function testIgnoresInvalidAction(): void

$response->assertOk();
}

public function testEmitsOnQueueRedirect(): void
{
Event::fake();

$this->mockConfig();

$userInQueueService = $this->mockQueueService();
$userInQueueService->validateQueueRequestResult = new RequestValidationResult(
ActionTypes::QueueAction, null, null, self::QUEUE_URL, null, null
);

$response = $this->get(self::PAGE_URL);

Event::assertDispatched(UserQueued::class);
}
}

0 comments on commit 564f97c

Please sign in to comment.