Skip to content

Commit

Permalink
Added product and variant gtin field tests
Browse files Browse the repository at this point in the history
  • Loading branch information
molnarerwin committed Feb 3, 2025
1 parent 995ea53 commit 7d48d99
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/MasterProduct/Tests/Unit/MasterProductVariantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,42 @@ public function a_variant_does_not_have_meta_description()

$this->assertNull($variant->meta_description);
}

/** @test */
public function the_variant_gtin_field_can_be_set(): void
{
$master = MasterProduct::create([
'name' => 'Kosmodisk',
]);

$variant = MasterProductVariant::create([
'master_product_id' => $master->id,
'sku' => 'kosmodisk',
'gtin' => '777888999'
]);

$this->assertEquals('777888999', $variant->gtin);
}

/** @test */
public function the_variant_gtin_field_is_nullable(): void
{
$master = MasterProduct::create([
'name' => 'Kosmodisk',
]);

$variant = MasterProductVariant::create([
'master_product_id' => $master->id,
'sku' => 'kosmodisk',
'gtin' => '777888999'
]);

$variant->update([
'gtin' => null,
]);

$variant->fresh();

$this->assertNull($variant->gtin);
}
}
22 changes: 21 additions & 1 deletion src/Product/Tests/BaseProductAttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public function all_fields_can_be_properly_set()
'description' => 'Maxi Baxi 2000 makes your dreams come true. See: https://youtu.be/5RKM_VLEbOc',
'state' => 'active',
'meta_keywords' => 'maxi, baxi, dreams',
'meta_description' => 'The THING you always have dreamt of'
'meta_description' => 'The THING you always have dreamt of',
'gtin' => '8675309',
]);

$this->assertGreaterThanOrEqual(1, $product->id);
Expand All @@ -80,6 +81,7 @@ public function all_fields_can_be_properly_set()
$this->assertEquals('active', $product->state->value());
$this->assertEquals('maxi, baxi, dreams', $product->meta_keywords);
$this->assertEquals('The THING you always have dreamt of', $product->meta_description);
$this->assertEquals('8675309', $product->gtin);
}

/**
Expand Down Expand Up @@ -160,4 +162,22 @@ public function find_by_sku_returns_null_if_no_product_was_found_by_the_requeste
{
$this->assertNull(Product::findBySku('Oh man such SKU could not exist in the Wild. Nor in a lab'));
}

/** @test */
public function the_product_gtin_field_is_nullable(): void
{
$product = Product::create([
'name' => 'Kosmodisk',
'sku' => 'kosmodisk',
'gtin' => '9876543210',
]);

$product->update([
'gtin' => null,
]);

$product->fresh();

$this->assertNull($product->gtin);
}
}

0 comments on commit 7d48d99

Please sign in to comment.