Skip to content

Commit

Permalink
Test headers are sent
Browse files Browse the repository at this point in the history
  • Loading branch information
keithbrink committed Nov 8, 2024
1 parent 131cfa8 commit 729c7b4
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions tests/Unit/AmznSPAHttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,18 @@ function (Request $request) {

public function testSetProxyHeaders()
{
[$config, $http] = $this->setupConfigWithFakeHttp(['tokens/create-restricted-data-token', 'orders/get-orders']);
$http = $this->fakeHttpStub(['orders/get-orders']);

$proxy_auth_token = Str::random();
$proxy = new Proxy(
url: 'https://www.example.com',
headers: [
'Authorization' => "Bearer {$proxy_auth_token}",
'X-Marketplace-Id' => 'ATVPDKIKX0DER',
],
);

$config = $this->setupMinimalProxyConfig($proxy, null, $http);

$amzn = new AmznSPA($config);
$amzn = $amzn->usingMarketplace('ATVPDKIKX0DER');
Expand All @@ -442,15 +453,11 @@ public function testSetProxyHeaders()
);

$request_validation = [
function (Request $request) {
$this->assertEquals('POST', $request->method());
$this->assertEquals('https://sellingpartnerapi-na.amazon.com/tokens/2021-03-01/restrictedDataToken', $request->url());

return true;
},
function (Request $request) {
function (Request $request) use ($proxy_auth_token) {
$this->assertEquals('GET', $request->method());
$this->assertEquals('https://sellingpartnerapi-na.amazon.com/orders/v0/orders?MarketplaceIds=ATVPDKIKX0DER', urldecode($request->url()));
$this->assertEquals('https://www.example.com/orders/v0/orders?MarketplaceIds=ATVPDKIKX0DER', urldecode($request->url()));
$this->assertEquals("Bearer {$proxy_auth_token}", $request->header('Authorization')[0]);
$this->assertEquals('ATVPDKIKX0DER', $request->header('X-Marketplace-Id')[0]);

return true;
},
Expand Down

0 comments on commit 729c7b4

Please sign in to comment.