Skip to content

Commit

Permalink
Add failing test for preview issue with badge summary of latest versions
Browse files Browse the repository at this point in the history
Currently, for the `content-api-firehose-client`, the Scaladex badges page
is showing some contrasting values:

https://index.scala-lang.org/guardian/content-api-firehose-client/badges

* The 'Latest version' badge is showing a good version:
  1.0.12
* The 'JVM badge' (which shows a summary of latest versions by supported
  Scala version, introduced with #660)
  is showing an undesireable pre-release version:
  1.0.13-PREVIEW.rt-dbremove-travis-file.2024-01-10T1738.6e259255

You can see both values on the versions page, but only if you tick the
'Show pre-release versions' button:

* https://index.scala-lang.org/guardian/content-api-firehose-client/artifacts/content-api-firehose-client
* https://index.scala-lang.org/guardian/content-api-firehose-client/artifacts/content-api-firehose-client?pre-releases=true#
  • Loading branch information
rtyley committed Jan 11, 2024
1 parent 6ddd036 commit 8d9146e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ object Values {
val `2.7.0` = PatchVersion(2, 7, 0)
val `7.0.0` = PatchVersion(7, 0, 0)
val `7.1.0` = PatchVersion(7, 1, 0)
val `7.2.0-PREVIEW1` = SemanticVersion.parse("7.2.0-PREVIEW.1").get
val `7.2.0-PREVIEW2` = SemanticVersion.parse("7.2.0-PREVIEW.2").get
val `7.2.0` = PatchVersion(7, 2, 0)
val `7.3.0` = PatchVersion(7, 3, 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ package scaladex.server.route
import scala.concurrent.Await
import scala.concurrent.Future
import scala.concurrent.duration.Duration

import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.model.Uri
import akka.http.scaladsl.model.headers.Location
import akka.http.scaladsl.server.Route
import org.scalatest.BeforeAndAfterAll
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers
import scaladex.core.model.Scala._
import scaladex.core.test.Values._
import scaladex.core.test.Values.{`7.2.0`, _}
import scaladex.core.util.ScalaExtensions._
import scaladex.server.route.Badges.summaryOfLatestVersions

class BadgesTests extends ControllerBaseSuite with BeforeAndAfterAll {

Expand All @@ -22,17 +24,6 @@ class BadgesTests extends ControllerBaseSuite with BeforeAndAfterAll {
def insertCats(): Future[Unit] =
Cats.allArtifacts.map(database.insertArtifact(_, Seq.empty, now)).sequence.map(_ => ())

it("should provide a concise summary of latest versions") {
Badges.summaryOfLatestVersions(
Map(
`2.11` -> Seq(`7.0.0`, `7.1.0`),
`2.12` -> Seq(`7.0.0`, `7.1.0`, `7.2.0`),
`2.13` -> Seq(`7.0.0`, `7.1.0`, `7.2.0`, `7.3.0`),
`3` -> Seq(`7.2.0`, `7.3.0`)
)
) shouldBe "7.3.0 (Scala 3.x, 2.13), 7.2.0 (Scala 2.12), 7.1.0 (Scala 2.11)"
}

it("should fallback to JVM artifacts") {
Get(s"/${Cats.reference}/cats-core/latest-by-scala-version.svg") ~> badgesRoute ~> check {
status shouldEqual StatusCodes.TemporaryRedirect
Expand Down Expand Up @@ -73,3 +64,25 @@ class BadgesTests extends ControllerBaseSuite with BeforeAndAfterAll {
}
}
}

class BadgesUnitTests extends AnyFunSpec with Matchers {
it("should provide a concise summary of latest versions") {
summaryOfLatestVersions(
Map(
`2.11` -> Seq(`7.0.0`, `7.1.0`),
`2.12` -> Seq(`7.0.0`, `7.1.0`, `7.2.0`),
`2.13` -> Seq(`7.0.0`, `7.1.0`, `7.2.0`, `7.3.0`),
`3` -> Seq(`7.2.0`, `7.3.0`)
)
) shouldBe "7.3.0 (Scala 3.x, 2.13), 7.2.0 (Scala 2.12), 7.1.0 (Scala 2.11)"
}

it("should prefer releases to pre-releases if both are available") {
summaryOfLatestVersions(Map(`2.13` -> Seq(`7.0.0`, `7.1.0`, `7.2.0-PREVIEW1`))) shouldBe "7.1.0 (Scala 2.13)"
}

it("should display latest pre-release if no full release is available") {
summaryOfLatestVersions(Map(`2.13` -> Seq(`7.2.0-PREVIEW1`, `7.2.0-PREVIEW2`))) shouldBe s"${`7.2.0-PREVIEW2`} (Scala 2.13)"
}

}

0 comments on commit 8d9146e

Please sign in to comment.