Skip to content

[PM-34546] Add integration tests for Notifications POST /send endpoint - #8171

Draft
justindbaur wants to merge 1 commit into
mainfrom
add-notifications-post-send-tests
Draft

[PM-34546] Add integration tests for Notifications POST /send endpoint#8171
justindbaur wants to merge 1 commit into
mainfrom
add-notifications-post-send-tests

Conversation

@justindbaur

@justindbaur justindbaur commented Aug 7, 2026

Copy link
Copy Markdown
Member

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-34546

📔 Objective

Adds integration tests for the POST /send endpoint on the Notifications service.

The tests form a three-part contract:

  1. PushAsync_ProducesASupportedPayload — the real NotificationsApiPushEngine must produce a payload matching a format in SupportedPayloads, catching wire-format changes at CI time.
  2. PostSend_RoutesPayloadToCorrectHubGroup — every format in SupportedPayloads is accepted by the live /send endpoint and routed to the correct SignalR hub group.
  3. PushAsync_Notification_RoutesToClientTypeGroup — a PushAsync call with a specific ClientType in the notification payload routes end-to-end to the correct client-type-scoped SignalR group.

SupportedPayloads also serves as the rolling-upgrade compatibility list: old formats are kept for at least one release so that senders on the previous version still work after Notifications is deployed.

Adds PostSendEndpointTests and NotificationsApplicationFactory to
test/Notifications.Test. The tests form a three-part contract:

1. NotificationsApiPushEngine.PushAsync produces a payload that matches
   a format in SupportedPayloads, catching wire-format changes at CI time.
2. Every format in SupportedPayloads is accepted by the live /send
   endpoint and routed to the correct SignalR hub group.
3. PushAsync calls with a specific ClientType in the notification payload
   route to the correct client-type-scoped group.

SupportedPayloads also serves as the rolling-upgrade compatibility list:
old formats are kept for at least one release so that senders on the
previous version still work after Notifications is updated.
@justindbaur justindbaur changed the title Add integration tests for Notifications POST /send endpoint [PM-34546] test: add integration tests for Notifications POST /send endpoint Aug 7, 2026
@justindbaur justindbaur added the t:tech-debt Change Type - Tech debt label Aug 7, 2026
@justindbaur justindbaur changed the title [PM-34546] test: add integration tests for Notifications POST /send endpoint [PM-34546] Add integration tests for Notifications POST /send endpoint Aug 7, 2026
NotificationsHubClients = notificationsClients;
var (anonymousHubContext, _) = BuildHubContext<AnonymousNotificationsHub>();

_notificationsFactory = new WebApplicationFactory<Bit.Notifications.Program>().WithWebHostBuilder(builder =>
Comment on lines +119 to +126
var response = await client.PostAsync("/connect/token", new FormUrlEncodedContent(
new Dictionary<string, string>
{
{ "grant_type", "client_credentials" },
{ "client_id", "internal.notifications" },
{ "client_secret", InternalIdentityKey },
{ "scope", "internal" },
}));
{
using var client = await _factory.CreateAuthenticatedClientAsync();
using var response = await client.PostAsync("/send",
new StringContent(json, Encoding.UTF8, "application/json"));

using var client = await _factory.CreateAuthenticatedClientAsync();
using var response = await client.PostAsync("/send",
new StringContent(captured, Encoding.UTF8, "application/json"));
const string notificationsBase = "http://localhost/";
const string identityBase = "http://localhost/";

var mockClient = new MockHttpMessageHandler();
const string identityBase = "http://localhost/";

var mockClient = new MockHttpMessageHandler();
var mockIdentityClient = new MockHttpMessageHandler();
var mockIdentityClient = new MockHttpMessageHandler();

var httpClientFactory = Substitute.For<IHttpClientFactory>();
httpClientFactory.CreateClient("client").Returns(new HttpClient(mockClient));

var httpClientFactory = Substitute.For<IHttpClientFactory>();
httpClientFactory.CreateClient("client").Returns(new HttpClient(mockClient));
httpClientFactory.CreateClient("identity").Returns(new HttpClient(mockIdentityClient));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t:tech-debt Change Type - Tech debt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant