| 1 | using System.Net.Http.Json; |
| 2 | using System.Text.Json; |
| 3 | |
| 4 | namespace AgentForge.Tests; |
| 5 | |
| 6 | public sealed class ForgeViewContributorTests(ForgeWebApplicationFactory factory) : IClassFixture<ForgeWebApplicationFactory> |
| 7 | { |
| 8 | private static readonly JsonSerializerOptions JsonOptions = new() { PropertyNameCaseInsensitive = true }; |
| 9 | |
| 10 | [Fact] |
| 11 | public async Task Capabilities_lists_view_contributors_from_issues_plugin() |
| 12 | { |
| 13 | var response = await factory.CreateClient().GetAsync("/api/v1/capabilities"); |
| 14 | response.EnsureSuccessStatusCode(); |
| 15 | |
| 16 | var caps = await response.Content.ReadFromJsonAsync<JsonElement>(JsonOptions); |
| 17 | var contributors = caps.GetProperty("viewContributors").EnumerateArray().ToList(); |
| 18 | Assert.Equal(2, contributors.Count); |
| 19 | |
| 20 | var issues = contributors.Single(c => c.GetProperty("tabId").GetString() == "issues"); |
| 21 | Assert.Equal("Issues", issues.GetProperty("label").GetString()); |
| 22 | Assert.Equal("issue", issues.GetProperty("pluginId").GetString()); |
| 23 | Assert.Equal("/view/repos/{name}/issues", issues.GetProperty("routePrefix").GetString()); |
| 24 | } |
| 25 | |
| 26 | [Fact] |
| 27 | public async Task Minimal_bundle_has_no_view_contributors() |
| 28 | { |
| 29 | await using var localFactory = new ForgeWebApplicationFactory { PluginBundle = "minimal" }; |
| 30 | var response = await localFactory.CreateClient().GetAsync("/api/v1/capabilities"); |
| 31 | response.EnsureSuccessStatusCode(); |
| 32 | |
| 33 | var caps = await response.Content.ReadFromJsonAsync<JsonElement>(JsonOptions); |
| 34 | Assert.Empty(caps.GetProperty("viewContributors").EnumerateArray()); |
| 35 | } |
| 36 | |
| 37 | [Fact] |
| 38 | public async Task Issue_view_route_returns_not_found_when_issue_missing() |
| 39 | { |
| 40 | var client = factory.CreateClient(); |
| 41 | var response = await client.GetAsync("/view/repos/missing/issues/1"); |
| 42 | Assert.Equal(System.Net.HttpStatusCode.NotFound, response.StatusCode); |
| 43 | } |
| 44 | } |
| 45 | |