Skip to content

Commit 3004455

Browse files
committed
feat: update test
1 parent 578f07c commit 3004455

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

app-modules/gamify/tests/Feature/ReputationTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
declare(strict_types=1);
44

5+
use App\Models\User;
56
use Laravelcm\Gamify\Models\Reputation;
67

8+
beforeEach(function (): void {
9+
$this->user = createUser(['reputation' => 0]);
10+
});
11+
712
describe(Reputation::class, function (): void {
813

914
it('gets user points', function (): void {
@@ -13,11 +18,11 @@
1318
});
1419

1520
it('gives reputation point to a user', function (): void {
16-
expect($user->getPoints())->toBe(0);
21+
expect($this->user->getPoints())->toBe(0);
1722

1823
$user->addPoint(10);
1924

20-
expect($user->fresh()->getPoints())->toBe(10);
25+
expect($this->user->fresh()->getPoints())->toBe(10);
2126
});
2227

2328
it('reduces reputation point for a user', function (): void {
@@ -38,4 +43,17 @@
3843
expect($user->fresh()->getPoints())->toBe(0);
3944
});
4045

46+
function createUser(array $attributes = []): User
47+
{
48+
$user = new User;
49+
50+
$user->forceFill(array_merge($attributes, [
51+
'name' => 'Demo',
52+
'email' => '[email protected]',
53+
'password' => 'password',
54+
]))->save();
55+
56+
return $user->fresh();
57+
}
58+
4159
});

app-modules/gamify/tests/Pest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Illuminate\Foundation\Testing\RefreshDatabase;
77
use Tests\TestCase;
88

9-
uses(TestCase::class, RefreshDatabase::class) > in('Feature');
9+
uses(TestCase::class, RefreshDatabase::class)->in('Feature');
1010

1111
function createUser(array $attributes = []): User
1212
{

0 commit comments

Comments
 (0)