[PM-34546] Add integration tests for Notifications POST /send endpoint - #8171
Draft
justindbaur wants to merge 1 commit into
Draft
[PM-34546] Add integration tests for Notifications POST /send endpoint#8171justindbaur wants to merge 1 commit into
justindbaur wants to merge 1 commit into
Conversation
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.
| 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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-34546
📔 Objective
Adds integration tests for the
POST /sendendpoint on the Notifications service.The tests form a three-part contract:
PushAsync_ProducesASupportedPayload— the realNotificationsApiPushEnginemust produce a payload matching a format inSupportedPayloads, catching wire-format changes at CI time.PostSend_RoutesPayloadToCorrectHubGroup— every format inSupportedPayloadsis accepted by the live/sendendpoint and routed to the correct SignalR hub group.PushAsync_Notification_RoutesToClientTypeGroup— aPushAsynccall with a specificClientTypein the notification payload routes end-to-end to the correct client-type-scoped SignalR group.SupportedPayloadsalso 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.