Skip to content

Commit

Permalink
qualche nuovo unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Sep 7, 2024
1 parent 6109ebc commit 8dbd543
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 22 deletions.
2 changes: 1 addition & 1 deletion code/app/Services/CirclesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
66 changes: 58 additions & 8 deletions code/tests/Services/GroupsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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);
}
}
}
41 changes: 39 additions & 2 deletions code/tests/Services/MultiGasServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
}
}
63 changes: 52 additions & 11 deletions code/tests/Services/OrdersServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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();
Expand All @@ -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);

Expand All @@ -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
*/
Expand Down

0 comments on commit 8dbd543

Please sign in to comment.