From 369bdb95f3a403b5ff5023aff6d80945731a03b8 Mon Sep 17 00:00:00 2001 From: Norris Oduro Date: Sun, 15 Nov 2020 06:46:12 +0000 Subject: [PATCH] Add more tests --- tests/CartTest.php | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/tests/CartTest.php b/tests/CartTest.php index 4732d67..4606a65 100644 --- a/tests/CartTest.php +++ b/tests/CartTest.php @@ -1482,8 +1482,46 @@ class CartTest extends TestCase $newInstanceSerialized = serialize($newInstance->content()); - $this->assertDatabaseHas('shoppingcart', ['identifier' => $identifier, 'instance' => 'default', 'content' => $serialized]); + $this->assertDatabaseHas('shoppingcart', ['identifier' => $identifier, 'instance' => Cart::DEFAULT_INSTANCE, 'content' => $serialized]); $this->assertDatabaseHas('shoppingcart', ['identifier' => $identifier, 'instance' => $instanceName, 'content' => $newInstanceSerialized]); } + + /** @test */ + public function it_can_calculate_the_total_price_of_the_items_in_cart() + { + $cart = $this->getCart(); + + $cart->add(new BuyableProduct(1, 'first item', $price = 1000), $qty = 5); + $this->assertEquals(5000, $cart->priceTotalFloat()); + } + + /** @test */ + public function it_can_format_the_total_price_of_the_items_in_cart() + { + $cart = $this->getCart(); + + $cart->add(new BuyableProduct(1, 'first item', 1000), 5); + $this->assertEquals("5,000.00", $cart->priceTotal()); + $this->assertEquals("5,000.0000", $cart->priceTotal(4, ".", ",")); + } + + /** @test */ + public function it_can_erase_saved_cart_from_the_database() + { + $this->artisan('migrate', [ + '--database' => 'testing', + ]); + + Event::fake(); + + $cart = $this->getCart(); + $cart->add(new BuyableProduct(1, 'Item', 10.00), 1); + $cart->add(new BuyableProduct(2, 'Item 2', 10.00), 1); + $cart->store($identifier = 'test'); + $cart->erase($identifier); + Event::assertDispatched('cart.erased'); + $this->assertDatabaseMissing('shoppingcart', ['identifier' => $identifier, 'instance' => Cart::DEFAULT_INSTANCE]); + + } }