Skip to content

Commit 9659317

Browse files
committed
unit test per apply_price
1 parent 9d7732d commit 9659317

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

code/tests/Services/BookingsServiceTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use App\Exceptions\AuthException;
99
use App\Exceptions\IllegalArgumentException;
10+
use App\Product;
1011
use App\Booking;
1112
use App\Movement;
1213

@@ -518,6 +519,38 @@ public function test_insufficient_credit_with_limit()
518519
$this->assertNotNull($booking);
519520
}
520521

522+
/*
523+
Consegna con prezzo forzato
524+
*/
525+
public function test_apply_price()
526+
{
527+
$this->actingAs($this->userWithBasePerms);
528+
[$data, $booked_count, $total] = $this->randomQuantities($this->sample_order->products);
529+
$target_test_product = Product::find(array_rand($data));
530+
$data['action'] = 'booked';
531+
$booking_booking = $this->updateAndFetch($data, $this->sample_order, $this->userWithBasePerms, false);
532+
$initial_value = $booking_booking->getValue('booked', false);
533+
534+
$this->nextRound();
535+
536+
do {
537+
$new_price = rand(1, 10);
538+
} while($new_price == $target_test_product->price);
539+
540+
$this->actingAs($this->userWithShippingPerms);
541+
$data['action'] = 'shipped';
542+
$data['apply_price_' . $target_test_product->id] = $new_price;
543+
$delivery_booking = $this->updateAndFetch($data, $this->sample_order, $this->userWithBasePerms, true);
544+
545+
$old_price = $target_test_product->price * $data[$target_test_product->id];
546+
$new_price = $new_price * $data[$target_test_product->id];
547+
548+
$target_booked_test_product = $delivery_booking->products->firstWhere('product_id', $target_test_product->id);
549+
$this->assertEquals($target_booked_test_product->getValue('delivered'), $new_price);
550+
551+
$this->assertEquals($initial_value - $old_price + $new_price, $delivery_booking->getValue('delivered', false));
552+
}
553+
521554
/*
522555
I test per prenotazioni fatte da un amico sono fatti in
523556
ModifiersServiceTest

0 commit comments

Comments
 (0)