@rpgjs/server 5.0.0-beta.2 → 5.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -92,6 +92,7 @@ const FreeSkill = {
92
92
 
93
93
  let player: RpgPlayer;
94
94
  let fixture: TestingFixture;
95
+ const onSkillChangeSpy = vi.fn();
95
96
 
96
97
  // Define server module with skills in database
97
98
  const serverModule = defineModule({
@@ -113,6 +114,7 @@ const serverModule = defineModule({
113
114
  async onConnected(player) {
114
115
  await player.changeMap("test-map", { x: 100, y: 100 });
115
116
  },
117
+ onSkillChange: onSkillChangeSpy,
116
118
  },
117
119
  });
118
120
 
@@ -122,6 +124,7 @@ const clientModule = defineModule({
122
124
  });
123
125
 
124
126
  beforeEach(async () => {
127
+ onSkillChangeSpy.mockClear();
125
128
  const myModule = createModule("TestModule", [
126
129
  {
127
130
  server: serverModule,
@@ -523,6 +526,51 @@ describe("Skill Management - Hooks", () => {
523
526
  expect(onForgetSpy).toHaveBeenCalledWith(player);
524
527
  });
525
528
 
529
+ test("should call player onSkillChange hook when learning skill", () => {
530
+ const skill = player.learnSkill("fire");
531
+
532
+ expect(skill).toBe(FireSkill);
533
+ expect(onSkillChangeSpy).toHaveBeenCalledWith(
534
+ player,
535
+ expect.objectContaining({
536
+ action: "learn",
537
+ skill: FireSkill,
538
+ skillId: "fire",
539
+ source: "manual",
540
+ }),
541
+ );
542
+ });
543
+
544
+ test("should call player onSkillChange hook when forgetting skill", () => {
545
+ player.learnSkill("fire");
546
+ onSkillChangeSpy.mockClear();
547
+
548
+ player.forgetSkill("fire");
549
+
550
+ expect(onSkillChangeSpy).toHaveBeenCalledWith(
551
+ player,
552
+ expect.objectContaining({
553
+ action: "forget",
554
+ skillId: "fire",
555
+ source: "manual",
556
+ }),
557
+ );
558
+ });
559
+
560
+ test("should pass source and level to onSkillChange hook", () => {
561
+ player.learnSkill("fire", { source: "level", level: 3 });
562
+
563
+ expect(onSkillChangeSpy).toHaveBeenCalledWith(
564
+ player,
565
+ expect.objectContaining({
566
+ action: "learn",
567
+ skillId: "fire",
568
+ source: "level",
569
+ level: 3,
570
+ }),
571
+ );
572
+ });
573
+
526
574
  test("should call onUse hook when using skill successfully", () => {
527
575
  const onUseSpy = vi.fn();
528
576
  const customSkill: SkillObject = {