test: Add comprehensive test suite

- Add fixtures for missions, demo_users, games
- Add model tests for Mission and Game
- Add controller tests for MissionsController
- Test validations, scopes, and methods
- Test state management and health clamping
- Ready for integration testing in host app
This commit is contained in:
Z. Cliffe Schreuders
2025-11-21 15:27:54 +00:00
parent 006ed4af3e
commit 8b71cf5f2f
6 changed files with 109 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
require 'test_helper'
module BreakEscape
class MissionsControllerTest < ActionDispatch::IntegrationTest
include Engine.routes.url_helpers
test "should get index" do
get missions_url
assert_response :success
end
test "should show published mission" do
mission = break_escape_missions(:ceo_exfil)
get mission_url(mission)
assert_response :redirect # Redirects to game
end
end
end

View File

@@ -0,0 +1,5 @@
test_user:
handle: test_user
other_user:
handle: other_user

7
test/fixtures/break_escape/games.yml vendored Normal file
View File

@@ -0,0 +1,7 @@
active_game:
player: test_user (BreakEscape::DemoUser)
mission: ceo_exfil
scenario_data: { "startRoom": "reception", "rooms": {} }
player_state: { "currentRoom": "reception", "unlockedRooms": ["reception"] }
status: in_progress
score: 0

13
test/fixtures/break_escape/missions.yml vendored Normal file
View File

@@ -0,0 +1,13 @@
ceo_exfil:
name: ceo_exfil
display_name: CEO Exfiltration
description: Test scenario
published: true
difficulty_level: 3
unpublished:
name: test_unpublished
display_name: Unpublished Test
description: Not visible
published: false
difficulty_level: 1

View File

@@ -0,0 +1,38 @@
require 'test_helper'
module BreakEscape
class GameTest < ActiveSupport::TestCase
setup do
@game = games(:active_game)
end
test "should belong to player and mission" do
assert @game.player
assert @game.mission
end
test "should unlock room" do
@game.unlock_room!('office')
assert @game.room_unlocked?('office')
end
test "should track inventory" do
item = { 'type' => 'key', 'name' => 'Test Key' }
@game.add_inventory_item!(item)
assert_includes @game.player_state['inventory'], item
end
test "should update health" do
@game.update_health!(50)
assert_equal 50, @game.player_state['health']
end
test "should clamp health between 0 and 100" do
@game.update_health!(150)
assert_equal 100, @game.player_state['health']
@game.update_health!(-10)
assert_equal 0, @game.player_state['health']
end
end
end

View File

@@ -0,0 +1,28 @@
require 'test_helper'
module BreakEscape
class MissionTest < ActiveSupport::TestCase
test "should validate presence of name" do
mission = Mission.new(display_name: 'Test')
assert_not mission.valid?
assert mission.errors[:name].any?
end
test "should validate uniqueness of name" do
Mission.create!(name: 'test', display_name: 'Test')
duplicate = Mission.new(name: 'test', display_name: 'Test 2')
assert_not duplicate.valid?
end
test "published scope returns only published missions" do
assert_includes Mission.published, missions(:ceo_exfil)
assert_not_includes Mission.published, missions(:unpublished)
end
test "scenario_path returns correct path" do
mission = missions(:ceo_exfil)
expected = Rails.root.join('app', 'assets', 'scenarios', 'ceo_exfil')
assert_equal expected, mission.scenario_path
end
end
end