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

Update CAPI & FAPI clients to latest versions (also remove hack required for Lightbox) #25139

Merged
merged 1 commit into from
Jul 1, 2022
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
20 changes: 6 additions & 14 deletions applications/app/controllers/ImageContentController.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package controllers

import com.gu.contentapi.client.Parameter
import com.gu.contentapi.client.model.SearchQueryBase
import com.gu.contentapi.client.model.{Direction, FollowingSearchQuery, SearchQuery, SearchQueryBase}
import com.gu.contentapi.client.model.v1.{ItemResponse, Content => ApiContent}
import common._
import conf.switches.Switches
Expand Down Expand Up @@ -53,11 +52,11 @@ class ImageContentController(

def getNextLightboxJson(path: String, tag: String, direction: String): Action[AnyContent] =
Action.async { implicit request =>
val capiQuery: ContentApiNavQuery = ContentApiNavQuery(currentId = path, direction = direction)
.tag(tag)
.showTags("all")
.showElements("image")
.pageSize(contentApi.nextPreviousPageSize)
val capiQuery = FollowingSearchQuery(
SearchQuery().tag(tag).showTags("all").showElements("image").pageSize(contentApi.nextPreviousPageSize),
path,
Direction.forPathSegment(direction),
)

contentApiClient.thriftClient.getResponse(capiQuery).map { response =>
val lightboxJson = response.results.flatMap(result =>
Expand All @@ -70,10 +69,3 @@ class ImageContentController(
}
}
}

case class ContentApiNavQuery(parameterHolder: Map[String, Parameter] = Map.empty, currentId: String, direction: String)
extends SearchQueryBase[ContentApiNavQuery] {
def withParameters(parameterMap: Map[String, Parameter]): ContentApiNavQuery = copy(parameterMap)

override def pathSegment: String = s"content/$currentId/$direction"
}
31 changes: 31 additions & 0 deletions facia-press/test/frontpress/FaciaClientTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package frontpress

import com.gu.contentapi.client.ContentApiClient
import com.gu.contentapi.client.model.SearchQuery
import org.scalatest.flatspec._
import org.scalatest.matchers.should.Matchers
import org.scalatestplus.mockito.MockitoSugar

class FaciaClientTest extends AsyncFlatSpec with Matchers with MockitoSugar {

"FAPI Client" should "send a CAPI client request without a runtime error like java.lang.NoSuchMethodError" in {
// The FAPI client uses the Content API client. If this test fails with a java.lang.NoSuchMethodError, the
// versions of FAPI client and CAPI client we are using are incompatible - the FAPI client will have been
// compiled against a different version of the CAPI client.

val mockContentApiClient = mock[ContentApiClient]

// This is only exercising the code to send the request, not recieve the result, but it's enough to trigger the
// java.lang.NoSuchMethodError seen in https://github.com/guardian/frontend/pull/25139#issuecomment-1163407402
noException shouldBe thrownBy(
com.gu.facia.api.contentapi.ContentApi.getHydrateResponse(
mockContentApiClient,
Seq(
SearchQuery().tag("profile/roberto-tyley"),
SearchQuery().tag("stage/comedy"),
),
),
)
}

}
4 changes: 2 additions & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import sbt._
object Dependencies {
val identityLibVersion = "3.254"
val awsVersion = "1.12.205"
val capiVersion = "18.0.1"
val faciaVersion = "3.3.12"
val capiVersion = "19.0.0"
val faciaVersion = "4.0.0"
val dispatchVersion = "0.13.1"
val romeVersion = "1.0"
val jerseyVersion = "1.19.4"
Expand Down