|
7 | 7 |
|
8 | 8 | use App\Exceptions\AuthException; |
9 | 9 | use App\Exceptions\IllegalArgumentException; |
| 10 | +use App\Product; |
10 | 11 | use App\Booking; |
11 | 12 | use App\Movement; |
12 | 13 |
|
@@ -518,6 +519,38 @@ public function test_insufficient_credit_with_limit() |
518 | 519 | $this->assertNotNull($booking); |
519 | 520 | } |
520 | 521 |
|
| 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 | + |
521 | 554 | /* |
522 | 555 | I test per prenotazioni fatte da un amico sono fatti in |
523 | 556 | ModifiersServiceTest |
|
0 commit comments