fix(items): persist clothing grants before redeem

Redeeming clothing furniture now inserts the wardrobe grant before removing/deleting the voucher furniture. If the DB insert fails, the item remains in the room and the in-memory wardrobe is not updated.

Tests: mvn -Dtest=RedeemClothingContractTest test; mvn -DskipTests package
This commit is contained in:
simoleo89
2026-06-14 20:39:51 +02:00
parent 82c6f3f9ff
commit 39c6e24097
2 changed files with 44 additions and 8 deletions
@@ -0,0 +1,29 @@
package com.eu.habbo.messages.incoming.rooms.items;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.jupiter.api.Test;
class RedeemClothingContractTest {
private static String source() throws Exception {
return Files.readString(Path.of("src/main/java/com/eu/habbo/messages/incoming/rooms/items/RedeemClothingEvent.java"));
}
@Test
void clothingIsGrantedBeforeVoucherFurnitureIsConsumed() throws Exception {
String source = source();
int grantCall = source.indexOf("grantClothing(");
int roomRemoval = source.indexOf("removeHabboItem(item)");
int deleteItem = source.indexOf("new QueryDeleteHabboItem(item.getId())");
assertTrue(source.contains("private boolean grantClothing(int clothingId)"),
"clothing DB insert should report whether the grant succeeded");
assertTrue(grantCall > -1, "redeem path should call grantClothing before consuming the item");
assertTrue(grantCall < roomRemoval, "room item must not be removed before the clothing grant succeeds");
assertTrue(grantCall < deleteItem, "voucher furniture must not be deleted before the clothing grant succeeds");
}
}