Skip to content

Commit

Permalink
HIPP-1810: Remove OAS title validation (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
victorarbuesmallada authored Jan 7, 2025
1 parent b326d93 commit 49aec28
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 36 deletions.
3 changes: 1 addition & 2 deletions app/connectors/ApplicationsConnector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,8 @@ class ApplicationsConnector @Inject()(
.execute[ApisInProductionStatistic]
}

def validateOAS(oas: String, validateTitle: Boolean = false)
def validateOAS(oas: String)
(implicit hc: HeaderCarrier, messagesProvider: MessagesProvider): Future[Either[InvalidOasResponse, Unit]] = httpClient.post(url"$applicationsBaseUrl/api-hub-applications/oas/validate")
.transform(request => request.withQueryStringParameters("validateTitle" -> validateTitle.toString))
.setHeader(ACCEPT -> JSON)
.setHeader(CONTENT_TYPE -> "text/plain")
.setHeader(AUTHORIZATION -> clientAuthToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class ProduceApiEnterOasController @Inject()(

private def validateOAS(oas: String)(implicit messagesProvider: MessagesProvider, hc: HeaderCarrier): Future[Either[String, String]] = {
(for {
_ <- EitherT(applicationsConnector.validateOAS(oas, true)).leftMap(error => Json.prettyPrint(Json.toJson(error)))
_ <- EitherT(applicationsConnector.validateOAS(oas)).leftMap(error => Json.prettyPrint(Json.toJson(error)))
openApiDoc <- EitherT.fromEither(OpenApiDoc.parse(oas))
apiName <- EitherT.fromOption(openApiDoc.getApiName(), Messages("produceApiEnterOas.error.missingApiName"))
} yield apiName).value
Expand Down
26 changes: 3 additions & 23 deletions it/test/connectors/ApplicationsConnectorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1837,10 +1837,9 @@ class ApplicationsConnectorSpec
}

"validateOas" - {
"must place the correct request and return success and not validate the oas title" in {
"must place the correct request and return success" in {
val oas = "some oas"
val validateTitle = false
val value1 = s"/api-hub-applications/oas/validate?validateTitle=$validateTitle"
val value1 = s"/api-hub-applications/oas/validate"
Console.println(s"OIYAF! $value1")
stubFor(
post(urlEqualTo(value1))
Expand All @@ -1852,26 +1851,7 @@ class ApplicationsConnectorSpec
)
)

buildConnector(this).validateOAS(oas, validateTitle)(HeaderCarrier()).map {
result =>
result.value mustBe()
}
}

"must place the correct request and return success and validate the oas title" in {
val oas = "some oas"
val validateTitle = true
stubFor(
post(urlEqualTo(s"/api-hub-applications/oas/validate?validateTitle=$validateTitle"))
.withHeader(AUTHORIZATION, equalTo("An authentication token"))
.withHeader(ACCEPT, equalTo("application/json"))
.withRequestBody(equalTo(oas))
.willReturn(
aResponse()
)
)

buildConnector(this).validateOAS(oas, validateTitle)(HeaderCarrier()).map {
buildConnector(this).validateOAS(oas)(HeaderCarrier()).map {
result =>
result.value mustBe()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class ProduceApiEnterOasControllerSpec extends SpecBase with MockitoSugar {
"must redirect to the next page when valid data is submitted" in {
val fixture = buildFixture(userAnswers = Some(emptyUserAnswers))
when(fixture.sessionRepository.set(any())).thenReturn(Future.successful(true))
when(fixture.applicationsConnector.validateOAS(eqTo(validOAS), eqTo(true))(any, any))
when(fixture.applicationsConnector.validateOAS(eqTo(validOAS))(any, any))
.thenReturn(Future.successful(Right(())))

running(fixture.application) {
Expand All @@ -139,7 +139,7 @@ class ProduceApiEnterOasControllerSpec extends SpecBase with MockitoSugar {
val errorMessage = "Unable to parse the OAS document, errorMessage"
val invalidResponse = InvalidOasResponse(FailuresResponse("400", errorMessage, None))
val fixture = buildFixture(userAnswers = Some(emptyUserAnswers))
when(fixture.applicationsConnector.validateOAS(eqTo(invalidOAS), eqTo(true))(any, any))
when(fixture.applicationsConnector.validateOAS(eqTo(invalidOAS))(any, any))
.thenReturn(Future.successful(Left(
invalidResponse
)))
Expand Down Expand Up @@ -196,7 +196,7 @@ class ProduceApiEnterOasControllerSpec extends SpecBase with MockitoSugar {
val userAnswers = emptyUserAnswers.set(ProduceApiUploadOasPage, oasModel).success.value
val fixture = buildFixture(userAnswers = Some(userAnswers))

when(fixture.applicationsConnector.validateOAS(eqTo(oasModel.fileContents), eqTo(true))(any, any))
when(fixture.applicationsConnector.validateOAS(eqTo(oasModel.fileContents))(any, any))
.thenReturn(Future.successful(Right(())))

running(fixture.application) {
Expand All @@ -220,7 +220,7 @@ class ProduceApiEnterOasControllerSpec extends SpecBase with MockitoSugar {

val fixture = buildFixture(userAnswers = Some(userAnswers))

when(fixture.applicationsConnector.validateOAS(eqTo(validOASEdited), eqTo(true))(any, any))
when(fixture.applicationsConnector.validateOAS(eqTo(validOASEdited))(any, any))
.thenReturn(Future.successful(Right(())))

running(fixture.application) {
Expand All @@ -241,7 +241,7 @@ class ProduceApiEnterOasControllerSpec extends SpecBase with MockitoSugar {
val fixture = buildFixture(userAnswers = Some(userAnswers))
val invalidResponse = InvalidOasResponse(FailuresResponse("400", "nope", None))

when(fixture.applicationsConnector.validateOAS(any(), eqTo(true))(any, any)).thenReturn(Future.successful(Left(invalidResponse)))
when(fixture.applicationsConnector.validateOAS(any())(any, any)).thenReturn(Future.successful(Left(invalidResponse)))

running(fixture.application) {
val request = FakeRequest(GET, controllers.myapis.produce.routes.ProduceApiEnterOasController.onPageLoadWithUploadedOas(NormalMode).url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class UpdateApiEnterOasControllerSpec extends SpecBase with MockitoSugar {
"must redirect to the next page when valid data is submitted" in {
val fixture = buildFixture(userAnswers = Some(emptyUserAnswers))
when(fixture.sessionRepository.set(any())).thenReturn(Future.successful(true))
when(fixture.applicationsConnector.validateOAS(eqTo(validOAS), eqTo(false))(any, any))
when(fixture.applicationsConnector.validateOAS(eqTo(validOAS))(any, any))
.thenReturn(Future.successful(Right(())))

running(fixture.application) {
Expand All @@ -141,7 +141,7 @@ class UpdateApiEnterOasControllerSpec extends SpecBase with MockitoSugar {
val errorMessage = "Unable to parse the OAS document, errorMessage"
val invalidResponse = InvalidOasResponse(FailuresResponse("400", errorMessage, None))
val fixture = buildFixture(userAnswers = Some(emptyUserAnswers))
when(fixture.applicationsConnector.validateOAS(eqTo(invalidOAS), eqTo(false))(any, any))
when(fixture.applicationsConnector.validateOAS(eqTo(invalidOAS))(any, any))
.thenReturn(Future.successful(Left(
invalidResponse
)))
Expand Down Expand Up @@ -198,7 +198,7 @@ class UpdateApiEnterOasControllerSpec extends SpecBase with MockitoSugar {
val userAnswers = emptyUserAnswers.set(UpdateApiUploadOasPage, oasModel).success.value
val fixture = buildFixture(userAnswers = Some(userAnswers))

when(fixture.applicationsConnector.validateOAS(eqTo(oasModel.fileContents), eqTo(false))(any, any))
when(fixture.applicationsConnector.validateOAS(eqTo(oasModel.fileContents))(any, any))
.thenReturn(Future.successful(Right(())))

running(fixture.application) {
Expand All @@ -222,7 +222,7 @@ class UpdateApiEnterOasControllerSpec extends SpecBase with MockitoSugar {

val fixture = buildFixture(userAnswers = Some(userAnswers))

when(fixture.applicationsConnector.validateOAS(eqTo(validOASEdited), eqTo(false))(any, any))
when(fixture.applicationsConnector.validateOAS(eqTo(validOASEdited))(any, any))
.thenReturn(Future.successful(Right(())))

running(fixture.application) {
Expand All @@ -243,7 +243,7 @@ class UpdateApiEnterOasControllerSpec extends SpecBase with MockitoSugar {
val fixture = buildFixture(userAnswers = Some(userAnswers))
val invalidResponse = InvalidOasResponse(FailuresResponse("400", "nope", None))

when(fixture.applicationsConnector.validateOAS(any(), any())(any, any)).thenReturn(Future.successful(Left(invalidResponse)))
when(fixture.applicationsConnector.validateOAS(any())(any, any)).thenReturn(Future.successful(Left(invalidResponse)))

running(fixture.application) {
val request = FakeRequest(GET, controllers.myapis.update.routes.UpdateApiEnterOasController.onPageLoadWithUploadedOas(NormalMode).url)
Expand Down

0 comments on commit 49aec28

Please sign in to comment.