-
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.
Check whether a relationship can be established with a given identity (…
…#808) * feat: Add /Relationships/CanCreate endpoint, query, response and handler * test: Add handler tests * chore: Add bruno file for /Relationships/CanCreate endpoint * chore: Add validator for CanEstablishRelationshipQuery and use string instead of IdentityAddress * chore: Remove unnecessary code * chore: Add CanCreate endpoint to ConsumerApi SDK * chore: Remove unnecessary handler tests * chore: Add integration tests * chore: Use helper method and modify Relationship.CountsAsActive method * chore: Add validator for the identity address format * chore: Remove unnecessary validator check * chore: Remove now obsolete static responses * chore: Use helper methods * chore: Create new helper method for rejected relationships * chore: Move and rename feature file * chore: Extract common helper method code into own method * chore: Don't use the null fallback * chore: Remove unused method * chore: Extract THEN method cluster into two methods * chore: cleanup --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Timo Notheisen <[email protected]>
- Loading branch information
1 parent
86f46a8
commit 5a4d55e
Showing
13 changed files
with
215 additions
and
8 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
Applications/ConsumerApi/src/http/Relationships/Can Establish Relationship.bru
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,19 @@ | ||
meta { | ||
name: /Relationships/CanCreate | ||
type: http | ||
seq: 4 | ||
} | ||
|
||
get { | ||
url: {{baseUrl}}/Relationships/CanCreate?peer={{PeerId}} | ||
body: none | ||
auth: inherit | ||
} | ||
|
||
params:query { | ||
peer: {{PeerId}} | ||
} | ||
|
||
vars:pre-request { | ||
PeerId: did:e:localhost:dids:8234cca0160ff05c785636 | ||
} |
38 changes: 38 additions & 0 deletions
38
...nsumerApi/test/ConsumerApi.Tests.Integration/Features/Relationships/CanCreate/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,38 @@ | ||
@Integration | ||
Feature: GET Relationships/CanCreate | ||
|
||
Scenario: Two identities without a relationship can create one | ||
Given Identities i1 and i2 | ||
When a GET request is sent to the /Relationships/CanCreate?peer={i.id} endpoint by i1 for i2 | ||
Then the response status code is 200 (OK) | ||
And a relationship can be established | ||
|
||
Scenario: Two identities with an active relationship can't create another one | ||
Given Identities i1 and i2 | ||
And an active Relationship between i1 and i2 created by i1 | ||
When a GET request is sent to the /Relationships/CanCreate?peer={i.id} endpoint by i1 for i2 | ||
Then the response status code is 200 (OK) | ||
And a relationship can not be established | ||
|
||
Scenario: Two identities with a rejected relationship can create one | ||
Given Identities i1 and i2 | ||
And a rejected Relationship between i1 and i2 created by i1 | ||
When a GET request is sent to the /Relationships/CanCreate?peer={i.id} endpoint by i1 for i2 | ||
Then the response status code is 200 (OK) | ||
And a relationship can be established | ||
|
||
Scenario: Two identities with a rejected and an active relationship can't create one | ||
Given Identities i1 and i2 | ||
And a rejected Relationship between i1 and i2 created by i1 | ||
And an active Relationship between i1 and i2 created by i1 | ||
When a GET request is sent to the /Relationships/CanCreate?peer={i.id} endpoint by i1 for i2 | ||
Then the response status code is 200 (OK) | ||
And a relationship can not be established | ||
|
||
Scenario: Two identities with two rejected relationships can create one | ||
Given Identities i1 and i2 | ||
And a rejected Relationship between i1 and i2 created by i1 | ||
And a rejected Relationship between i1 and i2 created by i1 | ||
When a GET request is sent to the /Relationships/CanCreate?peer={i.id} endpoint by i1 for i2 | ||
Then the response status code is 200 (OK) | ||
And a relationship can be established |
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
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
9 changes: 9 additions & 0 deletions
9
...plication/Relationships/Queries/CanEstablishRelationship/CanEstablishRelationshipQuery.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,9 @@ | ||
using Backbone.DevelopmentKit.Identity.ValueObjects; | ||
using MediatR; | ||
|
||
namespace Backbone.Modules.Relationships.Application.Relationships.Queries.CanEstablishRelationship; | ||
|
||
public class CanEstablishRelationshipQuery : IRequest<CanEstablishRelationshipResponse> | ||
{ | ||
public required string PeerAddress { get; set; } | ||
} |
14 changes: 14 additions & 0 deletions
14
.../Relationships/Queries/CanEstablishRelationship/CanEstablishRelationshipQueryValidator.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,14 @@ | ||
using Backbone.BuildingBlocks.Application.FluentValidation; | ||
using Backbone.DevelopmentKit.Identity.ValueObjects; | ||
using FluentValidation; | ||
|
||
namespace Backbone.Modules.Relationships.Application.Relationships.Queries.CanEstablishRelationship; | ||
|
||
// ReSharper disable once UnusedType.Global | ||
public class CanEstablishRelationshipQueryValidator : AbstractValidator<CanEstablishRelationshipQuery> | ||
{ | ||
public CanEstablishRelationshipQueryValidator() | ||
{ | ||
RuleFor(q => q.PeerAddress).Must(IdentityAddress.IsValid); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...cation/Relationships/Queries/CanEstablishRelationship/CanEstablishRelationshipResponse.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,6 @@ | ||
namespace Backbone.Modules.Relationships.Application.Relationships.Queries.CanEstablishRelationship; | ||
|
||
public class CanEstablishRelationshipResponse | ||
{ | ||
public required bool CanCreate { get; set; } | ||
} |
25 changes: 25 additions & 0 deletions
25
...s/src/Relationships.Application/Relationships/Queries/CanEstablishRelationship/Handler.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,25 @@ | ||
using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.UserContext; | ||
using Backbone.DevelopmentKit.Identity.ValueObjects; | ||
using Backbone.Modules.Relationships.Application.Infrastructure.Persistence.Repository; | ||
using MediatR; | ||
|
||
namespace Backbone.Modules.Relationships.Application.Relationships.Queries.CanEstablishRelationship; | ||
|
||
public class Handler : IRequestHandler<CanEstablishRelationshipQuery, CanEstablishRelationshipResponse> | ||
{ | ||
private readonly IRelationshipsRepository _relationshipsRepository; | ||
private readonly IUserContext _userContext; | ||
|
||
public Handler(IUserContext userContext, IRelationshipsRepository relationshipsRepository) | ||
{ | ||
_relationshipsRepository = relationshipsRepository; | ||
_userContext = userContext; | ||
} | ||
|
||
public async Task<CanEstablishRelationshipResponse> Handle(CanEstablishRelationshipQuery request, CancellationToken cancellationToken) | ||
{ | ||
var hasActiveRelationship = await _relationshipsRepository.RelationshipBetweenTwoIdentitiesExists(_userContext.GetAddress(), IdentityAddress.Parse(request.PeerAddress), cancellationToken); | ||
|
||
return new CanEstablishRelationshipResponse { CanCreate = !hasActiveRelationship }; | ||
} | ||
} |
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
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
6 changes: 6 additions & 0 deletions
6
...erApi.Sdk/src/Endpoints/Relationships/Types/Responses/CanEstablishRelationshipResponse.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,6 @@ | ||
namespace Backbone.ConsumerApi.Sdk.Endpoints.Relationships.Types.Responses; | ||
|
||
public class CanEstablishRelationshipResponse | ||
{ | ||
public required bool CanCreate { get; set; } | ||
} |