Refactor campaign payload loading
This commit is contained in:
@@ -17,7 +17,7 @@ public sealed class CampaignApiTests : ApiTestBase
|
||||
await RegisterAsync(gmClient, "gm", "Password123", "Game Master");
|
||||
await LoginAsync(gmClient, "gm", "Password123");
|
||||
|
||||
var campaign = await PostAsync<CreateCampaignRequest, CampaignDetails>(gmClient, "/api/campaigns", new("Alpha Campaign", "dnd5e"));
|
||||
var campaign = await PostAsync<CreateCampaignRequest, CampaignSummary>(gmClient, "/api/campaigns", new("Alpha Campaign", "dnd5e"));
|
||||
|
||||
var gmCharacter = await PostAsync<CreateCharacterRequest, CharacterSummary>(gmClient, "/api/characters", new("Arin", campaign.Id));
|
||||
Assert.Equal("Game Master", gmCharacter.OwnerDisplayName);
|
||||
@@ -39,17 +39,25 @@ public sealed class CampaignApiTests : ApiTestBase
|
||||
var invalidSkill = await gmClient.PostAsJsonAsync($"/api/characters/{gmCharacter.Id}/skills", new CreateSkillRequest("Broken", "5D+4", 0, false));
|
||||
Assert.Equal(HttpStatusCode.BadRequest, invalidSkill.StatusCode);
|
||||
|
||||
var details = await GetAsync<CampaignDetails>(gmClient, $"/api/campaigns/{campaign.Id}");
|
||||
var details = await GetAsync<CampaignRoster>(gmClient, $"/api/campaigns/{campaign.Id}");
|
||||
Assert.Equal(campaign.Id, details.Id);
|
||||
Assert.Single(details.Characters);
|
||||
Assert.Equal("Game Master", details.Characters[0].OwnerDisplayName);
|
||||
|
||||
var summaries = await GetAsync<IReadOnlyList<CampaignSummary>>(gmClient, "/api/campaigns");
|
||||
Assert.Single(summaries);
|
||||
Assert.Equal(1, summaries[0].CharacterCount);
|
||||
|
||||
var sheet = await GetAsync<CharacterSheet>(gmClient, $"/api/characters/{gmCharacter.Id}/sheet");
|
||||
Assert.Single(sheet.Skills);
|
||||
Assert.Equal(updatedSkill.Id, sheet.Skills[0].Id);
|
||||
|
||||
var currentCampaignCharacters = await GetAsync<IReadOnlyList<CharacterSummary>>(gmClient, "/api/characters");
|
||||
Assert.Single(currentCampaignCharacters);
|
||||
Assert.Equal(gmCharacter.Id, currentCampaignCharacters[0].Id);
|
||||
Assert.Equal("Game Master", currentCampaignCharacters[0].OwnerDisplayName);
|
||||
|
||||
var otherCampaign = await PostAsync<CreateCampaignRequest, CampaignDetails>(gmClient, "/api/campaigns", new("Beta Campaign", "d6"));
|
||||
var otherCampaign = await PostAsync<CreateCampaignRequest, CampaignSummary>(gmClient, "/api/campaigns", new("Beta Campaign", "d6"));
|
||||
|
||||
var updatedCharacter = await PutAsync<UpdateCharacterRequest, CharacterSummary>(gmClient, $"/api/characters/{gmCharacter.Id}", new("Arin Updated", otherCampaign.Id));
|
||||
|
||||
@@ -74,7 +82,7 @@ public sealed class CampaignApiTests : ApiTestBase
|
||||
await RegisterAsync(receiverClient, "receiver2", "Password123", "Receiver");
|
||||
await LoginAsync(receiverClient, "receiver2", "Password123");
|
||||
|
||||
var campaign = await PostAsync<CreateCampaignRequest, CampaignDetails>(gmClient, "/api/campaigns", new("Grouped Campaign", "d6"));
|
||||
var campaign = await PostAsync<CreateCampaignRequest, CampaignSummary>(gmClient, "/api/campaigns", new("Grouped Campaign", "d6"));
|
||||
var character = await PostAsync<CreateCharacterRequest, CharacterSummary>(ownerClient, "/api/characters", new("Grouped Hero", campaign.Id));
|
||||
|
||||
var createdGroup = await PostAsync<CreateSkillGroupRequest, SkillGroupSummary>(ownerClient, $"/api/characters/{character.Id}/skill-groups", new("Combat", "2D+1", 1, true));
|
||||
@@ -103,7 +111,7 @@ public sealed class CampaignApiTests : ApiTestBase
|
||||
Assert.Equal("Grouped Hero", transferResult.Name);
|
||||
Assert.Equal("Receiver", transferResult.OwnerDisplayName);
|
||||
|
||||
var gmCampaignView = await GetAsync<CampaignDetails>(gmClient, $"/api/campaigns/{campaign.Id}");
|
||||
var gmCampaignView = await GetAsync<CampaignRoster>(gmClient, $"/api/campaigns/{campaign.Id}");
|
||||
var gmViewedCharacter = Assert.Single(gmCampaignView.Characters, c => c.Id == character.Id);
|
||||
Assert.Equal("Receiver", gmViewedCharacter.OwnerDisplayName);
|
||||
|
||||
@@ -139,7 +147,7 @@ public sealed class CampaignApiTests : ApiTestBase
|
||||
var promotedPlayer = await PutAsync<UpdateUserRolesRequest, AdminUserSummary>(adminClient, $"/api/admin/users/{player.Id}/roles", new([ "admin" ]));
|
||||
Assert.Contains(promotedPlayer.Roles, role => string.Equals(role, "admin", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
var campaign = await PostAsync<CreateCampaignRequest, CampaignDetails>(gmClient, "/api/campaigns", new("Disposable Campaign", "d6"));
|
||||
var campaign = await PostAsync<CreateCampaignRequest, CampaignSummary>(gmClient, "/api/campaigns", new("Disposable Campaign", "d6"));
|
||||
var character = await PostAsync<CreateCharacterRequest, CharacterSummary>(playerClient, "/api/characters", new("Disposable Hero", campaign.Id));
|
||||
var skill = await PostAsync<CreateSkillRequest, SkillSummary>(playerClient, $"/api/characters/{character.Id}/skills", new("Stealth", "2D+1", 1, true));
|
||||
_ = await PostAsync<RollSkillRequest, RollResult>(playerClient, $"/api/skills/{skill.Id}/roll", new("public"));
|
||||
@@ -213,10 +221,10 @@ public sealed class CampaignApiTests : ApiTestBase
|
||||
await RegisterAsync(playerClient, "player-options", "Password123", "Player");
|
||||
await LoginAsync(playerClient, "player-options", "Password123");
|
||||
|
||||
var firstCampaign = await PostAsync<CreateCampaignRequest, CampaignDetails>(gmClient, "/api/campaigns", new("Alpha Visible", "d6"));
|
||||
var secondCampaign = await PostAsync<CreateCampaignRequest, CampaignDetails>(otherGmClient, "/api/campaigns", new("Beta Available", "d6"));
|
||||
var firstCampaign = await PostAsync<CreateCampaignRequest, CampaignSummary>(gmClient, "/api/campaigns", new("Alpha Visible", "d6"));
|
||||
var secondCampaign = await PostAsync<CreateCampaignRequest, CampaignSummary>(otherGmClient, "/api/campaigns", new("Beta Available", "d6"));
|
||||
|
||||
var playerVisibleCampaigns = await GetAsync<IReadOnlyList<CampaignDetails>>(playerClient, "/api/campaigns");
|
||||
var playerVisibleCampaigns = await GetAsync<IReadOnlyList<CampaignSummary>>(playerClient, "/api/campaigns");
|
||||
Assert.Empty(playerVisibleCampaigns);
|
||||
|
||||
var playerCampaignOptions = await GetAsync<IReadOnlyList<CampaignOption>>(playerClient, "/api/campaigns/options");
|
||||
@@ -246,7 +254,7 @@ public sealed class CampaignApiTests : ApiTestBase
|
||||
await RegisterAsync(otherClient, "other-delete", "Password123", "Other");
|
||||
await LoginAsync(otherClient, "other-delete", "Password123");
|
||||
|
||||
var campaign = await PostAsync<CreateCampaignRequest, CampaignDetails>(gmClient, "/api/campaigns", new("Deletion Campaign", "d6"));
|
||||
var campaign = await PostAsync<CreateCampaignRequest, CampaignSummary>(gmClient, "/api/campaigns", new("Deletion Campaign", "d6"));
|
||||
var ownerCharacter = await PostAsync<CreateCharacterRequest, CharacterSummary>(ownerClient, "/api/characters", new("Owner Character", campaign.Id));
|
||||
var otherCharacter = await PostAsync<CreateCharacterRequest, CharacterSummary>(otherClient, "/api/characters", new("Other Character", campaign.Id));
|
||||
|
||||
@@ -262,7 +270,43 @@ public sealed class CampaignApiTests : ApiTestBase
|
||||
var adminDelete = await adminClient.DeleteAsync($"/api/characters/{otherCharacter.Id}");
|
||||
Assert.Equal(HttpStatusCode.OK, adminDelete.StatusCode);
|
||||
|
||||
var campaignAfterDeletes = await GetAsync<CampaignDetails>(gmClient, $"/api/campaigns/{campaign.Id}");
|
||||
var campaignAfterDeletes = await GetAsync<CampaignRoster>(gmClient, $"/api/campaigns/{campaign.Id}");
|
||||
Assert.Empty(campaignAfterDeletes.Characters);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CampaignLog_ReturnsMostRecentHundredEntries()
|
||||
{
|
||||
using var factory = CreateFactory();
|
||||
using var gmClient = factory.CreateClient(new() { AllowAutoRedirect = false });
|
||||
using var playerClient = factory.CreateClient(new() { AllowAutoRedirect = false });
|
||||
|
||||
await RegisterAsync(gmClient, "gm-log-cap", "Password123", "GM");
|
||||
await LoginAsync(gmClient, "gm-log-cap", "Password123");
|
||||
|
||||
await RegisterAsync(playerClient, "player-log-cap", "Password123", "Player");
|
||||
await LoginAsync(playerClient, "player-log-cap", "Password123");
|
||||
|
||||
var campaign = await PostAsync<CreateCampaignRequest, CampaignSummary>(gmClient, "/api/campaigns", new("Log Cap", "d6"));
|
||||
var character = await PostAsync<CreateCharacterRequest, CharacterSummary>(playerClient, "/api/characters", new("Roller", campaign.Id));
|
||||
var skill = await PostAsync<CreateSkillRequest, SkillSummary>(playerClient, $"/api/characters/{character.Id}/skills", new("Stealth", "2D+1", 1, true));
|
||||
|
||||
var rollIds = new List<Guid>();
|
||||
for (var i = 0; i < 105; i++)
|
||||
{
|
||||
var roll = await PostAsync<RollSkillRequest, RollResult>(playerClient, $"/api/skills/{skill.Id}/roll", new("public"));
|
||||
rollIds.Add(roll.RollId);
|
||||
}
|
||||
|
||||
var log = await GetAsync<IReadOnlyList<CampaignLogEntry>>(gmClient, $"/api/campaigns/{campaign.Id}/log");
|
||||
Assert.Equal(100, log.Count);
|
||||
Assert.Equal(rollIds[5], log[0].RollId);
|
||||
Assert.Equal(rollIds[^1], log[^1].RollId);
|
||||
Assert.All(log, entry =>
|
||||
{
|
||||
Assert.False(string.IsNullOrWhiteSpace(entry.CharacterName));
|
||||
Assert.False(string.IsNullOrWhiteSpace(entry.SkillName));
|
||||
Assert.False(string.IsNullOrWhiteSpace(entry.RollerDisplayName));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace RpgRoller.Tests;
|
||||
|
||||
public sealed class FrontendHostTests : ApiTestBase
|
||||
@@ -21,24 +18,4 @@ public sealed class FrontendHostTests : ApiTestBase
|
||||
Assert.Contains("_framework/blazor.web.js", html);
|
||||
Assert.Contains("Connecting...", html);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BlazorHub_AllowsLargerInteropPayloads()
|
||||
{
|
||||
using var factory = CreateFactory();
|
||||
var componentHubType = Type.GetType("Microsoft.AspNetCore.Components.Server.ComponentHub, Microsoft.AspNetCore.Components.Server");
|
||||
Assert.NotNull(componentHubType);
|
||||
|
||||
var hubOptionsType = typeof(HubOptions<>).MakeGenericType(componentHubType);
|
||||
var optionsType = typeof(IOptions<>).MakeGenericType(hubOptionsType);
|
||||
var options = factory.Services.GetService(optionsType);
|
||||
Assert.NotNull(options);
|
||||
|
||||
var value = optionsType.GetProperty("Value")!.GetValue(options);
|
||||
Assert.NotNull(value);
|
||||
|
||||
var maximumReceiveMessageSize = (long?)hubOptionsType.GetProperty("MaximumReceiveMessageSize")!.GetValue(value);
|
||||
|
||||
Assert.Equal(256 * 1024, maximumReceiveMessageSize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public sealed class RollVisibilityApiTests : ApiTestBase
|
||||
|
||||
await RegisterAsync(gmClient, "gm", "Password123", "GM");
|
||||
await LoginAsync(gmClient, "gm", "Password123");
|
||||
var campaign = await PostAsync<CreateCampaignRequest, CampaignDetails>(gmClient, "/api/campaigns", new("Main", "d6"));
|
||||
var campaign = await PostAsync<CreateCampaignRequest, CampaignSummary>(gmClient, "/api/campaigns", new("Main", "d6"));
|
||||
|
||||
await RegisterAsync(playerClient, "player", "Password123", "Player");
|
||||
await LoginAsync(playerClient, "player", "Password123");
|
||||
@@ -68,4 +68,4 @@ public sealed class RollVisibilityApiTests : ApiTestBase
|
||||
var unauthorizedWithInvalidSession = await anonymousClient.SendAsync(invalidSessionRequest);
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, unauthorizedWithInvalidSession.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ public sealed class SystemApiTests : ApiTestBase
|
||||
await RegisterAsync(client, "sse", "Password123", "Sse User");
|
||||
await LoginAsync(client, "sse", "Password123");
|
||||
|
||||
var campaign = await PostAsync<CreateCampaignRequest, CampaignDetails>(client, "/api/campaigns", new("SSE", "d6"));
|
||||
var campaign = await PostAsync<CreateCampaignRequest, CampaignSummary>(client, "/api/campaigns", new("SSE", "d6"));
|
||||
|
||||
var sseResponse = await client.GetAsync($"/api/events/state?campaignId={campaign.Id}", HttpCompletionOption.ResponseHeadersRead);
|
||||
Assert.Equal(HttpStatusCode.OK, sseResponse.StatusCode);
|
||||
Assert.Equal("text/event-stream", sseResponse.Content.Headers.ContentType?.MediaType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public sealed class ServiceCampaignTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetCampaign_ForNonGmParticipant_ReturnsCampaignCharactersAndSkills()
|
||||
public void GetCampaignAndCharacterSheet_ForNonGmParticipant_ReturnCampaignRosterAndSheet()
|
||||
{
|
||||
using var harness = ServiceTestSupport.CreateHarness();
|
||||
var service = harness.Service;
|
||||
@@ -120,7 +120,11 @@ public sealed class ServiceCampaignTests
|
||||
Assert.Equal(2, ownerView.Characters.Count);
|
||||
Assert.Contains(ownerView.Characters, character => character.Id == ownerCharacter.Id);
|
||||
Assert.Contains(ownerView.Characters, character => character.Id == otherCharacter.Id);
|
||||
Assert.Equal(2, ownerView.Skills.Count);
|
||||
Assert.Contains(ownerView.Skills, skill => skill.Id == ownerSkill.Id);
|
||||
|
||||
var ownerSheet = ServiceTestSupport.GetValue(service.GetCharacterSheet(ownerSession, ownerCharacter.Id));
|
||||
var otherSheet = ServiceTestSupport.GetValue(service.GetCharacterSheet(ownerSession, otherCharacter.Id));
|
||||
Assert.Single(ownerSheet.Skills);
|
||||
Assert.Contains(ownerSheet.Skills, skill => skill.Id == ownerSkill.Id);
|
||||
Assert.Single(otherSheet.Skills);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,17 +45,19 @@ public sealed class ServiceSkillGroupAndOwnershipTests
|
||||
var deletedGroup = ServiceTestSupport.GetValue(service.DeleteSkillGroup(ownerSession, renamedGroup.Id));
|
||||
Assert.True(deletedGroup);
|
||||
|
||||
var afterGroupDelete = ServiceTestSupport.GetValue(service.GetCampaign(ownerSession, campaign.Id));
|
||||
Assert.DoesNotContain(afterGroupDelete.SkillGroups, group => group.Id == renamedGroup.Id);
|
||||
Assert.Contains(afterGroupDelete.SkillGroups, group => group.Id == otherGroup.Id);
|
||||
Assert.Null(afterGroupDelete.Skills.Single(s => s.Id == regroupedSkill.Id).SkillGroupId);
|
||||
var ownerSheetAfterGroupDelete = ServiceTestSupport.GetValue(service.GetCharacterSheet(ownerSession, ownerCharacter.Id));
|
||||
var otherSheetAfterGroupDelete = ServiceTestSupport.GetValue(service.GetCharacterSheet(ownerSession, otherCharacter.Id));
|
||||
Assert.DoesNotContain(ownerSheetAfterGroupDelete.SkillGroups, group => group.Id == renamedGroup.Id);
|
||||
Assert.Contains(otherSheetAfterGroupDelete.SkillGroups, group => group.Id == otherGroup.Id);
|
||||
Assert.Null(ownerSheetAfterGroupDelete.Skills.Single(s => s.Id == regroupedSkill.Id).SkillGroupId);
|
||||
|
||||
var deletedSkill = ServiceTestSupport.GetValue(service.DeleteSkill(ownerSession, regroupedSkill.Id));
|
||||
Assert.True(deletedSkill);
|
||||
|
||||
var ownerView = ServiceTestSupport.GetValue(service.GetCampaign(ownerSession, campaign.Id));
|
||||
var ownerView = ServiceTestSupport.GetValue(service.GetCharacterSheet(ownerSession, ownerCharacter.Id));
|
||||
var otherView = ServiceTestSupport.GetValue(service.GetCharacterSheet(ownerSession, otherCharacter.Id));
|
||||
Assert.DoesNotContain(ownerView.SkillGroups, group => group.Id == renamedGroup.Id);
|
||||
Assert.Contains(ownerView.SkillGroups, group => group.Id == otherGroup.Id);
|
||||
Assert.Contains(otherView.SkillGroups, group => group.Id == otherGroup.Id);
|
||||
Assert.DoesNotContain(ownerView.Skills, skillSummary => skillSummary.Id == regroupedSkill.Id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user