From 84edf5a134e8fcefdbede4f1c4beb8f0138f16db Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Sat, 6 Jun 2026 12:00:42 -0400 Subject: [PATCH] test(e2e): add ApiSurfaceFixture (inbound api-method for API-key form checkboxes) --- .../Admin/ApiSurfaceFixture.cs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests/Admin/ApiSurfaceFixture.cs diff --git a/tests/ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests/Admin/ApiSurfaceFixture.cs b/tests/ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests/Admin/ApiSurfaceFixture.cs new file mode 100644 index 00000000..c6e291be --- /dev/null +++ b/tests/ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests/Admin/ApiSurfaceFixture.cs @@ -0,0 +1,44 @@ +using ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests.Cluster; + +namespace ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests.Admin; + +/// +/// Provisions a single inbound API method so the API-key form renders at least one method checkbox +/// (id="method-access-{MethodId}"). Created API keys are deleted per-test; this fixture owns +/// only the method. +/// +public sealed class ApiSurfaceFixture : IAsyncLifetime +{ + public int MethodId { get; private set; } + public string MethodName { get; private set; } = string.Empty; + public bool Available { get; private set; } + + public async Task InitializeAsync() + { + Available = await ClusterAvailability.IsAvailableAsync(); + if (!Available) + { + return; + } + + try + { + MethodName = CliRunner.UniqueName("method"); + MethodId = await CliRunner.CreateApiMethodAsync(MethodName); + } + catch + { + await CliRunner.DeleteApiMethodAsync(MethodId); + Available = false; + throw; + } + } + + public async Task DisposeAsync() + { + if (Available) + { + await CliRunner.DeleteApiMethodAsync(MethodId); + } + } +}