-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added header constants * refactor resolve props * added always prop * added always prop test * added async task wrapper * added clear history & history encryption * Delete InertiaCore/Utils/Header.cs * fix test sdks? * Minor changes --------- Co-authored-by: Kacper Ziubryniewicz <[email protected]>
- Loading branch information
Showing
5 changed files
with
110 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
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
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,90 @@ | ||
using InertiaCore.Models; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace InertiaCoreTests; | ||
|
||
public partial class Tests | ||
{ | ||
[Test] | ||
[Description("Test if history encryption is sent correctly.")] | ||
public async Task TestHistoryEncryptionResult() | ||
{ | ||
_factory.EncryptHistory(); | ||
|
||
var response = _factory.Render("Test/Page", new | ||
{ | ||
Test = "Test" | ||
}); | ||
|
||
var headers = new HeaderDictionary | ||
{ | ||
{ "X-Inertia", "true" } | ||
}; | ||
|
||
var context = PrepareContext(headers); | ||
|
||
response.SetContext(context); | ||
await response.ProcessResponse(); | ||
|
||
var result = response.GetResult(); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.That(result, Is.InstanceOf<JsonResult>()); | ||
|
||
var json = (result as JsonResult)?.Value; | ||
Assert.That(json, Is.InstanceOf<Page>()); | ||
|
||
Assert.That((json as Page)?.ClearHistory, Is.EqualTo(false)); | ||
Assert.That((json as Page)?.EncryptHistory, Is.EqualTo(true)); | ||
Assert.That((json as Page)?.Component, Is.EqualTo("Test/Page")); | ||
Assert.That((json as Page)?.Props, Is.EqualTo(new Dictionary<string, object?> | ||
{ | ||
{ "test", "Test" }, | ||
{ "errors", new Dictionary<string, string>(0) } | ||
})); | ||
}); | ||
} | ||
|
||
[Test] | ||
[Description("Test if clear history is sent correctly.")] | ||
public async Task TestClearHistoryResult() | ||
{ | ||
_factory.ClearHistory(); | ||
|
||
var response = _factory.Render("Test/Page", new | ||
{ | ||
Test = "Test" | ||
}); | ||
|
||
var headers = new HeaderDictionary | ||
{ | ||
{ "X-Inertia", "true" } | ||
}; | ||
|
||
var context = PrepareContext(headers); | ||
|
||
response.SetContext(context); | ||
await response.ProcessResponse(); | ||
|
||
var result = response.GetResult(); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.That(result, Is.InstanceOf<JsonResult>()); | ||
|
||
var json = (result as JsonResult)?.Value; | ||
Assert.That(json, Is.InstanceOf<Page>()); | ||
|
||
Assert.That((json as Page)?.ClearHistory, Is.EqualTo(true)); | ||
Assert.That((json as Page)?.EncryptHistory, Is.EqualTo(false)); | ||
Assert.That((json as Page)?.Component, Is.EqualTo("Test/Page")); | ||
Assert.That((json as Page)?.Props, Is.EqualTo(new Dictionary<string, object?> | ||
{ | ||
{ "test", "Test" }, | ||
{ "errors", new Dictionary<string, string>(0) } | ||
})); | ||
}); | ||
} | ||
} |