フロントエンドプレイアブル
This commit is contained in:
0
test/controllers/.keep
Normal file
0
test/controllers/.keep
Normal file
48
test/controllers/games_controller_test.rb
Normal file
48
test/controllers/games_controller_test.rb
Normal file
@@ -0,0 +1,48 @@
|
||||
require "test_helper"
|
||||
|
||||
class GamesControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@game = games(:one)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get games_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
get new_game_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create game" do
|
||||
assert_difference("Game.count") do
|
||||
post games_url, params: { game: { memo: @game.memo, participants_count: @game.participants_count, title: @game.title } }
|
||||
end
|
||||
|
||||
assert_redirected_to game_url(Game.last)
|
||||
end
|
||||
|
||||
test "should show game" do
|
||||
get game_url(@game)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
get edit_game_url(@game)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update game" do
|
||||
patch game_url(@game), params: { game: { memo: @game.memo, participants_count: @game.participants_count, title: @game.title } }
|
||||
assert_redirected_to game_url(@game)
|
||||
end
|
||||
|
||||
test "should destroy game" do
|
||||
assert_difference("Game.count", -1) do
|
||||
delete game_url(@game)
|
||||
end
|
||||
|
||||
assert_redirected_to games_url
|
||||
end
|
||||
end
|
||||
48
test/controllers/turns_controller_test.rb
Normal file
48
test/controllers/turns_controller_test.rb
Normal file
@@ -0,0 +1,48 @@
|
||||
require "test_helper"
|
||||
|
||||
class TurnsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@turn = turns(:one)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get turns_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
get new_turn_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create turn" do
|
||||
assert_difference("Turn.count") do
|
||||
post turns_url, params: { turn: { game_id: @turn.game_id, game_stat: @turn.game_stat, number: @turn.number, phase: @turn.phase, svg_date: @turn.svg_date } }
|
||||
end
|
||||
|
||||
assert_redirected_to turn_url(Turn.last)
|
||||
end
|
||||
|
||||
test "should show turn" do
|
||||
get turn_url(@turn)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
get edit_turn_url(@turn)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update turn" do
|
||||
patch turn_url(@turn), params: { turn: { game_id: @turn.game_id, game_stat: @turn.game_stat, number: @turn.number, phase: @turn.phase, svg_date: @turn.svg_date } }
|
||||
assert_redirected_to turn_url(@turn)
|
||||
end
|
||||
|
||||
test "should destroy turn" do
|
||||
assert_difference("Turn.count", -1) do
|
||||
delete turn_url(@turn)
|
||||
end
|
||||
|
||||
assert_redirected_to turns_url
|
||||
end
|
||||
end
|
||||
0
test/fixtures/files/.keep
vendored
Normal file
0
test/fixtures/files/.keep
vendored
Normal file
11
test/fixtures/games.yml
vendored
Normal file
11
test/fixtures/games.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
title: MyString
|
||||
participants_count: 1
|
||||
memo: MyText
|
||||
|
||||
two:
|
||||
title: MyString
|
||||
participants_count: 1
|
||||
memo: MyText
|
||||
19
test/fixtures/turns.yml
vendored
Normal file
19
test/fixtures/turns.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
number: 1
|
||||
phase: MyString
|
||||
game_state:
|
||||
possible_orders:
|
||||
orders:
|
||||
svg_date: MyText
|
||||
game: one
|
||||
|
||||
two:
|
||||
number: 1
|
||||
phase: MyString
|
||||
game_state:
|
||||
possible_orders:
|
||||
orders:
|
||||
svg_date: MyText
|
||||
game: two
|
||||
11
test/fixtures/users.yml
vendored
Normal file
11
test/fixtures/users.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
one:
|
||||
username: UserOne
|
||||
email: one@example.com
|
||||
password_digest: <%= BCrypt::Password.create('password') %>
|
||||
admin: false
|
||||
|
||||
two:
|
||||
username: UserTwo
|
||||
email: two@example.com
|
||||
password_digest: <%= BCrypt::Password.create('password') %>
|
||||
admin: false
|
||||
0
test/helpers/.keep
Normal file
0
test/helpers/.keep
Normal file
0
test/integration/.keep
Normal file
0
test/integration/.keep
Normal file
0
test/mailers/.keep
Normal file
0
test/mailers/.keep
Normal file
0
test/models/.keep
Normal file
0
test/models/.keep
Normal file
7
test/models/game_test.rb
Normal file
7
test/models/game_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class GameTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
7
test/models/turn_test.rb
Normal file
7
test/models/turn_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class TurnTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
7
test/models/user_test.rb
Normal file
7
test/models/user_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class UserTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
85
test/services/game_services_test.rb
Normal file
85
test/services/game_services_test.rb
Normal file
@@ -0,0 +1,85 @@
|
||||
ENV["RAILS_ENV"] ||= "test"
|
||||
require_relative "../test/test_helper"
|
||||
|
||||
class RefactoringVerificationTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@game = Game.create!(title: "Refactor Test #{Time.now.to_r}", status: "recruiting", participants_count: 7, is_solo_mode: true)
|
||||
end
|
||||
|
||||
# Mock Client Class
|
||||
class MockClient
|
||||
def initialize(initial_state: {}, possible_orders: {}, render_result: "<svg>...</svg>", process_result: nil, auto_orders: nil)
|
||||
@initial_state = initial_state
|
||||
@possible_orders = possible_orders
|
||||
@render_result = render_result
|
||||
@process_result = process_result
|
||||
@auto_orders = auto_orders
|
||||
end
|
||||
|
||||
def api_game_initial_state(map_name = "standard")
|
||||
@initial_state
|
||||
end
|
||||
|
||||
def api_render(game_state, orders: nil, incl_orders: true, incl_abbrev: true)
|
||||
@render_result
|
||||
end
|
||||
|
||||
def api_calculate_possible_orders(game_state, power_name: "", by_power: false)
|
||||
@possible_orders
|
||||
end
|
||||
|
||||
def api_calculate_process(game_state, orders)
|
||||
@process_result
|
||||
end
|
||||
|
||||
def api_calculate_auto_orders(game_state, power_name)
|
||||
@auto_orders
|
||||
end
|
||||
end
|
||||
|
||||
test "GameSetupService creates initial turn" do
|
||||
mock_client = MockClient.new(
|
||||
initial_state: { "game_state" => { "name" => "Spring 1901" } },
|
||||
possible_orders: { "FRANCE" => [] }
|
||||
)
|
||||
|
||||
service = GameSetupService.new(@game, client: mock_client)
|
||||
result = service.setup_initial_turn
|
||||
|
||||
assert result[:success], "Service failed: #{result[:message]}"
|
||||
assert_equal 1, @game.turns.count
|
||||
assert_equal "Spring 1901", @game.turns.first.phase
|
||||
end
|
||||
|
||||
test "OrderSubmissionService submits orders" do
|
||||
turn = @game.turns.create!(number: 1, game_state: { "name" => "S1901" })
|
||||
user = User.create!(username: "TestUser#{Time.now.to_r}", email: "test#{Time.now.to_r}@example.com", password: "password")
|
||||
|
||||
mock_client = MockClient.new
|
||||
|
||||
service = OrderSubmissionService.new(turn, user, client: mock_client)
|
||||
orders = { "A PAR" => "H" }
|
||||
|
||||
result = service.submit(power: "FRANCE", orders: orders)
|
||||
|
||||
assert result[:success]
|
||||
turn.reload
|
||||
assert_equal "H", turn.orders["FRANCE"]["A PAR"]
|
||||
end
|
||||
|
||||
test "TurnProcessingService processes turn" do
|
||||
turn = @game.turns.create!(number: 1, game_state: { "name" => "S1901" })
|
||||
|
||||
mock_client = MockClient.new(
|
||||
process_result: { "game_state" => { "name" => "Fall 1901" } },
|
||||
possible_orders: {}
|
||||
)
|
||||
|
||||
service = TurnProcessingService.new(turn, client: mock_client)
|
||||
result = service.process(force: "true")
|
||||
|
||||
assert result[:success], result[:message]
|
||||
assert_equal 2, @game.turns.count
|
||||
assert_equal "Fall 1901", @game.turns.last.phase
|
||||
end
|
||||
end
|
||||
15
test/test_helper.rb
Normal file
15
test/test_helper.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
ENV["RAILS_ENV"] ||= "test"
|
||||
require_relative "../config/environment"
|
||||
require "rails/test_help"
|
||||
|
||||
module ActiveSupport
|
||||
class TestCase
|
||||
# Run tests in parallel with specified workers
|
||||
parallelize(workers: :number_of_processors)
|
||||
|
||||
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
||||
fixtures :all
|
||||
|
||||
# Add more helper methods to be used by all tests here...
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user