mirror of
https://github.com/arcan1s/ffxivbis.git
synced 2025-04-24 17:27:17 +00:00
compilation & test fixes
This commit is contained in:
parent
4a87ac8753
commit
4d12cbc1c1
@ -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))
|
||||
}
|
||||
|
@ -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(_ => ())
|
||||
|
@ -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)
|
||||
|
@ -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 =
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
|
11
src/test/scala/me/arcanis/ffxivbis/utils/Converters.scala
Normal file
11
src/test/scala/me/arcanis/ffxivbis/utils/Converters.scala
Normal 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))
|
||||
}
|
Loading…
Reference in New Issue
Block a user