Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SmokeTest #122

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions app/modules/ApplicationStart.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ApplicationStart @Inject()(
ws: WSClient,
configuration: Configuration,
cache: SyncCacheApi
) {
) extends Logging {

private val accessToken = configuration.get[String]("accessToken")
private val organization = configuration.get[String]("githubOrganisation")
Expand All @@ -33,19 +33,21 @@ class ApplicationStart @Inject()(

{
// Parse all and put into cache
println("loading posts…")
logger.info("loading posts…")
val fPosts = getPosts()
fPosts.map { posts =>
cache.set("posts", posts)
println("posts loaded!")
// Construct our author cache
getPostByAuthor(posts).foreach { case (author, posts) =>
cache.set("author-" + author, posts)
}
fPosts.map {
case Left(error) => logger.error(error)
case Right(posts) =>
cache.set("posts", posts)
logger.info("posts loaded!")
// Construct our author cache
getPostByAuthor(posts).foreach { case (author, posts) =>
cache.set("author-" + author, posts)
}

getPostByTag(posts).map { case (tag, posts) =>
cache.set("tag-" + tag.trim, posts)
}
getPostByTag(posts).map { case (tag, posts) =>
cache.set("tag-" + tag.trim, posts)
}
}
Await.result(fPosts, 5 minutes)
}
Expand Down Expand Up @@ -88,10 +90,8 @@ class ApplicationStart @Inject()(
case Nil => map
}

private def getPosts(page: Int = 1): Future[Seq[Post]] = getContents.flatMap {
case Left(e) =>
println(e.getMessage)
Future.successful(Seq.empty)
private def getPosts(page: Int = 1): Future[Either[String, Seq[Post]]] = getContents.flatMap {
case Left(e) => Future.successful(Left(e.getMessage))
// Those are our blog post
case Right(r) =>
// Build our posts
Expand Down Expand Up @@ -142,7 +142,7 @@ class ApplicationStart @Inject()(
posts
}
Future.sequence(posts).map { p =>
p.flatten
Right(p.flatten)
}
}
}
2 changes: 1 addition & 1 deletion conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ githubOrganisation = lunatech-labs
githubOrganisation = ${?github_organisation}
githubRepository = lunatech-blog
githubRepository = ${?github_repository}
githubBranch = master
githubBranch = main
githubBranch = ${?github_branch}
blogBackground = "https://lunatech.cdn.prismic.io/lunatech/c01fd6de48c3cdb8bda7247b0b94b84b14f3a488_kevin-horvat-1354011-unsplash.jpg"
blogBackground = ${?blog_background}
Expand Down
11 changes: 4 additions & 7 deletions test/integration/SmokeTest.scala
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
package integration

import org.scalatestplus.play.PlaySpec
import org.scalatestplus.play.guice.GuiceOneServerPerSuite
import play.api.libs.ws.WSClient
import org.scalatest._
import org.scalatestplus.play._

import play.api.test._
import play.api.test.Helpers.{GET => GET_REQUEST, _}
import play.api.Application
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.libs.ws.WSClient
import play.api.test.Helpers._

class SmokeTest extends PlaySpec with GuiceOneServerPerSuite {

override def fakeApplication(): Application = {
GuiceApplicationBuilder()
.configure(
"accessToken" -> sys.env.get("GITHUB_TOKEN").getOrElse("dummy")
"accessToken" -> sys.env.getOrElse("GITHUB_TOKEN", "dummy")
)
.build()
}
Expand Down