// test "update_game/2 active=true with no game_users" { // game = insert(:game, %{ // active: false // }) // game = Repo.get!(Game, game.id) // update_game = %{ // active: true, // system: true // } // assert {:error, %Ecto.Changeset{ // errors: [ // active: {"must have at least two game_users", []} // ] // }} = Engine.update_game(game, update_game) // insert(:game_user, %{game: game, faction: 1}) // assert {:error, %Ecto.Changeset{ // errors: [ // active: {"must have at least two game_users", []} // ] // }} = Engine.update_game(game, update_game) // insert(:game_user, %{game: game, faction: 2}) // assert {:ok, Game {}} = Engine.update_game(game, update_game) // } // test "update_game/2 with active: true assigns properties" { // unit = insert(:unit) // unit_1 = build(:unit_map_data, %{faction: 1, unit_id: unit.id}) // unit_2 = build(:unit_map_data, %{faction: 2, unit_id: unit.id}) // unit_3 = build(:unit_map_data, %{faction: 3, unit_id: unit.id}) // unit_4 = build(:unit_map_data, %{faction: 4, unit_id: unit.id}) // tile_1 = build(:tile_data, %{faction: 1, user_id: nil}) // tile_2 = build(:tile_data, %{faction: 2, user_id: nil}) // tile_3 = build(:tile_data, %{faction: 3, user_id: nil}) // tile_4 = build(:tile_data, %{faction: 4, user_id: nil}) // map = insert(:map, %{ // unit_data: [unit_1, unit_2, unit_3, unit_4], // tile_data: [tile_1, tile_2, tile_3, tile_4] // }) // game = insert(:game, %{ // active: false, // map: map, // user_data: [], // unit_data: [], // tile_data: [], // map_settings: build(:map_settings, %{ // starting_weather: "Random", // weather_seed: "sunny skies all day long" // }) // }) // insert(:game_user, %{game: game, faction: 1, position: 3, team: 0}) // insert(:game_user, %{game: game, faction: 2, position: 2, team: 1}) // insert(:game_user, %{game: game, faction: 3, position: 1, team: 2}) // insert(:game_user, %{game: game, faction: 4, position: 0, team: 3}) // update_game = %{ // active: true, // system: true // } // assert {:ok, Game {} = game} = Engine.update_game(game, update_game) // assert game.weather == "Clear" // assert [ // UserData {faction: 4, position: 0, team: 3, active: true, turn: true} = user_data_1, // UserData {faction: 3, position: 1, team: 2, active: true, turn: false} = user_data_2, // UserData {faction: 2, position: 2, team: 1, active: true, turn: false} = user_data_3, // UserData {faction: 1, position: 3, team: 0, active: true, turn: false} = user_data_4 // ] = game.user_data // assert tile_1.tile_id == Enum.at(game.tile_data, 0).tile_id // assert tile_2.tile_id == Enum.at(game.tile_data, 1).tile_id // assert tile_3.tile_id == Enum.at(game.tile_data, 2).tile_id // assert tile_4.tile_id == Enum.at(game.tile_data, 3).tile_id // assert user_data_1.user_id == Enum.at(game.tile_data, 3).user_id // assert user_data_2.user_id == Enum.at(game.tile_data, 2).user_id // assert user_data_3.user_id == Enum.at(game.tile_data, 1).user_id // assert user_data_4.user_id == Enum.at(game.tile_data, 0).user_id // assert unit_1.unit_id == Enum.at(game.unit_data, 0).unit_id // assert unit_2.unit_id == Enum.at(game.unit_data, 1).unit_id // assert unit_3.unit_id == Enum.at(game.unit_data, 2).unit_id // assert unit_4.unit_id == Enum.at(game.unit_data, 3).unit_id // assert user_data_1.user_id == Enum.at(game.unit_data, 3).user_id // assert user_data_2.user_id == Enum.at(game.unit_data, 2).user_id // assert user_data_3.user_id == Enum.at(game.unit_data, 1).user_id // assert user_data_4.user_id == Enum.at(game.unit_data, 0).user_id // } // test "create_action/1 kind: game_start, valid" { // user = insert(:user) // game = insert(:game, %{ // active: false, // user: user, // map_settings: build(:map_settings, %{ // starting_weather: "Snow" // }) // }) // insert(:game_user, %{game: game, position: 1}) // insert(:game_user, %{game: game, position: 2}) // action = build(:action, %{ // kind: "game_start", // game_id: game.id, // user_id: user.id // }) // |> Map.from_struct() // assert {:ok, Action { // game: Game { // active: true, // weather: "Snow" // } // } = action} = Engine.create_action(action) // assert_delivered_email WebWarsNotify.Mailers.GameStart.email(action) // } // test "create_action/1 kind: game_start, invalid" { // user = insert(:user) // game = insert(:game, %{ // active: false, // user: user // }) // action = build(:action, %{ // kind: "game_start", // game_id: game.id, // user_id: user.id // }) // |> Map.drop([:user, :game]) // |> Map.from_struct() // assert {:error, %Ecto.Changeset{ // errors: [ // active: {"must have at least two game_users", []} // ] // }} = Engine.create_action(action) // }