From 45cbd3f923415591929fde6bd0635d0c55b61de5 Mon Sep 17 00:00:00 2001 From: Angus Allman Date: Wed, 13 May 2026 12:11:27 +0100 Subject: [PATCH 1/2] Allow passing in of X-Barstool-UUID Also wrote a happy-path test for this --- src/Barstool.php | 8 ++++++-- tests/BarstoolTest.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/Barstool.php b/src/Barstool.php index b602e5c..1c59410 100755 --- a/src/Barstool.php +++ b/src/Barstool.php @@ -126,9 +126,13 @@ private static function getFatalData(FatalRequestException $exception): array private static function recordRequest(PendingRequest $data): void { - $uuid = Str::uuid()->toString(); + $uuid = $data->headers()->get('X-Barstool-UUID'); - $data->headers()->add('X-Barstool-UUID', $uuid); + if (is_null($uuid)) { + $uuid = Str::uuid()->toString(); + + $data->headers()->add('X-Barstool-UUID', $uuid); + } self::persist(RecordingType::REQUEST, self::getRequestData($data), $uuid); } diff --git a/tests/BarstoolTest.php b/tests/BarstoolTest.php index ca1c6ee..4dc7481 100644 --- a/tests/BarstoolTest.php +++ b/tests/BarstoolTest.php @@ -283,6 +283,48 @@ expect($barstool->response_headers)->toBe(['token' => 'abc123']); }); +it('stores the correct uuid if one is provided by the request', function () { + MockClient::global([ + RequestWithConnector::class => MockResponse::make( + body: [ + 'data' => [ + ['name' => 'John Wayne'], + ['name' => 'Billy the Kid'], + ], + ], + headers: ['token' => 'abc123'], + status: 200, + ), + ]); + + $uuid = (string) Str::uuid(); + $connector = new RandomConnector; + $request = new RequestWithConnector; + $request->headers()->add('X-Barstool-UUID', $uuid); + $response = $connector->send($request); + + expect($response->status())->toBe(200); + expect($response->json())->toBe([ + 'data' => [ + ['name' => 'John Wayne'], + ['name' => 'Billy the Kid'], + ], + ]); + expect($response->headers()->get('token'))->toBe('abc123'); + + $request = $response->getPendingRequest(); + $requestHeaders = [ + 'testing' => 'headers', + 'X-Barstool-UUID' => $uuid = $request->headers()->get('X-Barstool-UUID'), + ]; + expect($request->headers()->all())->toBe($requestHeaders); + + assertDatabaseCount('barstools', 1); + + $barstool = Barstool::where('uuid', $uuid)->sole(); + expect($barstool->uuid)->toBe($uuid); +}); + it('correctly records body, query, status & method', function () { MockClient::global([ RequestWithConnector::class => MockResponse::make( From 9e11e587df0b947ee3675aab3deeea2571d6a49e Mon Sep 17 00:00:00 2001 From: Angus Allman Date: Wed, 13 May 2026 13:48:20 +0100 Subject: [PATCH 2/2] Update test to check with and without uuid passed --- tests/BarstoolTest.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/BarstoolTest.php b/tests/BarstoolTest.php index 4dc7481..e7b634a 100644 --- a/tests/BarstoolTest.php +++ b/tests/BarstoolTest.php @@ -283,7 +283,7 @@ expect($barstool->response_headers)->toBe(['token' => 'abc123']); }); -it('stores the correct uuid if one is provided by the request', function () { +it('stores the barstool correctly with and without a uuid provided in the request headers', function ($sendUuid) { MockClient::global([ RequestWithConnector::class => MockResponse::make( body: [ @@ -300,7 +300,9 @@ $uuid = (string) Str::uuid(); $connector = new RandomConnector; $request = new RequestWithConnector; - $request->headers()->add('X-Barstool-UUID', $uuid); + if ($sendUuid) { + $request->headers()->add('X-Barstool-UUID', $uuid); + } $response = $connector->send($request); expect($response->status())->toBe(200); @@ -321,9 +323,14 @@ assertDatabaseCount('barstools', 1); - $barstool = Barstool::where('uuid', $uuid)->sole(); - expect($barstool->uuid)->toBe($uuid); -}); + if ($sendUuid) { + $barstool = Barstool::where('uuid', $uuid)->sole(); + expect($barstool->uuid)->toBe($uuid); + } +})->with([ + true, + false, +]); it('correctly records body, query, status & method', function () { MockClient::global([