Skip to content

Commit 7b489aa

Browse files
authored
APSR-1931 - Update to also check the APIs categories for fraud prevention info (#521)
1 parent 3aaff8d commit 7b489aa

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

app/uk/gov/hmrc/apidocumentation/controllers/ApiDocumentationController.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class ApiDocumentationController @Inject() (
246246
} yield Ok(parentPage(attrs, markdownBlocks, api.name, api, selectedVersion, developerId.isDefined, useV2 = useV2)).withHeaders(cacheControlHeaders)
247247
}
248248

249-
val categories = APICategoryFilters.categoryMap.getOrElse(api.name, Seq.empty)
249+
val categories = APICategoryFilters.categoryMap.getOrElse(api.name, Seq.empty) ++ api.categories
250250
documentationService.fetchApiSpecification(service, version, cacheBuster).flatMap(_.fold(renderOas(categories))(renderRamlSpec))
251251
}
252252

resources/categories.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
"Individual Benefits": ["SELF_ASSESSMENT"],
1717
"Individual Employment": ["SELF_ASSESSMENT"],
1818
"Individual Income": ["SELF_ASSESSMENT"],
19-
"Individual Losses (MTD)": ["INCOME_TAX_MTD"],
20-
"Individual Calculations (MTD)": ["INCOME_TAX_MTD"],
19+
2120
"Individual PAYE": ["PAYE", "SELF_ASSESSMENT"],
2221
"Individual Tax": ["SELF_ASSESSMENT"],
2322
"Individuals": ["PRIVATE_GOVERNMENT"],

test/uk/gov/hmrc/apidocumentation/controllers/ApiDocumentationControllerSpec.scala

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import org.apache.pekko.stream.Materializer
2525
import play.api.http.Status.{INTERNAL_SERVER_ERROR, NOT_FOUND, OK, SEE_OTHER}
2626
import play.api.mvc.MessagesControllerComponents
2727
import play.api.test.Helpers._
28+
import uk.gov.hmrc.apiplatform.modules.apis.domain.models.ApiCategory.VAT_MTD
2829
import uk.gov.hmrc.apiplatform.modules.apis.domain.models._
2930
import uk.gov.hmrc.apiplatform.modules.common.domain.models._
3031
import uk.gov.hmrc.http.NotFoundException
@@ -472,7 +473,7 @@ class ApiDocumentationControllerSpec extends CommonControllerBaseSpec with PageR
472473
verifyNotFoundPageRendered(result)
473474
}
474475

475-
"display the OAS when no RAML is found including fraud prevention information" in new Setup {
476+
"display the OAS when no RAML is found including fraud prevention information using info from Cat Map" in new Setup {
476477
theUserIsLoggedIn()
477478

478479
theDefinitionServiceWillReturnAnApiDefinition(
@@ -489,6 +490,23 @@ class ApiDocumentationControllerSpec extends CommonControllerBaseSpec with PageR
489490
contentAsString(result) should include("Fraud Prevention")
490491
}
491492

493+
"display the OAS when no RAML is found including fraud prevention information using info from Api" in new Setup {
494+
theUserIsLoggedIn()
495+
496+
theDefinitionServiceWillReturnAnApiDefinition(
497+
extendedApiDefinition(serviceName = serviceName.value).copy(categories = List(VAT_MTD))
498+
)
499+
500+
theDocumentationServiceWillFetchNoSpecification()
501+
when(downloadConnector.fetch(*[ServiceName], *[ApiVersionNbr], *)).thenReturn(successful(None))
502+
503+
val result = underTest.renderApiDocumentation(serviceName, versionOne, Option(true), None)(request)
504+
505+
status(result) shouldBe OK
506+
contentAsString(result) should include("Endpoints")
507+
contentAsString(result) should include("Fraud Prevention")
508+
}
509+
492510
"render OAS for a test support API without including fraud prevention information" in new Setup {
493511
theUserIsLoggedIn()
494512

@@ -506,6 +524,24 @@ class ApiDocumentationControllerSpec extends CommonControllerBaseSpec with PageR
506524
contentAsString(result) should include("Endpoints")
507525
contentAsString(result) should not include ("Fraud Prevention")
508526
}
527+
528+
"display the OAS when no RAML is found not including fraud prevention information" in new Setup {
529+
theUserIsLoggedIn()
530+
531+
theDefinitionServiceWillReturnAnApiDefinition(
532+
extendedApiDefinition(serviceName = serviceName.value)
533+
)
534+
535+
theDocumentationServiceWillFetchNoSpecification()
536+
when(downloadConnector.fetch(*[ServiceName], *[ApiVersionNbr], *)).thenReturn(successful(None))
537+
538+
val result = underTest.renderApiDocumentation(serviceName, versionOne, Option(true), None)(request)
539+
540+
status(result) shouldBe OK
541+
println(contentAsString(result))
542+
contentAsString(result) should include("Endpoints")
543+
contentAsString(result) should not include ("Fraud Prevention")
544+
}
509545
}
510546

511547
"display the not found page when invalid service specified" in new Setup {

0 commit comments

Comments
 (0)