mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-20 13:50:46 +00:00
Refactor tests and improve NPC handling
- Updated NPC ink loading tests to ensure proper handling of missing story files. - Adjusted lazy loading tests for rooms to enhance clarity and maintainability. - Enhanced unlock system tests by adding inventory checks for keys. - Refined filtered scenario tests to ensure accurate preservation of game state. - Improved game model tests to validate unlock functionality with various inventory scenarios.
This commit is contained in:
@@ -39,7 +39,7 @@ module BreakEscape
|
||||
# Create a game with custom scenario data, bypassing the generate callback
|
||||
mission = break_escape_missions(:ceo_exfil)
|
||||
player = break_escape_demo_users(:test_user)
|
||||
|
||||
|
||||
game = Game.new(
|
||||
mission: mission,
|
||||
player: player,
|
||||
@@ -47,14 +47,14 @@ module BreakEscape
|
||||
)
|
||||
# Manually skip callback and save
|
||||
game.save(validate: false)
|
||||
|
||||
|
||||
filtered = game.filtered_scenario_for_bootstrap
|
||||
|
||||
|
||||
# Check top-level fields are preserved
|
||||
assert_equal "Test mission", filtered["scenario_brief"]
|
||||
assert_equal "start", filtered["startRoom"]
|
||||
assert filtered["startItemsInInventory"].present?
|
||||
|
||||
|
||||
# Check rooms structure exists
|
||||
assert filtered["rooms"].present?
|
||||
assert filtered["rooms"]["start"].present?
|
||||
@@ -64,20 +64,20 @@ module BreakEscape
|
||||
test 'filtered_scenario_for_bootstrap preserves navigation structure' do
|
||||
mission = break_escape_missions(:ceo_exfil)
|
||||
player = break_escape_demo_users(:test_user)
|
||||
|
||||
|
||||
game = Game.new(mission: mission, player: player, scenario_data: @scenario_data)
|
||||
game.save(validate: false)
|
||||
|
||||
|
||||
filtered = game.filtered_scenario_for_bootstrap
|
||||
|
||||
|
||||
start_room = filtered["rooms"]["start"]
|
||||
|
||||
|
||||
# Keep connections for navigation
|
||||
assert_equal({ "north" => "next_room" }, start_room["connections"])
|
||||
|
||||
|
||||
# Keep type for room rendering
|
||||
assert_equal "room_office", start_room["type"]
|
||||
|
||||
|
||||
# Keep lock info for validation
|
||||
assert_equal false, start_room["locked"]
|
||||
end
|
||||
@@ -85,14 +85,14 @@ module BreakEscape
|
||||
test 'filtered_scenario_for_bootstrap removes objects and npcs' do
|
||||
mission = break_escape_missions(:ceo_exfil)
|
||||
player = break_escape_demo_users(:test_user)
|
||||
|
||||
|
||||
game = Game.new(mission: mission, player: player, scenario_data: @scenario_data)
|
||||
game.save(validate: false)
|
||||
|
||||
|
||||
filtered = game.filtered_scenario_for_bootstrap
|
||||
|
||||
|
||||
start_room = filtered["rooms"]["start"]
|
||||
|
||||
|
||||
# Objects and NPCs should be removed
|
||||
assert_nil start_room["objects"]
|
||||
assert_nil start_room["npcs"]
|
||||
@@ -101,14 +101,14 @@ module BreakEscape
|
||||
test 'filtered_scenario_for_bootstrap preserves lock requirements' do
|
||||
mission = break_escape_missions(:ceo_exfil)
|
||||
player = break_escape_demo_users(:test_user)
|
||||
|
||||
|
||||
game = Game.new(mission: mission, player: player, scenario_data: @scenario_data)
|
||||
game.save(validate: false)
|
||||
|
||||
|
||||
filtered = game.filtered_scenario_for_bootstrap
|
||||
|
||||
|
||||
locked_room = filtered["rooms"]["next_room"]
|
||||
|
||||
|
||||
# Keep lock data for server-side validation
|
||||
assert_equal true, locked_room["locked"]
|
||||
assert_equal "key", locked_room["lockType"]
|
||||
@@ -118,17 +118,17 @@ module BreakEscape
|
||||
test 'filtered_scenario_for_bootstrap does not modify original' do
|
||||
mission = break_escape_missions(:ceo_exfil)
|
||||
player = break_escape_demo_users(:test_user)
|
||||
|
||||
|
||||
game = Game.new(mission: mission, player: player, scenario_data: @scenario_data)
|
||||
game.save(validate: false)
|
||||
|
||||
|
||||
original_rooms = game.scenario_data["rooms"].keys
|
||||
filtered = game.filtered_scenario_for_bootstrap
|
||||
|
||||
|
||||
# Original should still have all data
|
||||
assert game.scenario_data["rooms"]["start"]["objects"].present?
|
||||
assert game.scenario_data["rooms"]["start"]["npcs"].present?
|
||||
|
||||
|
||||
# Filtered should not
|
||||
assert_nil filtered["rooms"]["start"]["objects"]
|
||||
assert_nil filtered["rooms"]["start"]["npcs"]
|
||||
|
||||
@@ -68,7 +68,7 @@ module BreakEscape
|
||||
@game.player_state['inventory'] = [
|
||||
{ 'type' => 'key', 'key_id' => 'office1_key', 'name' => 'Office Key' }
|
||||
]
|
||||
|
||||
|
||||
result = @game.validate_unlock('door', 'office1', '', 'key')
|
||||
assert result, "Should unlock door with correct key in inventory"
|
||||
end
|
||||
@@ -86,7 +86,7 @@ module BreakEscape
|
||||
@game.player_state['inventory'] = [
|
||||
{ 'type' => 'key', 'key_id' => 'wrong_key', 'name' => 'Wrong Key' }
|
||||
]
|
||||
|
||||
|
||||
result = @game.validate_unlock('door', 'office1', '', 'key')
|
||||
assert_not result, "Should reject unlock without required key"
|
||||
end
|
||||
@@ -102,7 +102,7 @@ module BreakEscape
|
||||
}
|
||||
}
|
||||
@game.player_state['inventory'] = []
|
||||
|
||||
|
||||
result = @game.validate_unlock('door', 'office1', '', nil)
|
||||
assert_not result, "Should reject locked door without unlock method"
|
||||
end
|
||||
@@ -121,7 +121,7 @@ module BreakEscape
|
||||
@game.player_state['inventory'] = [
|
||||
{ 'type' => 'lockpick', 'name' => 'Lock Pick Kit' }
|
||||
]
|
||||
|
||||
|
||||
result = @game.validate_unlock('door', 'office1', '', 'lockpick')
|
||||
assert result, "Should unlock door with lockpick"
|
||||
end
|
||||
@@ -139,7 +139,7 @@ module BreakEscape
|
||||
@game.player_state['inventory'] = [
|
||||
{ 'type' => 'key', 'key_id' => 'office1_key', 'name' => 'Office Key' }
|
||||
]
|
||||
|
||||
|
||||
result = @game.validate_unlock('door', 'office1', '', 'lockpick')
|
||||
assert_not result, "Should reject lockpick unlock without lockpick in inventory"
|
||||
end
|
||||
@@ -158,7 +158,7 @@ module BreakEscape
|
||||
@game.player_state['inventory'] = [
|
||||
{ 'type' => 'lockpick', 'name' => 'Lock Pick Kit' }
|
||||
]
|
||||
|
||||
|
||||
# Should succeed with lockpick even without the master key
|
||||
result = @game.validate_unlock('door', 'secure_vault', '', 'lockpick')
|
||||
assert result, "Lockpick should bypass specific key requirement"
|
||||
@@ -178,7 +178,7 @@ module BreakEscape
|
||||
{ 'type' => 'key', 'key_id' => 'office1_key', 'name' => 'Office Key' },
|
||||
{ 'type' => 'lockpick', 'name' => 'Lock Pick Kit' }
|
||||
]
|
||||
|
||||
|
||||
# Key unlock should succeed
|
||||
result = @game.validate_unlock('door', 'office1', '', 'key')
|
||||
assert result, "Key unlock should succeed"
|
||||
@@ -193,7 +193,7 @@ module BreakEscape
|
||||
}
|
||||
}
|
||||
@game.player_state['inventory'] = []
|
||||
|
||||
|
||||
result = @game.validate_unlock('door', 'reception', '', 'unlocked')
|
||||
assert result, "Should allow access to unlocked doors"
|
||||
end
|
||||
@@ -202,7 +202,7 @@ module BreakEscape
|
||||
@game.player_state['inventory'] = [
|
||||
{ 'type' => 'key', 'key_id' => 'office1_key', 'name' => 'Office Key' }
|
||||
]
|
||||
|
||||
|
||||
assert @game.has_key_in_inventory?('office1_key'), "Should find key by key_id"
|
||||
assert_not @game.has_key_in_inventory?('wrong_key'), "Should not find missing key"
|
||||
end
|
||||
@@ -211,7 +211,7 @@ module BreakEscape
|
||||
@game.player_state['inventory'] = [
|
||||
{ 'type' => 'lockpick', 'name' => 'Lock Pick Kit' }
|
||||
]
|
||||
|
||||
|
||||
assert @game.has_lockpick_in_inventory?, "Should find lockpick in inventory"
|
||||
end
|
||||
|
||||
@@ -219,7 +219,7 @@ module BreakEscape
|
||||
@game.player_state['inventory'] = [
|
||||
{ 'type' => 'key', 'key_id' => 'office1_key', 'name' => 'Office Key' }
|
||||
]
|
||||
|
||||
|
||||
assert_not @game.has_lockpick_in_inventory?, "Should not find non-lockpick items as lockpick"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user