Skip to content

Commit

Permalink
chore: Add integration test for cached GET /Tags
Browse files Browse the repository at this point in the history
  • Loading branch information
MH321Productions committed Feb 27, 2025
1 parent fdc6066 commit 436b57e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Backbone.ConsumerApi.Tests.Integration.Contexts;

public class TagsContext
{
public Dictionary<string, string> TagHashes { get; set; } = [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ User requests available Tags
Then the response status code is 200 (OK)
And the response supports the English language
And the response attributes contain tags

Scenario: Requesting the tags with the current hash
Given the most current hash h
When A GET request to the /Tags endpoint gets sent with hash h
Then the response status code is 304 (Not modified)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Backbone.BuildingBlocks.SDK.Endpoints.Common.Types;
using Backbone.ConsumerApi.Sdk.Endpoints.Tags.Types.Responses;
using Backbone.ConsumerApi.Tests.Integration.Contexts;
using Backbone.ConsumerApi.Tests.Integration.Extensions;
using Backbone.ConsumerApi.Tests.Integration.Helpers;

namespace Backbone.ConsumerApi.Tests.Integration.StepDefinitions;
Expand All @@ -10,22 +11,52 @@ public class TagsStepDefinitions
{
private readonly ResponseContext _responseContext;
private readonly ClientPool _clientPool;
private readonly TagsContext _tagsContext;

private ApiResponse<ListTagsResponse>? _listTagsResponse;
private CachedApiResponse<ListTagsResponse>? _listTagsResponse;

public TagsStepDefinitions(ResponseContext responseContext, ClientPool clientPool)
{
_responseContext = responseContext;
_clientPool = clientPool;
_tagsContext = new TagsContext();
}

#region Given

[Given($@"the most current hash {RegexFor.SINGLE_THING}")]
public async Task GivenTheMostCurrentHash(string hash)
{
await WhenAGETRequestToTheTagsEndpointGetsSent();

_listTagsResponse!.Should().BeASuccess();

_tagsContext.TagHashes[hash] = _listTagsResponse!.ETag;
}

#endregion


#region When

[When("A GET request to the /Tags endpoint gets sent")]
public async Task WhenAGETRequestToTheTagsEndpointGetsSent()
{
var client = _clientPool.Anonymous;
_responseContext.WhenResponse = _listTagsResponse = await client.Tags.ListTags();
}

[When($@"A GET request to the /Tags endpoint gets sent with hash {RegexFor.SINGLE_THING}")]
public async Task WhenAGETRequestToTheTagsEndpointGetsSentWithHash(string hash)
{
var client = _clientPool.Anonymous;
_responseContext.WhenResponse = _listTagsResponse = await client.Tags.ListTags(new CacheControl { ETag = _tagsContext.TagHashes[hash] });
}

#endregion

#region Then

[Then("the response supports the English language")]
public void AndTheResponseSupportsTheEnglishLanguage()
{
Expand All @@ -40,4 +71,6 @@ public void AndTheResponseAttributesContainTags()
attr.Should().NotBeEmpty();
}
}

#endregion
}

0 comments on commit 436b57e

Please sign in to comment.