Skip to content

Commit

Permalink
Rebase off main
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherjturner committed Dec 31, 2024
1 parent 54c149f commit 891e055
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task WillProcessAppConfigVersionEvent()
var shutteredUrlsService = Substitute.For<IShutteredUrlsService>();
var enabledUrlsService = Substitute.For<IEnabledVanityUrlsService>();
var eventHandler = new GitHubWorkflowEventHandler(
appConfigVersionService,
appConfigVersionService,
vanityUrlsService,
squidProxyConfigService,
tenantBucketsService,
Expand Down Expand Up @@ -74,7 +74,7 @@ public async Task WillProcessVanityUrlsEvent()
var shutteredUrlsService = Substitute.For<IShutteredUrlsService>();
var enabledUrlsService = Substitute.For<IEnabledVanityUrlsService>();
var eventHandler = new GitHubWorkflowEventHandler(
appConfigVersionService,
appConfigVersionService,
vanityUrlsService,
squidProxyConfigService,
tenantBucketsService,
Expand Down Expand Up @@ -129,7 +129,7 @@ public async Task WillProcessSquidProxyConfigEvent()
var shutteredUrlsService = Substitute.For<IShutteredUrlsService>();
var enabledUrlsService = Substitute.For<IEnabledVanityUrlsService>();
var eventHandler = new GitHubWorkflowEventHandler(
appConfigVersionService,
appConfigVersionService,
vanityUrlsService,
squidProxyConfigService,
tenantBucketsService,
Expand Down Expand Up @@ -158,7 +158,8 @@ public async Task WillProcessSquidProxyConfigEvent()

await squidProxyConfigService.PersistEvent(
Arg.Is<Event<SquidProxyConfigPayload>>(e =>
e.EventType == "squid-proxy-config" && e.Payload.Environment == "test" && e.Payload.Services.Count == 3),
e.EventType == "squid-proxy-config" && e.Payload.Environment == "test" &&
e.Payload.Services.Count == 3),
Arg.Any<CancellationToken>());
await appConfigVersionService.Received(0)
.PersistEvent(Arg.Any<Event<AppConfigVersionPayload>>(), Arg.Any<CancellationToken>());
Expand All @@ -182,7 +183,7 @@ public async Task WillProcessShutteredUrlEvent()
var shutteredUrlsService = Substitute.For<IShutteredUrlsService>();
var enabledUrlsService = Substitute.For<IEnabledVanityUrlsService>();
var eventHandler = new GitHubWorkflowEventHandler(
appConfigVersionService,
appConfigVersionService,
vanityUrlsService,
squidProxyConfigService,
tenantBucketsService,
Expand All @@ -209,7 +210,8 @@ await enabledUrlsService.DidNotReceive()
.PersistEvent(Arg.Any<Event<EnabledVanityUrlsPayload>>(), Arg.Any<CancellationToken>());
}

[Fact] public async Task WillProcessEnabledUrlEvents()
[Fact]
public async Task WillProcessEnabledUrlEvents()
{
var appConfigVersionService = Substitute.For<IAppConfigVersionService>();
var vanityUrlsService = Substitute.For<INginxVanityUrlsService>();
Expand All @@ -219,7 +221,7 @@ [Fact] public async Task WillProcessEnabledUrlEvents()
var shutteredUrlsService = Substitute.For<IShutteredUrlsService>();
var enabledUrlsService = Substitute.For<IEnabledVanityUrlsService>();
var eventHandler = new GitHubWorkflowEventHandler(
appConfigVersionService,
appConfigVersionService,
vanityUrlsService,
squidProxyConfigService,
tenantBucketsService,
Expand Down Expand Up @@ -261,7 +263,7 @@ public async Task WillProcessTenantBucketsEvent()
var shutteredUrlsService = Substitute.For<IShutteredUrlsService>();
var enabledUrlsService = Substitute.For<IEnabledVanityUrlsService>();
var eventHandler = new GitHubWorkflowEventHandler(
appConfigVersionService,
appConfigVersionService,
vanityUrlsService,
squidProxyConfigService,
tenantBucketsService,
Expand Down Expand Up @@ -308,15 +310,15 @@ await tenantBucketsService.PersistEvent(
await appConfigVersionService.Received(0)
.PersistEvent(Arg.Any<Event<AppConfigVersionPayload>>(), Arg.Any<CancellationToken>());
await vanityUrlsService.Received(0)
.PersistEvent(Arg.Any<Event<VanityUrlsPayload>>(), Arg.Any<CancellationToken>());
.PersistEvent(Arg.Any<Event<NginxVanityUrlsPayload>>(), Arg.Any<CancellationToken>());
await squidProxyConfigService.Received(0)
.PersistEvent(Arg.Any<Event<SquidProxyConfigPayload>>(), Arg.Any<CancellationToken>());
await tenantServicesService.Received(0)
.PersistEvent(Arg.Any<Event<TenantServicesPayload>>(), Arg.Any<CancellationToken>());

}
[Fact]

[Fact]
public async Task WillProcessTenantServicesEvent()
{
var appConfigVersionService = Substitute.For<IAppConfigVersionService>();
Expand All @@ -327,7 +329,7 @@ public async Task WillProcessTenantServicesEvent()
var shutteredUrlsService = Substitute.For<IShutteredUrlsService>();
var enabledUrlsService = Substitute.For<IEnabledVanityUrlsService>();
var eventHandler = new GitHubWorkflowEventHandler(
appConfigVersionService,
appConfigVersionService,
vanityUrlsService,
squidProxyConfigService,
tenantBucketsService,
Expand Down Expand Up @@ -368,7 +370,8 @@ public async Task WillProcessTenantServicesEvent()
]
}
}
""";;
""";
;

await eventHandler.Handle(eventType, messageBody, CancellationToken.None);

Expand All @@ -379,45 +382,45 @@ await tenantServicesService.PersistEvent(
await appConfigVersionService.Received(0)
.PersistEvent(Arg.Any<Event<AppConfigVersionPayload>>(), Arg.Any<CancellationToken>());
await vanityUrlsService.Received(0)
.PersistEvent(Arg.Any<Event<VanityUrlsPayload>>(), Arg.Any<CancellationToken>());
.PersistEvent(Arg.Any<Event<NginxVanityUrlsPayload>>(), Arg.Any<CancellationToken>());
await squidProxyConfigService.Received(0)
.PersistEvent(Arg.Any<Event<SquidProxyConfigPayload>>(), Arg.Any<CancellationToken>());
await tenantBucketsService.Received(0)
.PersistEvent(Arg.Any<Event<TenantBucketsPayload>>(), Arg.Any<CancellationToken>());

}

[Fact]
public async Task UnrecognizedGitHubWorkflowEvent()
{
{
var appConfigVersionService = Substitute.For<IAppConfigVersionService>();
var vanityUrlsService = Substitute.For<INginxVanityUrlsService>();
var squidProxyConfigService = Substitute.For<ISquidProxyConfigService>();
var tenantBucketsService = Substitute.For<ITenantBucketsService>();
var tenantServicesService = Substitute.For<ITenantServicesService>();
var shutteredUrlsService = Substitute.For<IShutteredUrlsService>();
var enabledUrlsService = Substitute.For<IEnabledVanityUrlsService>();
var eventHandler = new GitHubWorkflowEventHandler(
appConfigVersionService,
vanityUrlsService,
squidProxyConfigService,
tenantBucketsService,
tenantServicesService,
shutteredUrlsService,
enabledUrlsService,
ConsoleLogger.CreateLogger<GitHubWorkflowEventHandler>());

var eventType = new GitHubWorkflowEventWrapper { EventType = "unrecognized-github-workflow-event" };
var messageBody =
"""
{ "eventType": "unrecognized-github-workflow-event",
"timestamp": "2024-10-23T15:10:10.123",
"payload": {
"environment": "test"
}
}
""";

var appConfigVersionService = Substitute.For<IAppConfigVersionService>();
var vanityUrlsService = Substitute.For<INginxVanityUrlsService>();
var squidProxyConfigService = Substitute.For<ISquidProxyConfigService>();
var tenantBucketsService = Substitute.For<ITenantBucketsService>();
var tenantServicesService = Substitute.For<ITenantServicesService>();
var shutteredUrlsService = Substitute.For<IShutteredUrlsService>();
var enabledUrlsService = Substitute.For<IEnabledVanityUrlsService>();
var eventHandler = new GitHubWorkflowEventHandler(
appConfigVersionService,
vanityUrlsService,
squidProxyConfigService,
tenantBucketsService,
tenantServicesService,
shutteredUrlsService,
enabledUrlsService,
ConsoleLogger.CreateLogger<GitHubWorkflowEventHandler>());

var eventType = new GitHubWorkflowEventWrapper { EventType = "unrecognized-github-workflow-event" };
var messageBody =
"""
{ "eventType": "unrecognized-github-workflow-event",
"timestamp": "2024-10-23T15:10:10.123",
"payload": {
"environment": "test"
}
}
""";

await eventHandler.Handle(eventType, messageBody, CancellationToken.None);

Expand All @@ -426,14 +429,15 @@ await appConfigVersionService.Received(0)
await vanityUrlsService.Received(0)
.PersistEvent(Arg.Any<Event<NginxVanityUrlsPayload>>(), Arg.Any<CancellationToken>());
await squidProxyConfigService.Received(0)
.PersistEvent(Arg.Any<Event<SquidProxyConfigPayload>>(), Arg.Any<CancellationToken>());
.PersistEvent(Arg.Any<Event<SquidProxyConfigPayload>>(), Arg.Any<CancellationToken>());
await tenantBucketsService.Received(0)
.PersistEvent(Arg.Any<Event<TenantBucketsPayload>>(), Arg.Any<CancellationToken>());
.PersistEvent(Arg.Any<Event<TenantBucketsPayload>>(), Arg.Any<CancellationToken>());
await tenantServicesService.Received(0)
.PersistEvent(Arg.Any<Event<TenantServicesPayload>>(), Arg.Any<CancellationToken>());
.PersistEvent(Arg.Any<Event<TenantServicesPayload>>(), Arg.Any<CancellationToken>());
await shutteredUrlsService.DidNotReceive()
.PersistEvent(Arg.Any<Event<ShutteredUrlsPayload>>(), Arg.Any<CancellationToken>());
await enabledUrlsService.DidNotReceive()
.PersistEvent(Arg.Any<Event<EnabledVanityUrlsPayload>>(), Arg.Any<CancellationToken>());


}
}
4 changes: 2 additions & 2 deletions Defra.Cdp.Backend.Api/Endpoints/VanityUrlsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void MapVanityUrlsEndpoint(this IEndpointRouteBuilder app)
}

private static async Task<IResult> ServiceVanityUrlsForEnv(
ITenantUrlService vanityUrlsService,
IVanityUrlService vanityUrlsService,
string service,
string environment,
CancellationToken cancellationToken)
Expand All @@ -25,7 +25,7 @@ private static async Task<IResult> ServiceVanityUrlsForEnv(
}

private static async Task<IResult> ServiceVanityUrls(
ITenantUrlService vanityUrlsService,
IVanityUrlService vanityUrlsService,
string service,
CancellationToken cancellationToken)
{
Expand Down
2 changes: 1 addition & 1 deletion Defra.Cdp.Backend.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
builder.Services.AddSingleton<ITenantServicesService, TenantServicesService>();
builder.Services.AddSingleton<IShutteredUrlsService, ShutteredUrlsService>();
builder.Services.AddSingleton<IEnabledVanityUrlsService, EnabledVanityUrlsService>();
builder.Services.AddSingleton<ITenantUrlService, VanityUrlService>();
builder.Services.AddSingleton<IVanityUrlService, VanityUrlService>();

// Proxy
builder.Services.AddTransient<ProxyHttpMessageHandler>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Defra.Cdp.Backend.Api.Services.GithubWorkflowEvents.Services;

public interface ITenantUrlService
public interface IVanityUrlService
{
Task<List<VanityUrlRecord>> FindAll(CancellationToken cancellationToken);
Task<List<VanityUrlRecord>> FindService(string service, CancellationToken cancellationToken);
Expand All @@ -18,7 +18,7 @@ public interface ITenantUrlService
/**
* Combines data from NginxVanityUrls, EnabledVanityUrls and Shuttering
*/
public class VanityUrlService(IMongoDbClientFactory connectionFactory, ILoggerFactory loggerFactory) : ITenantUrlService
public class VanityUrlService(IMongoDbClientFactory connectionFactory, ILoggerFactory loggerFactory) : IVanityUrlService
{

public async Task<List<VanityUrlRecord>> FindAll(CancellationToken cancellationToken)
Expand Down

0 comments on commit 891e055

Please sign in to comment.