Skip to content

Commit

Permalink
Fix gearpreset ammo bug
Browse files Browse the repository at this point in the history
  • Loading branch information
gc committed Oct 12, 2024
1 parent e50fe6f commit 9bab974
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/mahoji/commands/gearpresets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ function gearPresetToGear(preset: GearPreset): GearSetup {
newGear.shield = gearItem(preset.shield);
newGear.weapon = gearItem(preset.weapon);
newGear.ring = gearItem(preset.ring);
newGear.ammo = preset.ammo
? {
item: preset.ammo,
quantity: 1
}
: null;
return newGear;
}
export async function createOrEditGearSetup(
Expand Down
29 changes: 26 additions & 3 deletions tests/integration/commands/gearPresets.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { randInt } from 'e';
import { EItem } from 'oldschooljs';
import { describe, expect, test, vi } from 'vitest';

import itemID from '../../../src/lib/util/itemID';
Expand Down Expand Up @@ -62,20 +63,42 @@ describe('Gear Presets Command', async () => {
edit: { gear_preset: 'TestEdit', weapon: 'Ghrazi rapier', feet: 'None' }
});

const gpEditResult = await global.prisma!.gearPreset.findFirst({
await user.runCommand(gearPresetsCommand, {
edit: { gear_preset: 'TestEdit', ammo: "Rada's blessing 4" }
});

const gpEditResult = await global.prisma!.gearPreset.findFirstOrThrow({
where: { user_id: user.id, name: 'testedit' }
});

// Verify row found:
expect(gpEditResult).toBeTruthy();
if (!gpEditResult) return false;

// Make sure row is as expected:
expect(gpEditResult.head).toEqual(itemID('Bronze full helm'));
expect(gpEditResult.feet).toBeNull();
expect(gpEditResult.weapon).toEqual(itemID('Ghrazi rapier'));
expect(gpEditResult.shield).toEqual(itemID('Bronze kiteshield'));
expect(gpEditResult.hands).toBeNull();
expect(gpEditResult.ammo).toBeNull();
expect(gpEditResult.ammo).toEqual(EItem.RADAS_BLESSING_4);

await user.runCommand(gearPresetsCommand, {
edit: { gear_preset: 'TestEdit', head: 'Bronze med helm' }
});

const gpEditResult2 = await global.prisma!.gearPreset.findFirstOrThrow({
where: { user_id: user.id, name: 'testedit' }
});
expect(gpEditResult2.ammo).toEqual(EItem.RADAS_BLESSING_4);
expect(gpEditResult2.head).toEqual(EItem.BRONZE_MED_HELM);

await user.runCommand(gearPresetsCommand, {
edit: { gear_preset: 'TestEdit', ammo: 'None' }
});
const gpEditResult3 = await global.prisma!.gearPreset.findFirstOrThrow({
where: { user_id: user.id, name: 'testedit' }
});
expect(gpEditResult3.ammo).toBeNull();
expect(gpEditResult3.ammo_qty).toBeNull();
});
});

0 comments on commit 9bab974

Please sign in to comment.