Skip to content

Commit

Permalink
Merge pull request #48 from 7OMI/patch-1
Browse files Browse the repository at this point in the history
fix: update level_id in experiences table when levelled up
  • Loading branch information
cjmellor committed Oct 4, 2023
2 parents 304cfb3 + 59f73bb commit e809a42
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Concerns/GiveExperience.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function levelUp(int $to): void
->save();

$this->experience->status()->associate(model: $to);
$this->save();
$this->experience->save();

// Fire an event for each level gained
for ($lvl = $this->getLevel(); $lvl <= $to; $lvl++) {
Expand Down
11 changes: 11 additions & 0 deletions tests/Concerns/GiveExperienceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@
]);
});

test(description: 'levels are associated on point increments', closure: function () {
$this->user->addPoints(amount: 10);

expect($this->user)->level_id->toBe(expected: 1);

$this->user->addPoints(amount: 100);

expect($this->user)->level_id->toBe(expected: 2)
->and($this->user)->getLevel()->toBe(expected: 2);
});

it(description: 'can deduct points from a User', closure: function (): void {
Event::fake();

Expand Down

0 comments on commit e809a42

Please sign in to comment.