-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from dystcz/feature/update-product-options
Update product options
- Loading branch information
Showing
12 changed files
with
171 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...e/Domain/ProductVariants/JsonApi/V1/ProductVariantProductOptionValuesRelationshipTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
use Dystcz\LunarApi\Domain\Products\Models\Product; | ||
use Dystcz\LunarApi\Domain\ProductVariants\Models\ProductVariant; | ||
use Dystcz\LunarApi\Tests\TestCase; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Lunar\Models\ProductOption; | ||
use Lunar\Models\ProductOptionValue; | ||
|
||
uses(TestCase::class, RefreshDatabase::class); | ||
|
||
it('can list product options values through relationship', function () { | ||
/** @var TestCase $this */ | ||
$product = Product::factory() | ||
->hasAttached( | ||
ProductOption::factory() | ||
->count(2) | ||
->has(ProductOptionValue::factory()->count(3), 'values'), | ||
['position' => 1], | ||
) | ||
->create(); | ||
|
||
$values = $product->productOptions->map(fn (ProductOption $option) => $option->values->first()); | ||
|
||
$variant = ProductVariant::factory() | ||
->for($product, 'product') | ||
->hasAttached($values, [], 'values') | ||
->create(); | ||
|
||
$response = $this | ||
->jsonApi() | ||
->expects('product_option_values') | ||
->get(serverUrl("/product_variants/{$variant->getRouteKey()}/product_option_values")); | ||
|
||
$response | ||
->assertSuccessful() | ||
->assertFetchedMany($variant->values) | ||
->assertDoesntHaveIncluded(); | ||
})->group('product-variants'); | ||
|
||
it('can count product option values', function () { | ||
/** @var TestCase $this */ | ||
$product = Product::factory() | ||
->hasAttached( | ||
ProductOption::factory() | ||
->count(2) | ||
->has(ProductOptionValue::factory()->count(3), 'values'), | ||
['position' => 1], | ||
) | ||
->create(); | ||
|
||
$values = $product->productOptions->map(fn (ProductOption $option) => $option->values->first()); | ||
|
||
$variant = ProductVariant::factory() | ||
->for($product, 'product') | ||
->hasAttached($values, [], 'values') | ||
->create(); | ||
|
||
$response = $this | ||
->jsonApi() | ||
->expects('product_variants') | ||
->get(serverUrl("/product_variants/{$variant->getRouteKey()}?with_count=product_option_values")); | ||
|
||
$response | ||
->assertSuccessful() | ||
->assertFetchedOne($variant); | ||
|
||
expect($response->json('data.relationships.product_option_values.meta.count'))->toBe(2); | ||
})->group('product-variants', 'counts'); |
43 changes: 43 additions & 0 deletions
43
tests/Feature/Domain/Products/JsonApi/V1/ProductProductOptionsRelationshipTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
use Dystcz\LunarApi\Domain\Products\Models\Product; | ||
use Dystcz\LunarApi\Tests\TestCase; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Lunar\Models\ProductOption; | ||
|
||
uses(TestCase::class, RefreshDatabase::class); | ||
|
||
it('can list product options through relationship', function () { | ||
/** @var TestCase $this */ | ||
$product = Product::factory() | ||
->hasAttached(ProductOption::factory()->count(2), ['position' => 1]) | ||
->create(); | ||
|
||
$response = $this | ||
->jsonApi() | ||
->expects('product_options') | ||
->get(serverUrl("/products/{$product->getRouteKey()}/product_options")); | ||
|
||
$response | ||
->assertSuccessful() | ||
->assertFetchedMany($product->productOptions) | ||
->assertDoesntHaveIncluded(); | ||
})->group('products'); | ||
|
||
it('can count product options', function () { | ||
/** @var TestCase $this */ | ||
$product = Product::factory() | ||
->hasAttached(ProductOption::factory()->count(4), ['position' => 1]) | ||
->create(); | ||
|
||
$response = $this | ||
->jsonApi() | ||
->expects('products') | ||
->get(serverUrl("/products/{$product->getRouteKey()}?with_count=product_options")); | ||
|
||
$response | ||
->assertSuccessful() | ||
->assertFetchedOne($product); | ||
|
||
expect($response->json('data.relationships.product_options.meta.count'))->toBe(4); | ||
})->group('products', 'counts'); |