Skip to content

Commit 7e43819

Browse files
committed
Add it_has_a_total_price_for_the_order()
1 parent 17819bc commit 7e43819

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

app/Models/Order.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ public function addProducts($products)
2121
]);
2222
}
2323
}
24+
25+
public function totalPrice()
26+
{
27+
return number_format($this->total / 100, 2);
28+
}
2429
}

tests/Unit/OrderTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ public function it_can_add_products_to_the_order()
2121

2222
$order->addProducts($products);
2323

24-
$this->assertEquals(3, $order->products()->count());
24+
$this->assertEquals(3, $order->products->count());
25+
}
26+
27+
/**
28+
* @test
29+
*/
30+
public function it_has_a_total_price_for_the_order()
31+
{
32+
$order = factory(Order::class)->create([
33+
'total' => 3000,
34+
]);
35+
36+
$this->assertEquals('30.00', $order->totalPrice());
2537
}
2638
}

0 commit comments

Comments
 (0)