Skip to content

Commit

Permalink
Merge branch 'master' into aggregations
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Sep 7, 2024
2 parents 0a7ca07 + a95321f commit 97abef0
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
2 changes: 1 addition & 1 deletion code/app/Booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,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
2 changes: 1 addition & 1 deletion code/resources/views/multigas/edit.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<x-larastrap::mform :obj="$gas" method="PUT" :action="route('multigas.update', $gas->id)">
<x-larastrap::mform :obj="$gas" method="PUT" :action="route('multigas.update', $gas->id)" :nodelete="$currentuser->gas->id == $gas->id">
<div class="row">
<div class="col-6">
<x-larastrap::text name="name" :label="_i('Nome')" required />
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 97abef0

Please sign in to comment.