-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add missing test + fixes for zena functionality
- Loading branch information
1 parent
aac6339
commit aad9e47
Showing
22 changed files
with
422 additions
and
112 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
DragaliaAPI.Integration.Test/Features/Maintenance/MaintenanceTest.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,92 @@ | ||
using DragaliaAPI.Models.Options; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.TestHost; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace DragaliaAPI.Integration.Test.Features.Maintenance; | ||
|
||
public class MaintenanceTest : TestFixture | ||
{ | ||
private readonly CustomWebApplicationFactory factory; | ||
|
||
public MaintenanceTest(CustomWebApplicationFactory factory, ITestOutputHelper testOutputHelper) | ||
: base(factory, testOutputHelper) | ||
{ | ||
this.factory = factory; | ||
} | ||
|
||
[Fact] | ||
public async Task MaintenanceActive_ReturnsResultCode() | ||
{ | ||
this.ConfigureMaintenanceClient(new MaintenanceOptions() { Enabled = true }); | ||
|
||
DragaliaResponse<ResultCodeData> response = await this.Client.PostMsgpack<ResultCodeData>( | ||
"load/index", | ||
new LoadIndexRequest(), | ||
ensureSuccessHeader: false | ||
); | ||
|
||
response.data_headers.result_code.Should().Be(ResultCode.CommonMaintenance); | ||
} | ||
|
||
[Fact] | ||
public async Task MaintenanceActive_CoreEndpoint_ReturnsNormalResponse() | ||
{ | ||
this.ConfigureMaintenanceClient(new MaintenanceOptions() { Enabled = true }); | ||
|
||
DragaliaResponse<ToolGetServiceStatusData> response = | ||
await this.Client.PostMsgpack<ToolGetServiceStatusData>( | ||
"tool/get_service_status", | ||
new ToolGetServiceStatusRequest(), | ||
ensureSuccessHeader: false | ||
); | ||
|
||
response.data_headers.result_code.Should().Be(ResultCode.Success); | ||
response.data.service_status.Should().Be(1); | ||
} | ||
|
||
[Fact] | ||
public async Task MaintenanceActive_GetText_ReturnsText() | ||
{ | ||
this.ConfigureMaintenanceClient( | ||
new MaintenanceOptions() | ||
{ | ||
Enabled = true, | ||
Title = "Title", | ||
Body = "Body", | ||
End = DateTimeOffset.UnixEpoch | ||
} | ||
); | ||
|
||
DragaliaResponse<MaintenanceGetTextData> response = | ||
await this.Client.PostMsgpack<MaintenanceGetTextData>( | ||
"maintenance/get_text", | ||
new MaintenanceGetTextRequest() | ||
); | ||
|
||
response | ||
.data.maintenance_text.Should() | ||
.BeEquivalentTo( | ||
$""" | ||
<title>Title</title> | ||
<body>Body</body> | ||
<schedule>Check back at:</schedule> | ||
<date>1970-01-01T09:00:00</date> | ||
""" // Date must be in Japan Standard Time | ||
); | ||
} | ||
|
||
private void ConfigureMaintenanceClient(MaintenanceOptions options) => | ||
this.Client = this.CreateClient(builder => | ||
builder.ConfigureTestServices(services => | ||
services.Configure<MaintenanceOptions>(opts => | ||
{ | ||
opts.Enabled = options.Enabled; | ||
opts.Title = options.Title; | ||
opts.Body = options.Body; | ||
opts.End = options.End; | ||
}) | ||
) | ||
); | ||
} |
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,86 @@ | ||
using System.Net; | ||
using System.Net.Http.Headers; | ||
using System.Net.Http.Json; | ||
using DragaliaAPI.Features.Zena; | ||
|
||
namespace DragaliaAPI.Integration.Test.Features.Zena; | ||
|
||
public class ZenaTest : TestFixture | ||
{ | ||
public ZenaTest(CustomWebApplicationFactory factory, ITestOutputHelper testOutputHelper) | ||
: base(factory, testOutputHelper) | ||
{ | ||
Environment.SetEnvironmentVariable("ZENA_TOKEN", "token"); | ||
|
||
this.Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( | ||
"Bearer", | ||
"token" | ||
); | ||
} | ||
|
||
[Fact] | ||
public async Task GetTeamData_ValidId_ReturnsTeamData() | ||
{ | ||
HttpResponseMessage zenaResponse = await this.Client.GetAsync( | ||
$"zena/get_team_data?id={this.ViewerId}&teamnum=1" | ||
); | ||
|
||
zenaResponse.Should().BeSuccessful(); | ||
|
||
GetTeamDataResponse? deserialized = | ||
await zenaResponse.Content.ReadFromJsonAsync<GetTeamDataResponse>(); | ||
|
||
deserialized | ||
.Should() | ||
.BeEquivalentTo( | ||
new GetTeamDataResponse() | ||
{ | ||
Name = "Euden", | ||
Unit1 = Charas.ThePrince, | ||
Unit2 = Charas.Empty, | ||
Unit3 = Charas.Empty, | ||
Unit4 = Charas.Empty, | ||
} | ||
); | ||
} | ||
|
||
[Fact] | ||
public async Task GetTeamData_ValidId_MultiTeam_ReturnsTeamData() | ||
{ | ||
HttpResponseMessage zenaResponse = await this.Client.GetAsync( | ||
$"zena/get_team_data?id={this.ViewerId}&teamnum=1&teamnum2=2" | ||
); | ||
|
||
zenaResponse.Should().BeSuccessful(); | ||
|
||
GetTeamDataResponse? deserialized = | ||
await zenaResponse.Content.ReadFromJsonAsync<GetTeamDataResponse>(); | ||
|
||
deserialized | ||
.Should() | ||
.BeEquivalentTo( | ||
new GetTeamDataResponse() | ||
{ | ||
Name = "Euden", | ||
Unit1 = Charas.ThePrince, | ||
Unit2 = Charas.Empty, | ||
Unit3 = Charas.Empty, | ||
Unit4 = Charas.Empty, | ||
Unit5 = Charas.ThePrince, | ||
Unit6 = Charas.Empty, | ||
Unit7 = Charas.Empty, | ||
Unit8 = Charas.Empty, | ||
} | ||
); | ||
} | ||
|
||
[Fact] | ||
public async Task GetTeamData_InvalidId_Returns404() | ||
{ | ||
HttpResponseMessage zenaResponse = await this.Client.GetAsync( | ||
"zena/get_team_data?id=9999&teamnum=1&teamnum2=2" | ||
); | ||
|
||
zenaResponse.Should().HaveStatusCode(HttpStatusCode.NotFound); | ||
} | ||
} |
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
6 changes: 0 additions & 6 deletions
6
DragaliaAPI/Controllers/BypassResourceVersionCheckAttribute.cs
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.