mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-20 13:50:46 +00:00
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:
18
test/controllers/break_escape/missions_controller_test.rb
Normal file
18
test/controllers/break_escape/missions_controller_test.rb
Normal 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
|
||||
5
test/fixtures/break_escape/demo_users.yml
vendored
Normal file
5
test/fixtures/break_escape/demo_users.yml
vendored
Normal 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
7
test/fixtures/break_escape/games.yml
vendored
Normal 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
13
test/fixtures/break_escape/missions.yml
vendored
Normal 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
|
||||
38
test/models/break_escape/game_test.rb
Normal file
38
test/models/break_escape/game_test.rb
Normal 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
|
||||
28
test/models/break_escape/mission_test.rb
Normal file
28
test/models/break_escape/mission_test.rb
Normal 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
|
||||
Reference in New Issue
Block a user