Skip to content

Commit ddaaf50

Browse files
authored
Error message for error.platform.validation.message.relationshipToRecipientNotActive contains wrong address (#915)
* fix: use correct address in error message of "relationshipToRecipientNotActive" * chore: fix formatting
1 parent 36343c0 commit ddaaf50

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

Modules/Messages/src/Messages.Application/Messages/Commands/SendMessage/Handler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ private async Task<List<RecipientInformation>> ValidateRecipients(SendMessageCom
6868
var numberOfUnreceivedMessagesFromActiveIdentity = await _messagesRepository.CountUnreceivedMessagesFromSenderToRecipient(sender, recipientDto.Address, cancellationToken);
6969

7070
relationshipBetweenSenderAndRecipient.EnsureSendingMessagesIsAllowed(
71+
_userContext.GetAddress(),
7172
numberOfUnreceivedMessagesFromActiveIdentity,
7273
_options.MaxNumberOfUnreceivedMessagesFromOneSender);
7374

Modules/Messages/src/Messages.Domain/DomainErrors.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static DomainError RelationshipToRecipientNotActive(string recipient = ""
1010

1111
return new DomainError(
1212
"error.platform.validation.message.relationshipToRecipientNotActive",
13-
$"Cannot send message to {recipientText} because the relationship to it is not active. In order to be able to send messages again, you have to reactivate the relationship.");
13+
$"Cannot send message to {recipientText} because the relationship to it is not active. If it's terminated, you'll need to reactivate it to be able to send messages again.");
1414
}
1515

1616
public static DomainError MaxNumberOfUnreceivedMessagesReached(string recipient = "")

Modules/Messages/src/Messages.Domain/Entities/Relationship.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ private Relationship(RelationshipId id, IdentityAddress from, IdentityAddress to
3535

3636
public RelationshipStatus Status { get; }
3737

38-
public void EnsureSendingMessagesIsAllowed(int numberOfUnreceivedMessagesFromActiveIdentity, int maxNumberOfUnreceivedMessagesFromOneSender)
38+
public void EnsureSendingMessagesIsAllowed(IdentityAddress activeIdentity, int numberOfUnreceivedMessagesFromActiveIdentity, int maxNumberOfUnreceivedMessagesFromOneSender)
3939
{
4040
if (Status != RelationshipStatus.Active)
41-
throw new DomainException(DomainErrors.RelationshipToRecipientNotActive(To));
41+
throw new DomainException(DomainErrors.RelationshipToRecipientNotActive(GetPeerOf(activeIdentity)));
4242

4343
if (numberOfUnreceivedMessagesFromActiveIdentity >= maxNumberOfUnreceivedMessagesFromOneSender)
4444
throw new DomainException(DomainErrors.MaxNumberOfUnreceivedMessagesReached(To));
@@ -48,6 +48,11 @@ public static Relationship LoadForTesting(RelationshipId id, IdentityAddress fro
4848
{
4949
return new Relationship(id, from, to, createdAt, status);
5050
}
51+
52+
private IdentityAddress GetPeerOf(IdentityAddress activeIdentity)
53+
{
54+
return From == activeIdentity ? To : From;
55+
}
5156
}
5257

5358
public enum RelationshipStatus
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
global using FluentAssertions;
2+
global using Xunit;
3+
global using static Backbone.UnitTestTools.Data.TestDataGenerator;

Modules/Messages/test/Messages.Domain.Tests/Relationships/RelationshipTests.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
using Backbone.Modules.Messages.Domain.Entities;
44
using Backbone.Modules.Messages.Domain.Ids;
55
using Backbone.UnitTestTools.BaseClasses;
6-
using Backbone.UnitTestTools.Data;
7-
using FluentAssertions;
8-
using Xunit;
96

107
namespace Backbone.Modules.Messages.Domain.Tests.Relationships;
118

@@ -18,7 +15,7 @@ public void Relationship_must_be_active_to_allow_sending_messages()
1815
var relationship = CreateRelationship(RelationshipStatus.Pending);
1916

2017
// Act
21-
var acting = () => relationship.EnsureSendingMessagesIsAllowed(0, 5);
18+
var acting = () => relationship.EnsureSendingMessagesIsAllowed(CreateRandomIdentityAddress(), 0, 5);
2219

2320
// Assert
2421
acting.Should().Throw<DomainException>().Which.Code.Should().Be("error.platform.validation.message.relationshipToRecipientNotActive");
@@ -31,7 +28,7 @@ public void Max_number_of_unreceived_messages_must_not_be_reached()
3128
var relationship = CreateRelationship();
3229

3330
// Act
34-
var acting = () => relationship.EnsureSendingMessagesIsAllowed(5, 5);
31+
var acting = () => relationship.EnsureSendingMessagesIsAllowed(CreateRandomIdentityAddress(), 5, 5);
3532

3633
// Assert
3734
acting.Should().Throw<DomainException>().Which.Code.Should().Be("error.platform.validation.message.maxNumberOfUnreceivedMessagesReached");
@@ -44,7 +41,7 @@ public void Relationship_cannot_be_terminated_to_allow_sending_messages()
4441
var relationship = CreateRelationship(RelationshipStatus.Terminated);
4542

4643
// Act
47-
var acting = () => relationship.EnsureSendingMessagesIsAllowed(0, 5);
44+
var acting = () => relationship.EnsureSendingMessagesIsAllowed(CreateRandomIdentityAddress(), 0, 5);
4845

4946
// Assert
5047
acting.Should().Throw<DomainException>().Which.Code.Should().Be("error.platform.validation.message.relationshipToRecipientNotActive");
@@ -61,8 +58,8 @@ private static Relationship CreateRelationship(string? relationshipId = null, Id
6158
RelationshipStatus? status = null)
6259
{
6360
relationshipId ??= "REL00000000000000000";
64-
from ??= TestDataGenerator.CreateRandomIdentityAddress();
65-
to ??= TestDataGenerator.CreateRandomIdentityAddress();
61+
from ??= CreateRandomIdentityAddress();
62+
to ??= CreateRandomIdentityAddress();
6663
createdAt ??= DateTime.UtcNow;
6764
status ??= RelationshipStatus.Active;
6865

0 commit comments

Comments
 (0)