-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Queueing of external events for new messages while relationship is in…
… status `Terminated` (#912) * feat: allow sending messages in status Terminated * refactor: remove reference to Newtonsoft.Json from ConsumerApi.Sdk * chore: delete leftover packages.lock.json file * refactor: rename RelationshipReactivationRequest method to ReactivateRelationship * refactor: fix typo in ExternalEventIdPayloadEntityFrameworkValueConverter * refactor: make external event payloads strongly typed * refactor: add empty constructor to each ExternalEvent subclass to satisfy ArchUnit tests * chore: fix formatting * feat: modify setup.sql scripts to allow synchronization user access to Relationships schema * test: add integration tests * test: add more integration tests * feat: add RelationshipId to message recipient * feat: propagate RelationshipId via DomainEvent * feat: add migrations for adding the IsDeliveryBlocked and Context columns to the ExternalEvents table * test: delete unused BaseStepDefinitions * test: fix reactivation by accepting as peer * feat: send NewRelationshipStatus as part of RelationshipReactivationCompletedDomainEvent * feat: update entity type configurations * feat: update MessageCreatedDomainEventHandler to block external events if the relationship is terminated * feat: unblock external events after relationship was reactivated * chore: remove todo list * test: remove Task.Delay * chore: add explaining comments to custom SQL in migrations * test: fix test * refactor: extract deletion of external events to method in dbcontext * test: fix tests * test: add some Task.Delays to avoid failing tests * fix: use correct type param for logger * test: add tests for MessageCreatedDomainEventHandler * chore: remove reactivation part from error message * test: add tests for RelationshipReactivationCompletedDomainEventHandler * test: add tests for RelationshipStatusChangedDomainEventHandler * test: add tests for Relationship * chore: rename ImplicitUsings to GlobalUsings to better reflect what they contain * test: inherit from AbstractTestsBase * chore: fix formatting * feat: don't send a push notification for blocked external events --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
a6ca655
commit f3dbf61
Showing
76 changed files
with
2,188 additions
and
575 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
45 changes: 45 additions & 0 deletions
45
...rApi/test/ConsumerApi.Tests.Integration/Features/SyncRuns/{id}/ExternalEvents/GET.feature
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
@Integration | ||
Feature: GET /SyncRuns/{id}/ExternalEvents | ||
|
||
Scenario: Getting external events does not return events for messages sent while the Relationship is still terminated | ||
Given Identities i1 and i2 | ||
And a terminated Relationship r between i1 and i2 | ||
And i1 has sent a Message m to i2 | ||
And a sync run sr started by i2 | ||
When i2 sends a GET request to the /SyncRuns/sr.id/ExternalEvents endpoint | ||
Then the response status code is 200 (OK) | ||
And the response does not contain an external event for the Message m | ||
|
||
Scenario: Getting external events returns events for messages sent while the Relationship was terminated | ||
Given Identities i1 and i2 | ||
And a terminated Relationship r between i1 and i2 | ||
And i1 has sent a Message m to i2 | ||
And r was fully reactivated | ||
And 1 second(s) have passed | ||
And a sync run sr started by i2 | ||
When i2 sends a GET request to the /SyncRuns/sr.id/ExternalEvents endpoint | ||
Then the response status code is 200 (OK) | ||
Then the response contains an external event for the Message m | ||
|
||
Scenario: Getting external events returns events for messages sent before the Relationship was terminated | ||
Given Identities i1 and i2 | ||
And an active Relationship r between i1 and i2 | ||
And i1 has sent a Message m to i2 | ||
And i1 has terminated r | ||
And a sync run sr started by i2 | ||
When i2 sends a GET request to the /SyncRuns/sr.id/ExternalEvents endpoint | ||
Then the response status code is 200 (OK) | ||
Then the response contains an external event for the Message m | ||
|
||
Scenario: Getting external events does not return events for messages that were sent with an old Relationship | ||
Given Identities i1 and i2 | ||
And an active Relationship r between i1 and i2 | ||
And i1 has sent a Message m to i2 | ||
And i1 has terminated r | ||
And i1 has decomposed r | ||
And i2 has decomposed r | ||
And an active Relationship r between i1 and i2 | ||
And a sync run sr started by i2 | ||
When i2 sends a GET request to the /SyncRuns/sr.id/ExternalEvents endpoint | ||
Then the response status code is 200 (OK) | ||
Then the response does not contain an external event for the Message m |
This file contains 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
39 changes: 0 additions & 39 deletions
39
...ons/ConsumerApi/test/ConsumerApi.Tests.Integration/StepDefinitions/BaseStepDefinitions.cs
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
...s/ConsumerApi/test/ConsumerApi.Tests.Integration/StepDefinitions/CommonStepDefinitions.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using FluentAssertions.Extensions; | ||
|
||
namespace Backbone.ConsumerApi.Tests.Integration.StepDefinitions; | ||
|
||
[Binding] | ||
internal class CommonStepDefinitions | ||
{ | ||
#region Given | ||
|
||
[Given(@"(\d+) second\(s\) have passed")] | ||
public async Task GivenXSecondsHavePassed(int numberOfSeconds) | ||
{ | ||
await Task.Delay(numberOfSeconds.Seconds()); | ||
} | ||
|
||
#endregion | ||
} |
This file contains 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
73 changes: 73 additions & 0 deletions
73
...rApi/test/ConsumerApi.Tests.Integration/StepDefinitions/SynchronizationStepDefinitions.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using Backbone.BuildingBlocks.SDK.Endpoints.Common.Types; | ||
using Backbone.ConsumerApi.Sdk.Endpoints.SyncRuns.Types.Requests; | ||
using Backbone.ConsumerApi.Sdk.Endpoints.SyncRuns.Types.Responses; | ||
using Backbone.ConsumerApi.Tests.Integration.Contexts; | ||
using Backbone.ConsumerApi.Tests.Integration.Helpers; | ||
|
||
namespace Backbone.ConsumerApi.Tests.Integration.StepDefinitions; | ||
|
||
[Binding] | ||
internal class SynchronizationStepDefinitions | ||
{ | ||
private readonly ClientPool _clientPool; | ||
private readonly Dictionary<string, StartSyncRunResponse> _startSyncRunResponses = new(); | ||
private readonly ResponseContext _responseContext; | ||
private readonly MessagesContext _messagesContext; | ||
private ApiResponse<ListExternalEventsResponse>? _listExternalEventsOfSyncRunResponse; | ||
|
||
public SynchronizationStepDefinitions(ResponseContext responseContext, MessagesContext messagesContext, ClientPool clientPool) | ||
{ | ||
_responseContext = responseContext; | ||
_messagesContext = messagesContext; | ||
_clientPool = clientPool; | ||
} | ||
|
||
#region Given | ||
|
||
[Given($"a sync run {RegexFor.SINGLE_THING} started by {RegexFor.SINGLE_THING}")] | ||
public async Task GivenASyncRunStartedBy(string syncRunName, string identityName) | ||
{ | ||
var client = _clientPool.FirstForIdentityName(identityName); | ||
|
||
var startSyncRunResponse = await client.SyncRuns.StartSyncRun(new StartSyncRunRequest { Type = SyncRunType.ExternalEventSync }, 1); | ||
|
||
_startSyncRunResponses.Add(syncRunName, startSyncRunResponse.Result!); | ||
} | ||
|
||
#endregion | ||
|
||
#region When | ||
|
||
[When($"{RegexFor.SINGLE_THING} sends a GET request to the /SyncRuns/{RegexFor.SINGLE_THING}.id/ExternalEvents endpoint")] | ||
public async Task WhenISendsAGETRequestToTheSyncRunsSrIdExternalEventsEndpoint(string identityName, string syncRunName) | ||
{ | ||
var client = _clientPool.FirstForIdentityName(identityName); | ||
|
||
var syncRunId = _startSyncRunResponses[syncRunName].SyncRun.Id; | ||
|
||
_responseContext.WhenResponse = _listExternalEventsOfSyncRunResponse = await client.SyncRuns.ListExternalEventsOfSyncRun(syncRunId); | ||
} | ||
|
||
#endregion | ||
|
||
#region Then | ||
|
||
[Then($"the response does not contain an external event for the Message {RegexFor.SINGLE_THING}")] | ||
public void ThenTheResponseDoesNotContainAnExternalEventForM(string _) | ||
{ | ||
_listExternalEventsOfSyncRunResponse!.Result.Should().NotBeEmpty(); | ||
_listExternalEventsOfSyncRunResponse.Result.Should().NotContain(e => e.Type == "MessageReceived"); | ||
} | ||
|
||
[Then($"the response contains an external event for the Message {RegexFor.SINGLE_THING}")] | ||
public void ThenTheResponseContainsAnExternalEventForM(string messageName) | ||
{ | ||
var message = _messagesContext.Messages[messageName]; | ||
_listExternalEventsOfSyncRunResponse!.Result.Should().NotBeEmpty(); | ||
_listExternalEventsOfSyncRunResponse.Result.Should().ContainSingle(e => e.Type == "MessageReceived"); | ||
var messageReceivedExternalEvent = _listExternalEventsOfSyncRunResponse.Result!.Single(e => e.Type == "MessageReceived"); | ||
messageReceivedExternalEvent.Payload["id"].GetString().Should().Be(message.Id); | ||
} | ||
|
||
#endregion | ||
} |
Oops, something went wrong.