Skip to content

Commit

Permalink
tests: ContentByTag test
Browse files Browse the repository at this point in the history
  • Loading branch information
nikcio committed May 5, 2024
1 parent 0fef3a1 commit 80d547b
Show file tree
Hide file tree
Showing 5 changed files with 4,797 additions and 0 deletions.
Binary file not shown.
106 changes: 106 additions & 0 deletions src/Nikcio.UHeadless.IntegrationTests/ApiTests.ContentByTagQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System.Net.Http.Json;

namespace Nikcio.UHeadless.IntegrationTests.Defaults;

public partial class ApiTests
{
private const string _contentByTagSnapshotPath = $"{SnapshotConstants.BasePath}/ContentByTag";

[Theory]
[InlineData("normal", null, "en-us", false, null, true)]
[InlineData("normal", null, "en-us", true, null, true)]
[InlineData("normal", null, "da", false, null, true)]
public async Task ContentByTagQuery_Snaps_Async(
string tag,
string? tagGroup,
string? culture,
bool? includePreview,
string? segment,
bool expectSuccess)
{
var snapshotProvider = new SnapshotProvider($"{_contentByTagSnapshotPath}/Snaps");
HttpClient client = _factory.CreateClient();

using var request = JsonContent.Create(new
{
query = ContentByTagQueries.GetItems,
variables = new
{
tag,
tagGroup,
culture,
includePreview,
segment
}
});

HttpResponseMessage response = await client.PostAsync("/graphql", request).ConfigureAwait(true);

string responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(true);

string snapshotName = $"ContentByTag_Snaps_{tag}_{tagGroup}_{culture}_{includePreview}_{segment}";

await snapshotProvider.AssertIsSnapshotEqualAsync(snapshotName, responseContent).ConfigureAwait(true);
Assert.Equal(expectSuccess, response.IsSuccessStatusCode);
}
}

public static class ContentByTagQueries
{
public const string GetItems = """
query ContentByTagQuery(
$tag: String!,
$tagGroup: String,
$culture: String
$includePreview: Boolean
$fallbacks: [PropertyFallback!]
$segment: String
) {
contentByTag(
tag: $tag,
tagGroup: $tagGroup
inContext: {
culture: $culture
includePreview: $includePreview
fallbacks: $fallbacks
segment: $segment
}
) {
items {
url(urlMode: ABSOLUTE)
redirect {
redirectUrl
isPermanent
}
statusCode
properties {
...typedProperties
__typename
}
urlSegment
name
id
key
templateId
parent {
url(urlMode: ABSOLUTE)
properties {
...typedProperties
__typename
}
urlSegment
name
id
key
templateId
}
__typename
}
page
pageSize
totalItems
hasNextPage
}
}
""" + Fragments.TypedProperties;
}
Loading

0 comments on commit 80d547b

Please sign in to comment.