public function test_products_maintain_an_associated_price() { $product = Factory::create(new Product()); $prices = Price::where('product_id', $product->id)->get(); $price = $prices->first(); $this->assertEquals(1, $prices->count()); $this->assertEquals($product->base_price, $price->price); }
public function test_prices_for_products_of_descendent_categories_added_to_discounts() { $product = Factory::create(new Product()); $parent = Factory::create(new Category(), ['is_inheriting' => true]); $child = Factory::create(new Category(), ['parent_id' => $parent->id]); $child->products()->attach($product); $discount = Factory::create(new Discount()); $discount->categories()->add($parent); $discount->save(); $this->assertEquals(1, Price::where('product_id', $product->id)->where('discount_id', $discount->id)->count()); }
public function test_discount_inheritance_is_updated_when_the_tree_is_updated() { $product = Factory::create(new Product()); $parent = Factory::create(new Category(), ['is_inheriting' => true]); $child = Factory::create(new Category(), ['is_inheriting' => true]); $grandchild = Factory::create(new Category(), ['is_inheriting' => true]); $grandchild->products()->attach($product); $discount = Factory::create(new Discount()); $discount->categories()->attach($parent); $discount->save(); $this->assertEquals(0, Price::where('discount_id', $discount->id)->count()); $tree = [['id' => $parent->id, 'parent_id' => null], ['id' => $child->id, 'parent_id' => $parent->id], ['id' => $grandchild->id, 'parent_id' => $child->id]]; Category::updateInheritanceTree($tree); $this->assertEquals(1, Price::where('discount_id', $discount->id)->count()); }