Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add URL encodes to Magento calls #10

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading