Skip to content

Commit

Permalink
Add URL encodes to Magento calls (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentBean authored Dec 8, 2023
1 parent f18e97e commit 77e50ed
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Actions/CheckMagentoExistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function exists(string $sku): bool

protected function getMagentoProduct(string $sku): Response
{
return $this->magento->get("products/$sku", ['fields' => 'sku']);
return $this->magento->get('products/' . urlencode($sku), ['fields' => 'sku']);
}

public static function bind(): void
Expand Down
2 changes: 1 addition & 1 deletion src/Actions/RetrieveProductData.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function getMagentoProduct(string $sku, string $store = null): Respons
{
return $this->magento
->store($store)
->get("products/$sku");
->get('products/'.urlencode($sku));
}

public static function bind(): void
Expand Down
8 changes: 7 additions & 1 deletion tests/Actions/CheckMagentoExistenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ protected function setUp(): void
Http::fake([
'*products/123?fields=sku' => Http::response(['data']),
'*products/456?fields=sku' => Http::response([], 404),
]);
'*products/123%2B456?fields=sku' => Http::response(['data']),
])->preventStrayRequests();
}

public function test_existing_product(): void
Expand All @@ -33,6 +34,11 @@ public function test_existing_product(): void
$this->assertTrue($this->action->exists('123'));
}

public function test_urlencode(): void
{
$this->assertTrue($this->action->exists('123+456'));
}

public function test_new_existing_product(): void
{
$this->assertTrue($this->action->exists('123'));
Expand Down
6 changes: 3 additions & 3 deletions tests/Actions/RetrieveProductDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function setUp(): void

Http::fake([
'*/products/123' => Http::response(['123']),
'*/products/456' => Http::response(['456']),
'*/products/123%2B456' => Http::response(['456']),
'*/some_store/V1/products/789' => Http::response(['789']),
'*/products/404' => Http::response([], 404),
]);
Expand All @@ -39,12 +39,12 @@ public function test_it_retrieves_existing_product(): void

public function test_it_retrieves_new_product(): void
{
$data = $this->action->retrieve('456');
$data = $this->action->retrieve('123+456');

$this->assertEquals(['456'], $data);

Http::assertSent(function (Request $request) {
return $request->url() == 'rest/all/V1/products/456';
return $request->url() == 'rest/all/V1/products/123%2B456';
});
}

Expand Down

0 comments on commit 77e50ed

Please sign in to comment.