From 4d12cbc1c1fe3027b1fd8ff3480ed8cff05427ff Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Sun, 8 Mar 2020 03:36:17 +0300 Subject: [PATCH] compilation & test fixes --- .../ffxivbis/http/api/v1/json/PlayerResponse.scala | 2 +- .../me/arcanis/ffxivbis/http/view/PlayerView.scala | 2 +- .../ffxivbis/service/impl/DatabasePartyHandler.scala | 4 ++-- .../me/arcanis/ffxivbis/storage/PlayersProfile.scala | 2 +- src/test/scala/me/arcanis/ffxivbis/Fixtures.scala | 4 ++-- .../ffxivbis/http/api/v1/LootEndpointTest.scala | 11 +++++++++-- .../scala/me/arcanis/ffxivbis/models/PlayerTest.scala | 4 +++- .../ffxivbis/service/DatabaseLootHandlerTest.scala | 4 +++- .../arcanis/ffxivbis/service/LootSelectorTest.scala | 8 +++++--- .../scala/me/arcanis/ffxivbis/utils/Converters.scala | 11 +++++++++++ 10 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 src/test/scala/me/arcanis/ffxivbis/utils/Converters.scala diff --git a/src/main/scala/me/arcanis/ffxivbis/http/api/v1/json/PlayerResponse.scala b/src/main/scala/me/arcanis/ffxivbis/http/api/v1/json/PlayerResponse.scala index e4860f0..277baf7 100644 --- a/src/main/scala/me/arcanis/ffxivbis/http/api/v1/json/PlayerResponse.scala +++ b/src/main/scala/me/arcanis/ffxivbis/http/api/v1/json/PlayerResponse.scala @@ -20,7 +20,7 @@ case class PlayerResponse( @Schema(description = "link to best in slot", example = "https://ffxiv.ariyala.com/19V5R") link: Option[String], @Schema(description = "player loot priority", `type` = "number") priority: Option[Int]) { def toPlayer: Player = - Player(partyId, Job.withName(job), nick, + Player(-1, partyId, Job.withName(job), nick, BiS(bis.getOrElse(Seq.empty).map(_.toPiece)), loot.getOrElse(Seq.empty).map(_.toLoot), link, priority.getOrElse(0)) } diff --git a/src/main/scala/me/arcanis/ffxivbis/http/view/PlayerView.scala b/src/main/scala/me/arcanis/ffxivbis/http/view/PlayerView.scala index 390be61..c47234f 100644 --- a/src/main/scala/me/arcanis/ffxivbis/http/view/PlayerView.scala +++ b/src/main/scala/me/arcanis/ffxivbis/http/view/PlayerView.scala @@ -62,7 +62,7 @@ class PlayerView(override val storage: ActorRef, ariyala: ActorRef)(implicit tim (implicit executionContext: ExecutionContext, timeout: Timeout): Future[Unit] = { def maybePlayerId = PlayerId(partyId, Some(nick), Some(job)) def player(playerId: PlayerId) = - Player(partyId, playerId.job, playerId.nick, BiS(), Seq.empty, maybeLink, maybePriority.getOrElse(0)) + Player(-1, partyId, playerId.job, playerId.nick, BiS(), Seq.empty, maybeLink, maybePriority.getOrElse(0)) (action, maybePlayerId) match { case ("add", Some(playerId)) => addPlayer(player(playerId)).map(_ => ()) diff --git a/src/main/scala/me/arcanis/ffxivbis/service/impl/DatabasePartyHandler.scala b/src/main/scala/me/arcanis/ffxivbis/service/impl/DatabasePartyHandler.scala index c96ba54..3537573 100644 --- a/src/main/scala/me/arcanis/ffxivbis/service/impl/DatabasePartyHandler.scala +++ b/src/main/scala/me/arcanis/ffxivbis/service/impl/DatabasePartyHandler.scala @@ -33,8 +33,8 @@ trait DatabasePartyHandler { this: Database => for { bis <- profile.getPiecesBiS(playerId) loot <- profile.getPieces(playerId) - } yield Player(playerId.partyId, playerId.job, playerId.nick, - BiS(bis.map(_.piece)), loot, + } yield Player(playerData.id, playerId.partyId, playerId.job, + playerId.nick, BiS(bis.map(_.piece)), loot, playerData.link, playerData.priority) } }.map(_.headOption) diff --git a/src/main/scala/me/arcanis/ffxivbis/storage/PlayersProfile.scala b/src/main/scala/me/arcanis/ffxivbis/storage/PlayersProfile.scala index e723545..46f5cbc 100644 --- a/src/main/scala/me/arcanis/ffxivbis/storage/PlayersProfile.scala +++ b/src/main/scala/me/arcanis/ffxivbis/storage/PlayersProfile.scala @@ -18,7 +18,7 @@ trait PlayersProfile { this: DatabaseProfile => case class PlayerRep(partyId: String, playerId: Option[Long], created: Long, nick: String, job: String, link: Option[String], priority: Int) { def toPlayer: Player = - Player(partyId, Job.withName(job), nick, BiS(Seq.empty), List.empty, link, priority) + Player(playerId.getOrElse(-1), partyId, Job.withName(job), nick, BiS(Seq.empty), List.empty, link, priority) } object PlayerRep { def fromPlayer(player: Player, id: Option[Long]): PlayerRep = diff --git a/src/test/scala/me/arcanis/ffxivbis/Fixtures.scala b/src/test/scala/me/arcanis/ffxivbis/Fixtures.scala index 45ffe11..27642ae 100644 --- a/src/test/scala/me/arcanis/ffxivbis/Fixtures.scala +++ b/src/test/scala/me/arcanis/ffxivbis/Fixtures.scala @@ -33,13 +33,13 @@ object Fixtures { lazy val lootLeftRing: Piece = Ring(isTome = true, Job.AnyJob, "left ring") lazy val lootRightRing: Piece = Ring(isTome = true, Job.AnyJob, "right ring") lazy val lootUpgrade: Piece = BodyUpgrade - lazy val loot: Seq[Loot] = Seq(lootBody, lootHands, lootLegs, lootUpgrade) + lazy val loot: Seq[Piece] = Seq(lootBody, lootHands, lootLegs, lootUpgrade) lazy val partyId: String = Party.randomPartyId lazy val partyId2: String = Party.randomPartyId lazy val playerEmpty: Player = - Player(partyId, Job.DNC, "Siuan Sanche", BiS(), Seq.empty, Some(link)) + Player(1, partyId, Job.DNC, "Siuan Sanche", BiS(), Seq.empty, Some(link)) lazy val playerWithBiS: Player = playerEmpty.copy(bis = bis) lazy val userPassword: String = "password" diff --git a/src/test/scala/me/arcanis/ffxivbis/http/api/v1/LootEndpointTest.scala b/src/test/scala/me/arcanis/ffxivbis/http/api/v1/LootEndpointTest.scala index b82b8eb..da0e5f5 100644 --- a/src/test/scala/me/arcanis/ffxivbis/http/api/v1/LootEndpointTest.scala +++ b/src/test/scala/me/arcanis/ffxivbis/http/api/v1/LootEndpointTest.scala @@ -1,5 +1,7 @@ package me.arcanis.ffxivbis.http.api.v1 +import java.time.Instant + import akka.actor.ActorRef import akka.http.scaladsl.model.{StatusCodes, Uri} import akka.http.scaladsl.model.headers.{Authorization, BasicHttpCredentials} @@ -58,12 +60,17 @@ class LootEndpointTest extends WordSpec } "return looted items" in { + import me.arcanis.ffxivbis.utils.Converters._ + val uri = endpoint.withQuery(Uri.Query(Map("nick" -> playerId.nick, "job" -> playerId.job))) - val response = Seq(PlayerResponse.fromPlayer(Fixtures.playerEmpty.withLoot(Fixtures.lootBody.toLoot(-1)))) + val response = Seq(PlayerResponse.fromPlayer(Fixtures.playerEmpty.withLoot(Fixtures.lootBody))) Get(uri).withHeaders(auth) ~> route ~> check { status shouldEqual StatusCodes.OK - responseAs[Seq[PlayerResponse]] shouldEqual response + val withEmptyTimestamp = responseAs[Seq[PlayerResponse]].map { player => + player.copy(loot = player.loot.map(_.map(_.copy(timestamp = Instant.ofEpochMilli(0))))) + } + withEmptyTimestamp shouldEqual response } } diff --git a/src/test/scala/me/arcanis/ffxivbis/models/PlayerTest.scala b/src/test/scala/me/arcanis/ffxivbis/models/PlayerTest.scala index 871cbdd..5e483c1 100644 --- a/src/test/scala/me/arcanis/ffxivbis/models/PlayerTest.scala +++ b/src/test/scala/me/arcanis/ffxivbis/models/PlayerTest.scala @@ -12,7 +12,9 @@ class PlayerTest extends WordSpecLike with Matchers with BeforeAndAfterAll { } "add loot" in { - Fixtures.playerEmpty.withLoot(Fixtures.loot).loot shouldEqual Fixtures.loot + import me.arcanis.ffxivbis.utils.Converters._ + + Fixtures.playerEmpty.withLoot(Fixtures.loot.map(pieceToLoot)).loot.map(_.piece) shouldEqual Fixtures.loot } } diff --git a/src/test/scala/me/arcanis/ffxivbis/service/DatabaseLootHandlerTest.scala b/src/test/scala/me/arcanis/ffxivbis/service/DatabaseLootHandlerTest.scala index 6ad3d8d..b152458 100644 --- a/src/test/scala/me/arcanis/ffxivbis/service/DatabaseLootHandlerTest.scala +++ b/src/test/scala/me/arcanis/ffxivbis/service/DatabaseLootHandlerTest.scala @@ -83,5 +83,7 @@ class DatabaseLootHandlerTest } private def partyLootCompare[T](party: Seq[T], loot: Seq[Piece]): Boolean = - Compare.seqEquals(party.foldLeft(Seq.empty[Piece]){ case (acc, player) => acc ++ player.asInstanceOf[Player].loot }, loot) + Compare.seqEquals(party.foldLeft(Seq.empty[Piece]){ case (acc, player) => + acc ++ player.asInstanceOf[Player].loot.map(_.piece) + }, loot) } diff --git a/src/test/scala/me/arcanis/ffxivbis/service/LootSelectorTest.scala b/src/test/scala/me/arcanis/ffxivbis/service/LootSelectorTest.scala index 2d973e3..a771447 100644 --- a/src/test/scala/me/arcanis/ffxivbis/service/LootSelectorTest.scala +++ b/src/test/scala/me/arcanis/ffxivbis/service/LootSelectorTest.scala @@ -14,9 +14,11 @@ import scala.language.postfixOps class LootSelectorTest extends TestKit(ActorSystem("lootselector")) with ImplicitSender with WordSpecLike with Matchers with BeforeAndAfterAll { + import me.arcanis.ffxivbis.utils.Converters._ + private var default: Party = Party(Some(Fixtures.partyId), Settings.config(Map.empty)) - private var dnc: Player = Player(Fixtures.partyId, Job.DNC, "a nick", BiS(), Seq.empty, Some(Fixtures.link)) - private var drg: Player = Player(Fixtures.partyId, Job.DRG, "another nick", BiS(), Seq.empty, Some(Fixtures.link2)) + private var dnc: Player = Player(-1, Fixtures.partyId, Job.DNC, "a nick", BiS(), Seq.empty, Some(Fixtures.link)) + private var drg: Player = Player(-1, Fixtures.partyId, Job.DRG, "another nick", BiS(), Seq.empty, Some(Fixtures.link2)) private val timeout: FiniteDuration = 60 seconds override def beforeAll(): Unit = { @@ -77,7 +79,7 @@ class LootSelectorTest extends TestKit(ActorSystem("lootselector")) "suggest loot by total piece got" in { val piece = Body(isTome = true, Job.AnyJob) val party = default - .withPlayer(dnc.withLoot(Seq(piece, piece))) + .withPlayer(dnc.withLoot(Seq(piece, piece).map(pieceToLoot))) .withPlayer(drg.withLoot(piece)) toPlayerId(party.suggestLoot(piece)) shouldEqual Seq(drg.playerId, dnc.playerId) diff --git a/src/test/scala/me/arcanis/ffxivbis/utils/Converters.scala b/src/test/scala/me/arcanis/ffxivbis/utils/Converters.scala new file mode 100644 index 0000000..bb3ca13 --- /dev/null +++ b/src/test/scala/me/arcanis/ffxivbis/utils/Converters.scala @@ -0,0 +1,11 @@ +package me.arcanis.ffxivbis.utils + +import java.time.Instant + +import me.arcanis.ffxivbis.models.{Loot, Piece} + +import scala.language.implicitConversions + +object Converters { + implicit def pieceToLoot(piece: Piece): Loot = Loot(-1, piece, Instant.ofEpochMilli(0)) +}