HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/shop.komma.nl/tests/Unit/VatRateTest.php
<?php
//TODO Update when shop v1 is ready
//
//namespace App\Tests\Unit;
//
//use App\Cart\ShoppingCartServiceInterface;
//use App\Checkout\CheckoutServiceInterface;
//use App\Orders\Models\Order;
//use App\Products\Product\Product;
//use Tests\TestCase;
//use App\Vat\VatService;
//use Illuminate\Foundation\Testing\DatabaseTransactions;
//
//class VatRateTest extends TestCase
//{
//    use DatabaseTransactions; //Automatically rolls back database actions after tests
//
//    /**
//     * @var VatService $vatService
//     */
//    private $vatService;
//
//    /**
//     * @var ShoppingCartServiceInterface
//     */
//    private $shoppingCartService;
//
//    /**
//     * @var CheckoutServiceInterface
//     */
//    private $checkoutService;
//
//    /**
//     * Runs before each test
//     */
//    public function setUp(): void
//    {
//        parent::setUp();
//        $this->vatService = new VatService();
//        $this->shoppingCartService = app(ShoppingCartServiceInterface::class);
//        $this->checkoutService = app(CheckoutServiceInterface::class);
//    }
//
//    /**
//     * @group VatRate
//     * @test
//     */
//    public function testOrderVatCalculation()
//    {
//        $order = $this->createSampleOrder();
//        $expectedVatTotal = round($order->total_ex * 0.21, 0, config('financial.cent_rounding.vat_total', PHP_ROUND_HALF_UP)); //Default vat percentage. Check  SampleVatRates seed. //TODO USE ROUNGING SERVICE HERE
//        $expectedTotalIncVat = round($order->total_ex * 1.21, 0, config('financial.cent_rounding.vat_total', PHP_ROUND_HALF_UP)); //Default vat percentage. Check  SampleVatRates seed.
//
//        $this->vatService->calculateOrderVatTotal($order);
//        $this->assertEquals($expectedVatTotal, $order->vat_amount);
//        $this->assertEquals($expectedTotalIncVat, $order->total);
//        $this->assertEquals(21, $order->vat_percentage);
//    }
//
//    /**
//     * Test calculating a certain price including vat rate.
//     *
//     * @group VatRate
//     * @test
//     */
//    public function testCalculatingIncVatRatePrice()
//    {
//        $this->assertEquals(1490, $this->vatService->calculateIncVatRatePrice(1231));
//    }
//
//    /**
//     * Test calculating a certain price including vat rate.
//     *
//     * @group VatRate
//     * @test
//     */
//    public function testCalculatingExVatRatePrice()
//    {
//        $this->assertEquals(1231, $this->vatService->calculateExVatRatePrice(1490));
//    }
//
//    /**
//     * Test calculating a certain price including vat rate.
//     *
//     * @group VatRate
//     * @test
//     */
//    public function testCalculatingVatRateAmountFromExAmount()
//    {
//        $priceEx = 1231;
//        $vatRateAmount = $this->vatService->calculateVatRateAmountFromExAmount($priceEx);
//        $this->assertEquals(259, $vatRateAmount);
//        //Verify the result by doing the reverse
//        $this->assertEquals($priceEx + $vatRateAmount, $this->vatService->calculateIncVatRatePrice($priceEx));
//    }
//
//    /**
//     * Test calculating a certain price including vat rate.
//     *
//     * @group VatRate
//     * @test
//     */
//    public function testCalculatingVatRateAmountFromIncAmount()
//    {
//        $priceInc = 1490;
//        $vatRateAmount = $this->vatService->calculateVatRateAmountFromIncAmount($priceInc);
//        $this->assertEquals(259, $vatRateAmount);
//        //Verify the result by doing the reverse
//        $this->assertEquals($priceInc - $vatRateAmount, $this->vatService->calculateExVatRatePrice($priceInc));
//    }
//
//    /**
//     * Test calculation of vat for a product or productable.
//     * The productable will be given vat details. Those details are not to be saved into the database.
//     * Just for carrying the information around.
//     *
//     * @group VatRate
//     * @test
//     */
//    public function TestCalculatingVatForProductable()
//    {
//        $sampleProduct = new Product();
//        $sampleProduct->price = 822;
//
//        $expectedVatAmount = 143;
//        $expectedIncAmount = $sampleProduct->price;
//
//        $sampleProduct = $this->vatService->calculateVatForProductable($sampleProduct);
//        $this->assertEquals($expectedVatAmount, $sampleProduct->vat_amount);
//        $this->assertEquals($expectedIncAmount, $sampleProduct->price_inc);
//    }
//
//
//    //HELPER FUNCTIONS
//    /**
//     * @return Order
//     */
//    public function createSampleOrder()
//    {
//        /** @var Order $order */
//        $order = factory(Order::class)->create();
//        $order->total_ex = mt_rand(100, 6599);
//        return $order;
//    }
//}