Skip to content

Commit

Permalink
Add test to spot FAPI/CAPI incompatability
Browse files Browse the repository at this point in the history
We're adding a test that will break at build time rather than runtime if
our versions of the FAPI & CAPI clients are incompatible.

See also:

* #25139 (comment)
* https://github.com/guardian/ophan/pull/4719/files#diff-ee7f97c92065084bba37d70d043ad0daa0d7745f235d0ad3206b59f073829529
  • Loading branch information
rtyley committed Jun 30, 2022
1 parent 7830dfc commit 9864128
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions facia-press/test/frontpress/FaciaClientTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package frontpress

import com.gu.contentapi.client.ContentApiClient
import com.gu.contentapi.client.model.SearchQuery
import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
import org.scalatest.{BeforeAndAfterAll, EitherValues}
import org.scalatest.flatspec._
import org.scalatest.matchers.should.Matchers
import org.scalatestplus.mockito.MockitoSugar
import test.{SingleServerSuite, WithMaterializer, WithTestContentApiClient, WithTestWsClient}

class FaciaClientTest extends AsyncFlatSpec with Matchers
with ScalaFutures
with IntegrationPatience
with MockitoSugar
with EitherValues {

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

}

0 comments on commit 9864128

Please sign in to comment.