Skip to content

Commit

Permalink
Optimize tests with time travelling between multiple actions within t…
Browse files Browse the repository at this point in the history
…he same test
  • Loading branch information
Kovah committed Feb 22, 2024
1 parent f930ec0 commit fa73ba1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions tests/Components/History/LinkEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function testModelDeletion(): void
$link = Link::factory()->create();

$link->delete();
$this->travel(10)->seconds();
$link->restore();

$historyEntries = $link->audits()->get();
Expand Down
1 change: 1 addition & 0 deletions tests/Components/History/ListEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function testModelDeletion(): void
$list = LinkList::factory()->create();

$list->delete();
$this->travel(10)->seconds();
$list->restore();

$historyEntries = $list->audits()->get();
Expand Down
1 change: 1 addition & 0 deletions tests/Components/History/TagEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function testModelDeletion(): void
$tag = Tag::factory()->create();

$tag->delete();
$this->travel(10)->seconds();
$tag->restore();

$historyEntries = $tag->audits()->get();
Expand Down
25 changes: 13 additions & 12 deletions tests/Components/History/UserEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ public function testRegularChange(): void
public function testModelDeletion(): void
{
$user = User::factory()->create(['name' => 'TestUser']);

$this->travel(10)->seconds();
$user->delete();
$this->travel(10)->seconds();
$user->restore();

$historyEntries = $user->audits()->latest()->get();
$output = (new UserEntry($historyEntries[0]))->render();
$this->assertStringContainsString('User <code>TestUser</code> was restored', $output);

$output = (new UserEntry($historyEntries[1]))->render();
$this->assertStringContainsString('User <code>TestUser</code> was deleted', $output);

$user->restore();

$historyEntries = $user->audits()->latest()->get();

$output = (new UserEntry($historyEntries[2]))->render();
$this->assertStringContainsString('User <code>TestUser</code> was restored', $output);
$this->assertStringContainsString('User <code>TestUser</code> was created', $output);
}

public function testModelBlocking(): void
Expand All @@ -56,19 +56,20 @@ public function testModelBlocking(): void
$this->actingAs($admin);

$user = User::factory()->create(['name' => 'TestUser']);

$this->travel(10)->seconds();
$this->patch('system/users/2/block');
$this->travel(10)->seconds();
$this->patch('system/users/2/unblock');

$historyEntries = $user->audits()->latest()->get();

$output = (new UserEntry($historyEntries[0]))->render();
$this->assertStringContainsString('User <code>TestUser</code> was unblocked', $output);

$output = (new UserEntry($historyEntries[1]))->render();
$this->assertStringContainsString('User <code>TestUser</code> was blocked', $output);

$this->patch('system/users/2/unblock');

$historyEntries = $user->audits()->latest()->get();

$output = (new UserEntry($historyEntries[2]))->render();
$this->assertStringContainsString('User <code>TestUser</code> was unblocked', $output);
$this->assertStringContainsString('User <code>TestUser</code> was created', $output);
}
}

0 comments on commit fa73ba1

Please sign in to comment.