Marcus’ nitpicks

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-07-03 23:01:41 +01:00
parent 9211c8d3b1
commit 9f1e59cf78
4 changed files with 8 additions and 23 deletions

View file

@ -153,7 +153,7 @@ class ActionlogFactory extends Factory
});
}
public function logUserUpdate()
public function userUpdated()
{
return $this->state(function () {

View file

@ -124,7 +124,7 @@ class ConsumableFactory extends Factory
$consumable->users()->attach($consumable->id, [
'consumable_id' => $consumable->id,
'created_at' => Carbon::now(),
'user_id' => 1,
'user_id' => User::factory()->create()->id,
'assigned_to' => $user->id ?? User::factory()->create()->id,
]);
});

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Users\Console;
namespace Tests\Feature\Console;
use App\Models\Accessory;
use App\Models\Asset;
@ -23,7 +23,6 @@ class MergeUsersTest extends TestCase
$this->artisan('snipeit:merge-users')->assertExitCode(0);
$this->assertNotEquals(3, $user_to_merge_into->refresh()->assets->count());
$this->assertEquals(6, $user_to_merge_into->refresh()->assets->count());
$this->assertEquals(0, $user1->refresh()->assets->count());
@ -41,7 +40,6 @@ class MergeUsersTest extends TestCase
$this->artisan('snipeit:merge-users')->assertExitCode(0);
$this->assertNotEquals(3, $user_to_merge_into->refresh()->licenses->count());
$this->assertEquals(6, $user_to_merge_into->refresh()->licenses->count());
$this->assertEquals(0, $user1->refresh()->licenses->count());
@ -59,7 +57,6 @@ class MergeUsersTest extends TestCase
$this->artisan('snipeit:merge-users')->assertExitCode(0);
$this->assertNotEquals(3, $user_to_merge_into->refresh()->accessories->count());
$this->assertEquals(6, $user_to_merge_into->refresh()->accessories->count());
$this->assertEquals(0, $user1->refresh()->accessories->count());
@ -77,7 +74,6 @@ class MergeUsersTest extends TestCase
$this->artisan('snipeit:merge-users')->assertExitCode(0);
$this->assertNotEquals(3, $user_to_merge_into->refresh()->consumables->count());
$this->assertEquals(6, $user_to_merge_into->refresh()->consumables->count());
$this->assertEquals(0, $user1->refresh()->consumables->count());
@ -95,7 +91,6 @@ class MergeUsersTest extends TestCase
$this->artisan('snipeit:merge-users')->assertExitCode(0);
$this->assertNotEquals(3, $user_to_merge_into->refresh()->uploads->count());
$this->assertEquals(6, $user_to_merge_into->refresh()->uploads->count());
$this->assertEquals(0, $user1->refresh()->uploads->count());
@ -113,7 +108,6 @@ class MergeUsersTest extends TestCase
$this->artisan('snipeit:merge-users')->assertExitCode(0);
$this->assertNotEquals(3, $user_to_merge_into->refresh()->acceptances->count());
$this->assertEquals(6, $user_to_merge_into->refresh()->acceptances->count());
$this->assertEquals(0, $user1->refresh()->acceptances->count());
@ -124,15 +118,13 @@ class MergeUsersTest extends TestCase
$user1 = User::factory()->create(['username' => 'user1']);
$user_to_merge_into = User::factory()->create(['username' => 'user1@example.com']);
Actionlog::factory()->count(3)->logUserUpdate()->create(['target_id' => $user1->id, 'item_id' => $user1->id]);
Actionlog::factory()->count(3)->logUserUpdate()->create(['target_id' => $user_to_merge_into->id, 'item_id' => $user_to_merge_into->id]);
Actionlog::factory()->count(3)->userUpdated()->create(['target_id' => $user1->id, 'item_id' => $user1->id]);
Actionlog::factory()->count(3)->userUpdated()->create(['target_id' => $user_to_merge_into->id, 'item_id' => $user_to_merge_into->id]);
$this->assertEquals(3, $user_to_merge_into->refresh()->userlog->count());
$this->artisan('snipeit:merge-users')->assertExitCode(0);
$this->assertNotEquals(3, $user_to_merge_into->refresh()->userlog->count());
// This needs to be more than the otherwise expected because the merge action itself is logged for the two merging users
$this->assertEquals(7, $user_to_merge_into->refresh()->userlog->count());
$this->assertEquals(1, $user1->refresh()->userlog->count());

View file

@ -33,7 +33,6 @@ class MergeUsersTest extends TestCase
->assertRedirect(route('users.index'));
$this->followRedirects($response)->assertSee('Success');
$this->assertNotEquals(3, $user_to_merge_into->refresh()->assets->count());
$this->assertEquals(9, $user_to_merge_into->refresh()->assets->count());
$this->assertEquals(0, $user1->refresh()->assets->count());
$this->assertEquals(0, $user2->refresh()->assets->count());
@ -62,7 +61,6 @@ class MergeUsersTest extends TestCase
->assertRedirect(route('users.index'));
$this->followRedirects($response)->assertSee('Success');
$this->assertNotEquals(3, $user_to_merge_into->refresh()->licenses->count());
$this->assertEquals(9, $user_to_merge_into->refresh()->licenses->count());
$this->assertEquals(0, $user1->refresh()->licenses->count());
$this->assertEquals(0, $user2->refresh()->licenses->count());
@ -91,7 +89,6 @@ class MergeUsersTest extends TestCase
->assertRedirect(route('users.index'));
$this->followRedirects($response)->assertSee('Success');
$this->assertNotEquals(3, $user_to_merge_into->refresh()->accessories->count());
$this->assertEquals(9, $user_to_merge_into->refresh()->accessories->count());
$this->assertEquals(0, $user1->refresh()->accessories->count());
$this->assertEquals(0, $user2->refresh()->accessories->count());
@ -120,7 +117,6 @@ class MergeUsersTest extends TestCase
->assertRedirect(route('users.index'));
$this->followRedirects($response)->assertSee('Success');
$this->assertNotEquals(3, $user_to_merge_into->refresh()->consumables->count());
$this->assertEquals(9, $user_to_merge_into->refresh()->consumables->count());
$this->assertEquals(0, $user1->refresh()->consumables->count());
$this->assertEquals(0, $user2->refresh()->consumables->count());
@ -149,7 +145,6 @@ class MergeUsersTest extends TestCase
->assertRedirect(route('users.index'));
$this->followRedirects($response)->assertSee('Success');
$this->assertNotEquals(3, $user_to_merge_into->refresh()->uploads->count());
$this->assertEquals(9, $user_to_merge_into->refresh()->uploads->count());
$this->assertEquals(0, $user1->refresh()->uploads->count());
$this->assertEquals(0, $user2->refresh()->uploads->count());
@ -178,7 +173,6 @@ class MergeUsersTest extends TestCase
->assertRedirect(route('users.index'));
$this->followRedirects($response)->assertSee('Success');
$this->assertNotEquals(3, $user_to_merge_into->refresh()->acceptances->count());
$this->assertEquals(9, $user_to_merge_into->refresh()->acceptances->count());
$this->assertEquals(0, $user1->refresh()->acceptances->count());
$this->assertEquals(0, $user2->refresh()->acceptances->count());
@ -191,9 +185,9 @@ class MergeUsersTest extends TestCase
$user2 = User::factory()->create();
$user_to_merge_into = User::factory()->create();
Actionlog::factory()->count(3)->logUserUpdate()->create(['target_id' => $user1->id, 'item_id' => $user1->id]);
Actionlog::factory()->count(3)->logUserUpdate()->create(['target_id' => $user2->id, 'item_id' => $user2->id]);
Actionlog::factory()->count(3)->logUserUpdate()->create(['target_id' => $user_to_merge_into->id, 'item_id' => $user_to_merge_into->id]);
Actionlog::factory()->count(3)->userUpdated()->create(['target_id' => $user1->id, 'item_id' => $user1->id]);
Actionlog::factory()->count(3)->userUpdated()->create(['target_id' => $user2->id, 'item_id' => $user2->id]);
Actionlog::factory()->count(3)->userUpdated()->create(['target_id' => $user_to_merge_into->id, 'item_id' => $user_to_merge_into->id]);
$this->assertEquals(3, $user_to_merge_into->refresh()->userlog->count());
@ -207,7 +201,6 @@ class MergeUsersTest extends TestCase
->assertRedirect(route('users.index'));
$this->followRedirects($response)->assertSee('Success');
$this->assertNotEquals(3, $user_to_merge_into->refresh()->userlog->count());
// This needs to be 2 more than the otherwise expected because the merge action itself is logged for the two merging users
$this->assertEquals(11, $user_to_merge_into->refresh()->userlog->count());