|
| 1 | +package code.api.util |
| 2 | + |
| 3 | +import code.setup.ServerSetup |
| 4 | +import org.scalatest.Tag |
| 5 | + |
| 6 | +/** |
| 7 | + * Guards the invariant that APIUtil.getAllResourceDocs — the global operation-id |
| 8 | + * registry used wherever an operation id must be resolved (api-collection endpoint |
| 9 | + * validation, top-apis operation-id lookups, ...) — contains every per-standard |
| 10 | + * resource-doc surface the resource-docs dispatcher can serve to API Explorer. |
| 11 | + * |
| 12 | + * These are two parallel registries (ResourceDocsAPIMethods dispatches per |
| 13 | + * standard/version; getAllResourceDocs aggregates them all), and they have drifted |
| 14 | + * twice: Berlin Group v2 was served by the dispatcher but missing from the global |
| 15 | + * registry (so BGv2-getAccountDetails could not be added to an API collection), |
| 16 | + * and the global registry was based on the v6 aggregation, excluding v7-only |
| 17 | + * operation ids. When you add a NEW API standard, register its docs in BOTH |
| 18 | + * places — and add its surface to this list. |
| 19 | + */ |
| 20 | +class ResourceDocRegistryParityTest extends ServerSetup { |
| 21 | + |
| 22 | + object RegistryParityTag extends Tag("ResourceDocRegistryParity") |
| 23 | + |
| 24 | + private lazy val allOperationIds: Set[String] = |
| 25 | + APIUtil.getAllResourceDocs.map(_.operationId).toSet |
| 26 | + |
| 27 | + private lazy val surfaces: List[(String, Seq[String])] = List( |
| 28 | + ("OBP standard (v7 aggregation)", code.api.v7_0_0.Http4s700.allResourceDocs.map(_.operationId).toSeq), |
| 29 | + ("Berlin Group v1.3", code.api.berlin.group.v1_3.Http4sBGv13.resourceDocs.map(_.operationId).toSeq), |
| 30 | + ("Berlin Group v2", code.api.berlin.group.v2.Http4sBGv2.resourceDocs.map(_.operationId).toSeq), |
| 31 | + ("UK Open Banking 2.0.0", code.api.UKOpenBanking.v2_0_0.OBP_UKOpenBanking_200.allResourceDocs.map(_.operationId).toSeq), |
| 32 | + ("UK Open Banking 3.1.0", code.api.UKOpenBanking.v3_1_0.OBP_UKOpenBanking_310.allResourceDocs.map(_.operationId).toSeq), |
| 33 | + ("UK Open Banking 4.0.1", code.api.UKOpenBanking.v4_0_1.OBP_UKOpenBanking_401.allResourceDocs.map(_.operationId).toSeq) |
| 34 | + ) |
| 35 | + |
| 36 | + feature("getAllResourceDocs contains every per-standard resource-doc surface") { |
| 37 | + surfaces.foreach { case (label, operationIds) => |
| 38 | + scenario(s"$label operation ids are all resolvable globally", RegistryParityTag) { |
| 39 | + operationIds should not be empty |
| 40 | + val missing = operationIds.filterNot(allOperationIds.contains) |
| 41 | + withClue(s"$label operation ids missing from getAllResourceDocs: ${missing.take(10).mkString(", ")} ") { |
| 42 | + missing shouldBe empty |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + scenario("the operation id from the sandbox bug report resolves", RegistryParityTag) { |
| 48 | + allOperationIds should contain("BGv2-getAccountDetails") |
| 49 | + } |
| 50 | + } |
| 51 | +} |
0 commit comments