diff --git a/code/app/Booking.php b/code/app/Booking.php index 8572dede..5ae42af5 100644 --- a/code/app/Booking.php +++ b/code/app/Booking.php @@ -149,7 +149,7 @@ public function allModifiedValues($id, $with_friends) }); } - return $values; + return $values->unique('id'); } /* diff --git a/code/app/Services/NotificationsService.php b/code/app/Services/NotificationsService.php index 33e5ce54..de9bd9df 100644 --- a/code/app/Services/NotificationsService.php +++ b/code/app/Services/NotificationsService.php @@ -14,7 +14,7 @@ public function list($start, $end) { $user = $this->ensureAuth(); - $notifications_query = Notification::orderBy('start_date', 'desc'); + $notifications_query = Notification::orderBy('start_date', 'desc')->with(['users']); if (!is_null($start)) { $notifications_query->where('end_date', '>=', $start); diff --git a/code/tests/Services/DynamicBookingsServiceTest.php b/code/tests/Services/DynamicBookingsServiceTest.php index d93359bf..33736b9e 100644 --- a/code/tests/Services/DynamicBookingsServiceTest.php +++ b/code/tests/Services/DynamicBookingsServiceTest.php @@ -319,7 +319,7 @@ private function attachDiscount($product) /* Lettura dinamica delle prenotazioni, prodotto con modificatori */ - public function testModifiersOnProduct() + public function testModifiersOnProductBooking() { $product = $this->order->products->random(); $this->attachDiscount($product); @@ -336,10 +336,60 @@ public function testModifiersOnProduct() $this->assertEquals(count($ret->bookings), 1); foreach($ret->bookings as $b) { + $this->assertEquals($b->total, $product->price * 2 - ($product->price * 0.10 * 2)); + + $this->assertEquals(count($b->modifiers), 1); + foreach($b->modifiers as $mid => $mod) { + $this->assertEquals($mod->amount, round($product->price * 0.10 * 2, 2) * -1); + } + $this->assertEquals(count($b->products), 1); + foreach($b->products as $pid => $p) { + $this->assertEquals($p->quantity, 2); + $this->assertEquals($p->total, $product->price * 2); + } + } + } + + /* + Lettura dinamica delle consegne, prodotto con modificatori + */ + public function testModifiersOnProductShipping() + { + $product = $this->order->products->random(); + $this->attachDiscount($product); + + $this->actingAs($this->userWithBasePerms); + + $data = [ + 'action' => 'booked', + $product->id => 2, + ]; + + app()->make('BookingsService')->bookingUpdate($data, $this->order->aggregate, $this->userWithBasePerms, false); + + $this->nextRound(); + + $this->actingAs($this->userWithShippingPerms); + + $data = [ + 'action' => 'shipped', + $product->id => 2, + ]; + + $ret = app()->make('DynamicBookingsService')->dynamicModifiers($data, $this->order->aggregate, $this->userWithBasePerms); + + $this->assertEquals(count($ret->bookings), 1); + + foreach($ret->bookings as $b) { $this->assertEquals($b->total, $product->price * 2 - ($product->price * 0.10 * 2)); + $this->assertEquals(count($b->modifiers), 1); + foreach($b->modifiers as $mid => $mod) { + $this->assertEquals($mod->amount, round($product->price * 0.10 * 2, 2) * -1); + } + $this->assertEquals(count($b->products), 1); foreach($b->products as $pid => $p) { $this->assertEquals($p->quantity, 2); $this->assertEquals($p->total, $product->price * 2);