Skip to content

Commit

Permalink
Fix creating product options values in hub (#1402)
Browse files Browse the repository at this point in the history
  • Loading branch information
lguichard authored Dec 22, 2023
1 parent 380012a commit 7f41cf6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Lunar\Hub\Tests\Unit\Http\Livewire\Components\Settings\Product;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Lunar\Hub\Http\Livewire\Components\Settings\Product\Options\OptionEdit;
use Lunar\Hub\Models\Staff;
use Lunar\Hub\Tests\TestCase;
use Lunar\Models\Language;
use Lunar\Models\ProductOption;
use Lunar\Models\ProductOptionValue;

class ProductOptionValueCreateTest extends TestCase
{
use RefreshDatabase;

public function setUp(): void
{
parent::setUp();

Language::factory()->create([
'default' => true,
'code' => 'en',
]);
}

/**
* @test
* */
public function can_populate_product_option_data()
{
ProductOption::factory(1)->create()->each(function ($option) {
$staff = Staff::factory()->create([
'admin' => true,
]);

LiveWire::actingAs($staff, 'staff')
->test(OptionEdit::class, ['productOption' => $option])
->set('newProductOptionValue.name.' . Language::getDefault()->code, 'Size')
->call('createOptionValue');

$this->assertDatabaseHas((new ProductOptionValue())->getTable(), [
'product_option_id' => $option->id,
'name' => json_encode([Language::getDefault()->code => 'Size'])
]);
});
}
}
2 changes: 1 addition & 1 deletion packages/core/src/Models/ProductOptionValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected static function newFactory(): ProductOptionValueFactory
*/
protected $guarded = [];

public function getNameAttribute(string $value): mixed
public function getNameAttribute(string $value = null): mixed
{
return json_decode($value);
}
Expand Down

0 comments on commit 7f41cf6

Please sign in to comment.