diff --git a/code/app/Services/CirclesService.php b/code/app/Services/CirclesService.php index d0f7e48b..b0d70552 100644 --- a/code/app/Services/CirclesService.php +++ b/code/app/Services/CirclesService.php @@ -59,7 +59,7 @@ public function update($id, array $request) $this->boolIfSet($c, $request, 'is_default'); if ($c->is_default) { - $c->group->circles()->update(['is_default' => false]); + $c->group->circles()->where('circles.id', '!=', $c->id)->update(['is_default' => false]); } $c->save(); diff --git a/code/tests/Services/GroupsServiceTest.php b/code/tests/Services/GroupsServiceTest.php index b95812d7..5b9714f1 100644 --- a/code/tests/Services/GroupsServiceTest.php +++ b/code/tests/Services/GroupsServiceTest.php @@ -21,10 +21,7 @@ public function setUp(): void $this->userWithNoPerms = User::factory()->create(['gas_id' => $this->gas->id]); } - /* - Salvataggio Gruppo e Cerchie - */ - public function testStore() + private function createGroupWithCircle() { $this->actingAs($this->userAdmin); @@ -35,8 +32,6 @@ public function testStore() $this->nextRound(); $group = Group::find($group->id); - $this->assertEquals('Luoghi di Consegna', $group->name); - $circle = app()->make('CirclesService')->store([ 'name' => 'Bar Sport', 'description' => 'Un test', @@ -46,8 +41,6 @@ public function testStore() $this->nextRound(); $circle = Circle::find($circle->id); - $this->assertTrue($circle->is_default == true); - $circle2 = app()->make('CirclesService')->store([ 'name' => 'Da Mario', 'description' => 'Un altro test', @@ -57,13 +50,70 @@ public function testStore() $this->nextRound(); $circle2 = Circle::find($circle2->id); + return [$group, $circle, $circle2]; + } + + /* + Salvataggio Gruppo e Cerchie + */ + public function testStore() + { + list($group, $circle, $circle2) = $this->createGroupWithCircle(); + + $this->nextRound(); + + $this->assertEquals('Luoghi di Consegna', $group->name); + $this->assertTrue($circle->is_default == true); $this->assertTrue($circle2->is_default == false); + $group = Group::find($group->id); + $this->assertEquals(2, $group->circles()->count()); + $users = User::all(); + $this->assertTrue($users->count() > 0); + foreach($users as $user) { $assigned = $user->circlesByGroup($group); $this->assertEquals(1, count($assigned->circles)); $this->assertEquals($circle->id, $assigned->circles[0]->id); } } + + /* + Aggiornamento Gruppo e Cerchie + */ + public function testUpdate() + { + list($group, $circle, $circle2) = $this->createGroupWithCircle(); + + $this->nextRound(); + + app()->make('CirclesService')->update($circle->id, [ + 'name' => 'Bar Sport 2', + 'description' => 'Un altro test', + 'is_default' => true, + ]); + + $this->nextRound(); + $circle = Circle::find($circle->id); + $this->assertEquals('Bar Sport 2', $circle->name); + + $this->nextRound(); + $this->assertTrue($circle->is_default == true); + app()->make('CirclesService')->destroy($circle->id); + $this->nextRound(); + + $group = Group::find($group->id); + $this->assertEquals(1, $group->circles()->count()); + + $circle2 = Circle::find($circle2->id); + $this->assertTrue($circle2->is_default == true); + + $users = User::all(); + foreach($users as $user) { + $assigned = $user->circlesByGroup($group); + $this->assertEquals(1, count($assigned->circles)); + $this->assertEquals($circle2->id, $assigned->circles[0]->id); + } + } } diff --git a/code/tests/Services/MultiGasServiceTest.php b/code/tests/Services/MultiGasServiceTest.php index aa9f228d..26dea0a1 100644 --- a/code/tests/Services/MultiGasServiceTest.php +++ b/code/tests/Services/MultiGasServiceTest.php @@ -81,6 +81,37 @@ public function testStore() $this->assertEquals($user->roles()->where('roles.id', $role->id)->count(), 1); } + /* + Aggiornamento GAS + */ + public function testUpdate() + { + $role = $this->initSubgasAdminRole(); + $this->nextRound(); + $gas = $this->createGas(); + + $this->nextRound(); + $this->userSuperAdmin = app()->make('UsersService')->show($this->userSuperAdmin->id); + + $this->nextRound(); + $this->actingAs($this->userSuperAdmin); + $gas = app()->make('MultiGasService')->update($gas->id, ['name' => 'Cambio nome']); + + $this->nextRound(); + + $list = app()->make('MultiGasService')->list(); + $this->assertCount(2, $list); + + $found = 0; + foreach($list as $g) { + if ($g->name == 'Cambio nome') { + $found++; + } + } + + $this->assertEquals($found, 1); + } + /* Assegnazione fornitore a due GAS */ @@ -116,8 +147,14 @@ public function testAttach() ]); /* - TODO: verificare effettivo accesso al fornitore da parte del secondo - GAS, tenuto conto delle cache sparse + Questo è necessario per resettare lo stato interno dell'hub e fargli + rileggere i GAS attualmente sul DB */ + app()->forgetInstance('GlobalScopeHub'); + + $this->nextRound(); + + $suppliers = app()->make('SuppliersService')->list(); + $this->assertCount(1, $suppliers); } } diff --git a/code/tests/Services/OrdersServiceTest.php b/code/tests/Services/OrdersServiceTest.php index d98d7488..597e70fa 100644 --- a/code/tests/Services/OrdersServiceTest.php +++ b/code/tests/Services/OrdersServiceTest.php @@ -43,13 +43,8 @@ public function testFailsToStore() ]); } - /* - Creazione Ordine - */ - public function testStore() + private function storeMailableOrder() { - Notification::fake(); - $this->gas->setConfig('notify_all_new_orders', '1'); $this->userWithNoPerms->addContact('email', fake()->email()); $this->userWithBasePerms->addContact('email', fake()->email()); @@ -75,6 +70,18 @@ public function testStore() 'status' => 'open', ]); + return [$aggregate, $start, $end, $shipping]; + } + + /* + Creazione Ordine + */ + public function testStore() + { + Notification::fake(); + + list($aggregate, $start, $end, $shipping) = $this->storeMailableOrder(); + $this->assertEquals(1, $aggregate->orders->count()); $this->assertTrue($aggregate->isActive()); $this->assertTrue($aggregate->isRunning()); @@ -115,6 +122,19 @@ public function testStore() } } + /* + Creazione Ordine. + Questa funzione è identica alla precedente, ma non intercetta le + notifiche in modo che venga eseguito il codice destinato alla loro + formattazione. Non vengono qui eseguiti test rilevanti: basta che non si + schianti + */ + public function testStoreMails() + { + $this->storeMailableOrder(); + $this->assertTrue(true); + } + /* Modifica Ordine con permessi sbagliati */ @@ -157,12 +177,8 @@ public function testUpdate() $this->assertEquals($order->end, $this->order->end); } - /* - Chiusura ordini automatica - */ - public function testAutoClose() + private function initMailableOrder() { - Notification::fake(); $this->populateOrder($this->order); $this->nextRound(); @@ -186,6 +202,18 @@ public function testAutoClose() Artisan::call('close:orders'); + return $booking; + } + + /* + Chiusura ordini automatica + */ + public function testAutoClose() + { + Notification::fake(); + + $booking = $this->initMailableOrder(); + $order = app()->make('OrdersService')->show($this->order->id); $this->assertEquals('closed', $order->status); @@ -194,6 +222,19 @@ public function testAutoClose() Notification::assertSentTo([$booking->user], \App\Notifications\BookingNotification::class); } + /* + Chiusura ordini automatica. + Questa funzione è identica alla precedente, ma non intercetta le + notifiche in modo che venga eseguito il codice destinato alla loro + formattazione. Non vengono qui eseguiti test rilevanti: basta che non si + schianti + */ + public function testAutoCloseMails() + { + $this->initMailableOrder(); + $this->assertTrue(true); + } + /* Cambio stato */