diff --git a/src/Concerns/GiveExperience.php b/src/Concerns/GiveExperience.php index 898e86c..44d101e 100644 --- a/src/Concerns/GiveExperience.php +++ b/src/Concerns/GiveExperience.php @@ -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++) { diff --git a/tests/Concerns/GiveExperienceTest.php b/tests/Concerns/GiveExperienceTest.php index 9b18b78..40d77e4 100644 --- a/tests/Concerns/GiveExperienceTest.php +++ b/tests/Concerns/GiveExperienceTest.php @@ -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();