Skip to content

Commit

Permalink
chore: Simplify used test functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MH321Productions committed Nov 11, 2024
1 parent 6b68bef commit a03f31a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ User deletes a Relationship Template
Given Identity i
And a Relationship Template t created by i
When i sends a DELETE request to the /RelationshipTemplates/t.Id endpoint
And i sends a GET request to the /RelationshipTemplates/t.Id endpoint with password "-"
And i sends a GET request to the /RelationshipTemplates/t.Id endpoint
Then the response status code is 404 (Not Found)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ User deletes a Token

Scenario: Deleting a Token actually removes it
Given Identity i
And Token t created by i with password "-" and forIdentity -
And Token t created by i
When i sends a DELETE request to the /Tokens/t.Id endpoint
And i sends a GET request to the /Tokens/t.Id endpoint with password "-"
And i sends a GET request to the /Tokens/t.Id endpoint
Then the response status code is 404 (Not Found)
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ public async Task WhenIdentitySendsAGetRequestToTheRelationshipTemplatesIdEndpoi
: await client.RelationshipTemplates.GetTemplate(relationshipTemplateId);
}

[When($"{RegexFor.SINGLE_THING} sends a GET request to the /RelationshipTemplates/{RegexFor.SINGLE_THING}.Id endpoint")]
public async Task WhenIdentitySendsAGetRequestToTheRelationshipTemplatesIdEndpoint(string identityName, string relationshipTemplateName)
{
var client = _clientPool.FirstForIdentityName(identityName);

var relationshipTemplateId = _relationshipTemplatesContext.CreateRelationshipTemplatesResponses[relationshipTemplateName].Id;

_responseContext.WhenResponse = await client.RelationshipTemplates.GetTemplate(relationshipTemplateId);
}

[When($@"{RegexFor.SINGLE_THING} sends a GET request to the /RelationshipTemplates endpoint with the following payloads")]
public async Task WhenISendsAGETRequestToTheRelationshipTemplatesEndpointWithTheFollowingPayloads(string identityName, Table table)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ public async Task GivenRelationshipTemplateCreatedByTokenOwnerWithPasswordAndFor
_tokensContext.CreateTokenResponses[relationshipTemplateName] = response.Result!;
}

[Given($@"Token {RegexFor.SINGLE_THING} created by {RegexFor.SINGLE_THING}")]
public async Task GivenTokenCreatedByIdentity(string tokenName, string identityName)
{
var client = _clientPool.FirstForIdentityName(identityName);

var response = await client.Tokens.CreateToken(
new CreateTokenRequest { Content = TestData.SOME_BYTES, ExpiresAt = TOMORROW, ForIdentity = null, Password = null });

_tokensContext.CreateTokenResponses[tokenName] = response.Result!;
}

[Given(@"the following Tokens")]
public async Task GivenTheFollowingTokens(Table table)
{
Expand Down Expand Up @@ -121,6 +132,20 @@ public async Task WhenIdentitySendsAGetRequestToTheTokensIdEndpointWithPassword(
: await client.Tokens.GetTokenUnauthenticated(tokenId);
}

[When($@"{RegexFor.OPTIONAL_SINGLE_THING} sends a GET request to the /Tokens/{RegexFor.SINGLE_THING}.Id endpoint")]
public async Task WhenIdentitySendsAGetRequestToTheTokensIdEndpoint(string identityName, string tokenName)
{
var isAuthenticated = identityName != "-";

var client = isAuthenticated ? _clientPool.FirstForIdentityName(identityName) : _clientPool.Anonymous;
var tokenId = _tokensContext.CreateTokenResponses[tokenName].Id;

if (isAuthenticated)
_responseContext.WhenResponse = await client.Tokens.GetToken(tokenId);
else
_responseContext.WhenResponse = await client.Tokens.GetTokenUnauthenticated(tokenId);
}

[When($@"{RegexFor.SINGLE_THING} sends a GET request to the /Tokens endpoint with the following payloads")]
public async Task WhenISendsAGETRequestToTheTokensEndpointWithTheFollowingPayloads(string identityName, Table table)
{
Expand Down

0 comments on commit a03f31a

Please sign in to comment.