compilation & test fixes

This commit is contained in:
Evgenii Alekseev 2020-03-08 03:36:17 +03:00
parent 4a87ac8753
commit 4d12cbc1c1
10 changed files with 38 additions and 14 deletions

View File

@ -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))
}

View File

@ -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(_ => ())

View File

@ -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)

View File

@ -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 =

View File

@ -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"

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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)
}

View File

@ -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)

View File

@ -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))
}