From 8c0cd0cd8d4b6ed3cd8284dd53961c113969d8aa Mon Sep 17 00:00:00 2001 From: Keith Brink Date: Wed, 6 Oct 2021 12:18:16 +0300 Subject: [PATCH] Fix fn_sku --- src/Resources/FbaInventoryResource.php | 4 ---- src/helpers.php | 6 ++++-- tests/Unit/HelpersTest.php | 2 ++ tests/Unit/Resources/FbaInventoryResourceTest.php | 1 + 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Resources/FbaInventoryResource.php b/src/Resources/FbaInventoryResource.php index 9610adb8..e9cc4d27 100644 --- a/src/Resources/FbaInventoryResource.php +++ b/src/Resources/FbaInventoryResource.php @@ -3,13 +3,9 @@ namespace Jasara\AmznSPA\Resources; use Carbon\CarbonImmutable; -use Illuminate\Support\Arr; use Jasara\AmznSPA\AmznSPAHttp; -use Jasara\AmznSPA\Constants\AmazonEnums; use Jasara\AmznSPA\Constants\MarketplacesList; use Jasara\AmznSPA\Contracts\ResourceContract; -use Jasara\AmznSPA\DataTransferObjects\Responses\CatalogItems\GetCatalogItemResponse; -use Jasara\AmznSPA\DataTransferObjects\Responses\CatalogItems\ItemSearchResults; use Jasara\AmznSPA\DataTransferObjects\Responses\FbaInventory\GetInventorySummariesResponse; use Jasara\AmznSPA\Traits\ValidatesParameters; diff --git a/src/helpers.php b/src/helpers.php index 3ee2c6be..b8be6c84 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -3,7 +3,7 @@ use Illuminate\Support\Collection; use Illuminate\Support\Str; -if (! function_exists('array_keys_to_snake')) { // @codeCoverageIgnore +if (!function_exists('array_keys_to_snake')) { // @codeCoverageIgnore function array_keys_to_snake(array $array): array { $snakecased_array = []; @@ -15,7 +15,9 @@ function array_keys_to_snake(array $array): array $match = $match == strtoupper($match) ? strtolower($match) : lcfirst($match); } - $key = Str::snake(implode('_', $result)); + $key = (string) Str::of(implode('_', $result)) + ->snake() + ->replace('fn_sku', 'fnsku'); } if (is_array($value)) { $value = array_keys_to_snake($value); diff --git a/tests/Unit/HelpersTest.php b/tests/Unit/HelpersTest.php index 5cdb2408..7d290ba9 100644 --- a/tests/Unit/HelpersTest.php +++ b/tests/Unit/HelpersTest.php @@ -28,6 +28,7 @@ public function testArrayKeysToSnake() 'abc12345abc' => 0, 'aBc12345Abc' => 0, 'SKUInboundGuidanceList' => 0, + 'fnSku' => 0, ]; $array = array_keys_to_snake($array); @@ -41,6 +42,7 @@ public function testArrayKeysToSnake() $this->assertArrayHasKey('abc_12345_abc', $array); $this->assertArrayHasKey('a_bc_12345_abc', $array); $this->assertArrayHasKey('sku_inbound_guidance_list', $array); + $this->assertArrayHasKey('fnsku', $array); $this->assertArrayHasKey('test_deep_camel', $array['test_camel']); $this->assertArrayHasKey('test_deep_array_with_objects', $array['test_camel']); $this->assertArrayHasKey('test_collection', $array['test_camel']['test_deep_array_with_objects'][0]); diff --git a/tests/Unit/Resources/FbaInventoryResourceTest.php b/tests/Unit/Resources/FbaInventoryResourceTest.php index a6c133e4..6070cc06 100644 --- a/tests/Unit/Resources/FbaInventoryResourceTest.php +++ b/tests/Unit/Resources/FbaInventoryResourceTest.php @@ -33,6 +33,7 @@ public function testGetInventorySummaries() $this->assertInstanceOf(GetInventorySummariesResponse::class, $response); $this->assertEquals('seed', $response->pagination->next_token); $this->assertEquals('B0020MLK00', $response->payload->inventory_summaries->first()->asin); + $this->assertEquals('B0020MLK00', $response->payload->inventory_summaries->first()->fnsku); $http->assertSent(function (Request $request) use ($sku) { $this->assertEquals('GET', $request->method());