Skip to content

Commit

Permalink
fix calcolo modificatori in fase di consegna. closes #284
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Sep 7, 2024
1 parent 3a75bb2 commit a95321f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
2 changes: 1 addition & 1 deletion code/app/Booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function allModifiedValues($id, $with_friends)
});
}

return $values;
return $values->unique('id');
}

/*
Expand Down
2 changes: 1 addition & 1 deletion code/app/Services/NotificationsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
52 changes: 51 additions & 1 deletion code/tests/Services/DynamicBookingsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit a95321f

Please sign in to comment.