// describe "changeset/2" { // test "validates widths" { // map = build(:map, %{ // user_id: UUID.generate(), // map_data: "1,1,1\n1,1,1,1\n1,1,1", // tile_data: [ // TileData {tile_id: Tile.HQ.id(), faction: 1, coord: Coord {x: 0, y: 0}}, // TileData {tile_id: Tile.HQ.id(), faction: 2, coord: Coord {x: 0, y: 1}} // ] // }) // assert Changeset { // errors: [ // map_data: {"widths must match", []} // ] // } = Engine.Map.changeset(%Engine.Map{}, map) // } // test "populates player count based on properties" { // map = build(:map, %{ // user_id: UUID.generate(), // map_data: "#{Tile.HQ.id()}", // tile_data: [ // TileData {tile_id: Tile.HQ.id(), faction: 1, coord: Coord {x: 0, y: 0}}, // TileData {tile_id: Tile.HQ.id(), faction: 1, coord: Coord {x: 0, y: 0}}, // TileData {tile_id: Tile.HQ.id(), faction: 2, coord: Coord {x: 0, y: 0}}, // TileData {tile_id: Tile.HQ.id(), faction: 2, coord: Coord {x: 0, y: 0}} // ], // unit_data: [ // UnitMapData {faction: 1, unit_id: UUID.generate(), coord: Coord {x: 0, y: 0}}, // UnitMapData {faction: 1, unit_id: UUID.generate(), coord: Coord {x: 0, y: 0}}, // UnitMapData {faction: 3, unit_id: UUID.generate(), coord: Coord {x: 0, y: 0}}, // UnitMapData {faction: 4, unit_id: UUID.generate(), coord: Coord {x: 0, y: 0}} // ] // }) // assert Changeset { // changes: %{ // players: 4 // } // } = Engine.Map.changeset(%Engine.Map{}, map) // } // test "validates map has at least two primary_hqs, valid" { // map = build(:map, %{ // user_id: UUID.generate(), // map_data: "#{Tile.HQ.id()}", // tile_data: [ // TileData {tile_id: Tile.HQ.id(), faction: 1, coord: Coord {x: 0, y: 0}} // ] // }) // assert Changeset { // errors: [ // players: {"must have at least two players", []} // ] // } = Engine.Map.changeset(%Engine.Map{}, map) // } // test "validates map checks for hqs vs owned properties, invalid" { // map = build(:map, %{ // user_id: UUID.generate(), // map_data: "#{Tile.City.id()}", // tile_data: [ // TileData {tile_id: Tile.City.id(), faction: 1, coord: Coord {x: 0, y: 0}}, // TileData {tile_id: Tile.City.id(), faction: 2, coord: Coord {x: 0, y: 0}} // ] // }) // assert Changeset { // errors: [ // players: {"must have at least two players", []} // ] // } = Engine.Map.changeset(%Engine.Map{}, map) // } // test "validates map has at least two primary_hqs, invalid" { // map = build(:map, %{ // user_id: UUID.generate(), // map_data: "#{Tile.HQ.id()}", // tile_data: [ // TileData {tile_id: Tile.HQ.id(), faction: 1, coord: Coord {x: 0, y: 0}}, // TileData {tile_id: Tile.HQ.id(), faction: 2, coord: Coord {x: 0, y: 0}} // ] // }) // assert Changeset {valid?: true} = Engine.Map.changeset(%Engine.Map{}, map) // } // test "validates map has at least two secondary_hqs, invalid" { // map = build(:map, %{ // user_id: UUID.generate(), // map_data: "#{Tile.Lab.id()}", // tile_data: [ // TileData {tile_id: Tile.Lab.id(), faction: 1, coord: Coord {x: 0, y: 0}} // ] // }) // assert Changeset { // errors: [ // players: {"must have at least two players", []} // ] // } = Engine.Map.changeset(%Engine.Map{}, map) // } // test "validates map has at least two secondary_hqs, valid" { // map = build(:map, %{ // user_id: UUID.generate(), // map_data: "#{Tile.Lab.id()}", // tile_data: [ // TileData {tile_id: Tile.Lab.id(), faction: 1, coord: Coord {x: 0, y: 0}}, // TileData {tile_id: Tile.Lab.id(), faction: 2, coord: Coord {x: 0, y: 0}} // ] // }) // assert Changeset {valid?: true} = Engine.Map.changeset(%Engine.Map{}, map) // } // test "validates map has at least two differently-owned secondary_hqs, invalid" { // map = build(:map, %{ // user_id: UUID.generate(), // map_data: "#{Tile.Lab.id()}", // tile_data: [ // TileData {tile_id: Tile.Lab.id(), faction: 1, coord: Coord {x: 0, y: 0}}, // TileData {tile_id: Tile.Lab.id(), faction: 1, coord: Coord {x: 0, y: 0}} // ] // }) // assert Changeset { // errors: [ // players: {"must have at least two players", []} // ] // } = Engine.Map.changeset(%Engine.Map{}, map) // } // test "validates map has at least two mixed hqs, valid" { // map = build(:map, %{ // user_id: UUID.generate(), // map_data: "#{Tile.HQ.id()},#{Tile.Lab.id()}", // tile_data: [ // TileData {tile_id: Tile.HQ.id(), faction: 1, coord: Coord {x: 0, y: 0}}, // TileData {tile_id: Tile.Lab.id(), faction: 2, coord: Coord {x: 1, y: 0}} // ] // }) // assert Changeset {valid?: true} = Engine.Map.changeset(%Engine.Map{}, map) // } // test "validates map has at least two differently owned units, invalid" { // map = build(:map, %{ // user_id: UUID.generate(), // tile_data: [], // unit_data: [ // UnitMapData {faction: 1, unit_id: UUID.generate(), coord: Coord {x: 0, y: 0}}, // UnitMapData {faction: 1, unit_id: UUID.generate(), coord: Coord {x: 0, y: 0}} // ] // }) // assert Changeset { // errors: [ // players: {"must have at least two players", []} // ] // } = Engine.Map.changeset(%Engine.Map{}, map) // } // test "validates map has at least two differently owned units, valid" { // map = build(:map, %{ // user_id: UUID.generate(), // map_data: "#{Tile.Lab.id()}", // tile_data: [ // TileData {tile_id: Tile.Lab.id(), faction: 1, coord: Coord {x: 0, y: 0}}, // TileData {tile_id: Tile.Lab.id(), faction: 1, coord: Coord {x: 0, y: 0}} // ] // }) // assert Changeset { // errors: [ // players: {"must have at least two players", []} // ] // } = Engine.Map.changeset(%Engine.Map{}, map) // } // test "validates map has at least two differently owned entities, valid" { // map = build(:map, %{ // user_id: UUID.generate(), // map_data: "#{Tile.Lab.id()}", // tile_data: [ // TileData {tile_id: Tile.Lab.id(), faction: 1, coord: Coord {x: 0, y: 0}} // ], // unit_data: [ // UnitMapData {faction: 2, unit_id: UUID.generate(), coord: Coord {x: 0, y: 0}} // ] // }) // assert Changeset {valid?: true} = Engine.Map.changeset(%Engine.Map{}, map) // } // } // }