-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: MediaByContentTypeQuery tests
- Loading branch information
Showing
18 changed files
with
1,143 additions
and
9 deletions.
There are no files selected for viewing
Binary file modified
BIN
+72 KB
(110%)
src/Nikcio.UHeadless.IntegrationTests.TestProject/umbraco/Data/Default-Tests
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/Nikcio.UHeadless.IntegrationTests/ApiTests.MediaByContentTypeQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System.Net.Http.Json; | ||
|
||
namespace Nikcio.UHeadless.IntegrationTests.Defaults; | ||
|
||
public partial class ApiTests | ||
{ | ||
private const string _mediaByContentTypeSnapshotPath = $"{SnapshotConstants.BasePath}/MediaByContentType"; | ||
|
||
[Theory] | ||
[InlineData("image", 1, 0, true)] | ||
[InlineData("folder", 1, 0, true)] | ||
[InlineData("customMediaType", 1, 10, true)] | ||
[InlineData("image", 1, 1, true)] | ||
[InlineData("image", 2, 1, true)] | ||
[InlineData("image", 1, 1000, true)] | ||
[InlineData("image", 1000, 1000, true)] | ||
[InlineData("image", 1, 5, true)] | ||
[InlineData("image", 0, 5, false)] | ||
[InlineData("image", -1, 5, false)] | ||
[InlineData("image", 0, -1, false)] | ||
[InlineData("", 1, 1, false)] | ||
public async Task MediaByContentTypeQuery_Snaps_Async( | ||
string contentType, | ||
int page, | ||
int pageSize, | ||
bool expectSuccess) | ||
{ | ||
var snapshotProvider = new SnapshotProvider($"{_mediaByContentTypeSnapshotPath}/Snaps"); | ||
HttpClient client = _factory.CreateClient(); | ||
|
||
using var request = JsonContent.Create(new | ||
{ | ||
query = MediaByContentTypeQueries.GetItems, | ||
variables = new | ||
{ | ||
contentType, | ||
page, | ||
pageSize, | ||
} | ||
}); | ||
|
||
HttpResponseMessage response = await client.PostAsync("/graphql", request).ConfigureAwait(true); | ||
|
||
string responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(true); | ||
|
||
string snapshotName = $"MediaByContentType_Snaps_{contentType}_{page}_{pageSize}"; | ||
|
||
await snapshotProvider.AssertIsSnapshotEqualAsync(snapshotName, responseContent).ConfigureAwait(true); | ||
Assert.Equal(expectSuccess, response.IsSuccessStatusCode); | ||
} | ||
} | ||
|
||
public static class MediaByContentTypeQueries | ||
{ | ||
public const string GetItems = """ | ||
query MediaAtRootQuery( | ||
$contentType: String! | ||
$page: Int!, | ||
$pageSize: Int! | ||
) { | ||
mediaByContentType( | ||
contentType: $contentType | ||
page: $page, | ||
pageSize: $pageSize | ||
) { | ||
items { | ||
url(urlMode: ABSOLUTE) | ||
properties { | ||
...customMediaType | ||
__typename | ||
} | ||
urlSegment | ||
name | ||
id | ||
key | ||
templateId | ||
parent { | ||
url(urlMode: ABSOLUTE) | ||
properties { | ||
...customMediaType | ||
__typename | ||
} | ||
urlSegment | ||
name | ||
id | ||
key | ||
templateId | ||
} | ||
__typename | ||
} | ||
page | ||
pageSize | ||
totalItems | ||
hasNextPage | ||
} | ||
} | ||
""" + Fragments.CustomMediaType; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.