Skip to content

Commit

Permalink
fix: Level relationship updated correctly
Browse files Browse the repository at this point in the history
tests: Added a new sanity test
  • Loading branch information
cjmellor committed Oct 4, 2023
1 parent 5162e21 commit 59f73bb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
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
3 changes: 0 additions & 3 deletions src/Listeners/UserLevelledUpListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ public function __invoke(UserLevelledUp $event): void
'level_to' => $event->level,
'type' => AuditType::LevelUp->value,
]);
$event->user->experience->update(attributes: [
'level_id' => $event->level,
]);
}
}
}
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 59f73bb

Please sign in to comment.