Skip to content

Commit

Permalink
CanCreate returns true even though peer is in status ToBeDeleted (#871)
Browse files Browse the repository at this point in the history
* test: add test for missing condition

* fix: check for identity status in controller
  • Loading branch information
tnotheis authored Sep 17, 2024
1 parent c74e296 commit b04878d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ Feature: GET /Relationships/CanCreate
When i1 sends a GET request to the /Relationships/CanCreate?peer={id} endpoint with id=i2.id
Then the response status code is 200 (OK)
And a Relationship can be established

Scenario: Cannot create Relationship if peer is to be deleted
Given Identities i1 and i2
And i2 is in status "ToBeDeleted"
When i1 sends a GET request to the /Relationships/CanCreate?peer={id} endpoint with id=i2.id
Then the response status code is 200 (OK)
And a Relationship can not be established
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,14 @@ public async Task<IActionResult> DecomposeRelationship([FromRoute] string id, Ca
[HttpGet("CanCreate")]
[ProducesResponseType(typeof(HttpResponseEnvelopeResult<CanEstablishRelationshipResponse>), StatusCodes.Status200OK)]
[ProducesError(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> CanEstablishRelationship([FromQuery] string peer, CancellationToken cancellationToken)
public async Task<IActionResult> CanEstablishRelationship([FromQuery(Name = "peer")] string peerAddress, CancellationToken cancellationToken)
{
var response = await _mediator.Send(new CanEstablishRelationshipQuery { PeerAddress = peer }, cancellationToken);
var peerIdentity = await _mediator.Send(new GetIdentityQuery(peerAddress), cancellationToken);

var response = peerIdentity.Status is IdentityStatus.ToBeDeleted
? new CanEstablishRelationshipResponse { CanCreate = false }
: await _mediator.Send(new CanEstablishRelationshipQuery { PeerAddress = peerAddress }, cancellationToken);

return Ok(response);
}

Expand Down

0 comments on commit b04878d

Please sign in to comment.