Skip to content

Commit

Permalink
tests: ContentByRoute tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nikcio committed May 5, 2024
1 parent 67be0f4 commit 0fef3a1
Show file tree
Hide file tree
Showing 26 changed files with 3,915 additions and 12 deletions.

This file was deleted.

Binary file not shown.
111 changes: 111 additions & 0 deletions src/Nikcio.UHeadless.IntegrationTests/ApiTests.ContentByRouteQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using System.Net.Http.Json;
using System.Text;

namespace Nikcio.UHeadless.IntegrationTests.Defaults;

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

[Theory]
[InlineData("https://site-1.com", "/", null, false, null, true)]
[InlineData("https://site-1.com", "/homepage", null, false, null, true)]
[InlineData("https://site-1.com", "/page-1", null, false, null, true)]
[InlineData("https://site-1.com", "/page-2", null, false, null, true)]
[InlineData("https://site-1.com", "/collection-of-pages/block-list-page", null, false, null, true)]
[InlineData("", "/no-domain-site", null, false, null, true)]
[InlineData("", "/no-domain-homepage", null, false, null, true)]
[InlineData("https://site-2.com", "/", null, false, null, true)]
[InlineData("https://site-2.com", "/page-1", null, false, null, true)]
[InlineData("https://site-culture.com", "/homepage", "en-us", false, null, true)]
[InlineData("https://site-culture.dk", "/homepage", "da", false, null, true)]
[InlineData("https://site-1.com", "/old-page", "en-us", false, null, true)]
[InlineData("https://site-1.com", "/new-page", "en-us", false, null, true)]
public async Task ContentByRouteQuery_Snaps_Async(
string baseUrl,
string route,
string? culture,
bool? includePreview,
string? segment,
bool expectSuccess)
{
var snapshotProvider = new SnapshotProvider($"{_contentByRouteSnapshotPath}/Snaps");
HttpClient client = _factory.CreateClient();

using var request = JsonContent.Create(new
{
query = ContentByRouteQueries.GetItems,
variables = new
{
baseUrl,
route,
culture,
includePreview,
segment
}
});

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

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

string snapshotName = $"ContentByRoute_Snaps_{Convert.ToBase64String(Encoding.UTF8.GetBytes(baseUrl))}_{Convert.ToBase64String(Encoding.UTF8.GetBytes(route))}_{culture}_{includePreview}_{segment}";

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

public static class ContentByRouteQueries
{
public const string GetItems = """
query ContentByRouteQuery(
$baseUrl: String!,
$route: String!,
$culture: String
$includePreview: Boolean
$fallbacks: [PropertyFallback!]
$segment: String
) {
contentByRoute(
baseUrl: $baseUrl,
route: $route,
inContext: {
culture: $culture
includePreview: $includePreview
fallbacks: $fallbacks
segment: $segment
}
) {
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
}
}
""" + Fragments.TypedProperties;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"items": [],
"page": 1000,
"pageSize": 1000,
"totalItems": 15,
"totalItems": 16,
"hasNextPage": false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"items": [],
"page": 1,
"pageSize": 0,
"totalItems": 15,
"totalItems": 16,
"hasNextPage": true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4308,6 +4308,213 @@
},
"__typename": "ContentItem"
},
{
"url": "http://site-1.com/new-page/",
"redirect": null,
"statusCode": 200,
"properties": {
"blockGrid": {
"model": "BlockGrid",
"gridColumns": null,
"blocks": []
},
"eyeDropperColorPicker": {
"value": "",
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"article": {
"value": "",
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"audio": {
"value": "",
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"file": {
"value": "",
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"svg": {
"value": "",
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"video": {
"value": "",
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"imageCropper": {
"value": null,
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"markdown": {
"value": "",
"sourceValue": null,
"model": "RichText",
"__typename": "RichText"
},
"imageMediaPicker": {
"mediaItems": [],
"model": "MediaPicker",
"__typename": "MediaPicker"
},
"mediaPicker": {
"mediaItems": [],
"model": "MediaPicker",
"__typename": "MediaPicker"
},
"multipleImageMediaPicker": {
"mediaItems": [],
"model": "MediaPicker",
"__typename": "MediaPicker"
},
"multipleMediaPicker": {
"mediaItems": [],
"model": "MediaPicker",
"__typename": "MediaPicker"
},
"mediaPickerLegacy": {
"mediaItems": [],
"model": "MediaPicker",
"__typename": "MediaPicker"
},
"multipleMediaPickerLegacy": {
"mediaItems": [],
"model": "MediaPicker",
"__typename": "MediaPicker"
},
"blockList": {
"blocks": [],
"model": "BlockList",
"__typename": "BlockList"
},
"memberGroupPicker": {
"value": "",
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"memberPicker": {
"members": [],
"model": "MemberPicker",
"__typename": "MemberPicker"
},
"multinodeTreepicker": {
"items": [],
"model": "ContentPicker",
"__typename": "ContentPicker"
},
"multiUrlPicker": {
"links": [],
"model": "MultiUrlPicker",
"__typename": "MultiUrlPicker"
},
"numeric": {
"value": 0,
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"radiobox": {
"value": null,
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"checkboxList": {
"value": [],
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"repeatableTextstrings": {
"value": [],
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"richtext": {
"value": "",
"sourceValue": null,
"model": "RichText",
"__typename": "RichText"
},
"slider": {
"value": 0,
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"tags": {
"value": [],
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"textarea": {
"value": "",
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"textstring": {
"value": "",
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"trueOrFalse": {
"value": false,
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"userPicker": {
"value": 0,
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"colorPicker": {
"value": "",
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"contentPicker": {
"items": [],
"model": "ContentPicker",
"__typename": "ContentPicker"
},
"decimal": {
"value": 0,
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"dropdown": {
"value": "",
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"emailAddress": {
"value": "",
"model": "DefaultProperty",
"__typename": "DefaultProperty"
},
"__typename": "Default"
},
"urlSegment": "new-page",
"name": "new-page",
"id": 1178,
"key": "706938b1-62a6-41df-a78e-982ec672c222",
"templateId": null,
"parent": {
"url": "http://site-1.com/",
"properties": {
"__typename": "EmptyPropertyType"
},
"urlSegment": "site-1",
"name": "Site 1",
"id": 1146,
"key": "eadd5be4-456c-4a7d-8c4a-2f7ead9c8ecf",
"templateId": null
},
"__typename": "ContentItem"
},
{
"url": "http://localhost/no-domain-homepage/",
"redirect": null,
Expand Down Expand Up @@ -5346,7 +5553,7 @@
],
"page": 1,
"pageSize": 1000,
"totalItems": 15,
"totalItems": 16,
"hasNextPage": false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
],
"page": 1,
"pageSize": 1,
"totalItems": 15,
"totalItems": 16,
"hasNextPage": true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1760,7 +1760,7 @@
],
"page": 1,
"pageSize": 5,
"totalItems": 15,
"totalItems": 16,
"hasNextPage": true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1760,7 +1760,7 @@
],
"page": 1,
"pageSize": 5,
"totalItems": 15,
"totalItems": 16,
"hasNextPage": true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1760,7 +1760,7 @@
],
"page": 1,
"pageSize": 5,
"totalItems": 15,
"totalItems": 16,
"hasNextPage": true
}
}
Expand Down
Loading

0 comments on commit 0fef3a1

Please sign in to comment.