Skip to content

Commit

Permalink
Updates to autotags
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-bstein committed Sep 18, 2024
1 parent 2f227a8 commit 948be03
Show file tree
Hide file tree
Showing 29 changed files with 4,367 additions and 99 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Gameboard.Api.Common.Services;
using Gameboard.Api.Data;
using Gameboard.Api.Tests.Shared;
using Microsoft.EntityFrameworkCore;

namespace Gameboard.Api.Tests.Integration.Fixtures;

Expand All @@ -23,6 +23,8 @@ public IDataStateBuilder Add<TEntity>(IFixture fixture, Action<TEntity>? entityB
{
var entity = fixture.Create<TEntity>() ?? throw new GbAutomatedTestSetupException($"The test fixture can't create entity of type {typeof(TEntity)}");
entityBuilder?.Invoke(entity);
entity.Id ??= GuidService.StaticGenerateGuid();

_dbContext.Add(entity);

return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Gameboard.Api;
using Gameboard.Api.Common;
using Gameboard.Api.Data;

namespace Gameboard.Api.Tests.Integration;

public class SupportControllerTests(GameboardTestContext testContext) : IClassFixture<GameboardTestContext>
{
private readonly GameboardTestContext _testContext = testContext;

[Theory, GbIntegrationAutoData]
public async Task Ticket_WhenCreatedWithAutoTagTrigger_AutoTags
(
IFixture fixture,
string gameId,
string tag,
string sponsorId,
string userId
)
{
// given an autotag which triggers on sponsor and a player with that sponsor
await _testContext.WithDataState(state =>
{
state.Add<Data.Game>(fixture, g =>
{
g.Id = gameId;
g.Players = new Data.Player
{
Id = fixture.Create<string>(),
Sponsor = state.Build<Data.Sponsor>(fixture, s => s.Id = sponsorId),
User = new Data.User { Id = userId, SponsorId = sponsorId }
}.ToCollection();
});
state.Add<SupportSettingsAutoTag>(fixture, t =>
{
t.ConditionType = SupportSettingsAutoTagConditionType.SponsorId;
t.ConditionValue = sponsorId;
t.IsEnabled = true;
t.Tag = tag;
});
});

var result = await _testContext
.CreateHttpClientWithAuthRole(UserRoleKey.Support)
.PostAsync("api/ticket", new NewTicket
{
AssigneeId = userId,
Description = fixture.Create<string>(),
Summary = fixture.Create<string>(),
RequesterId = userId,

}
.ToJsonBody())
.DeserializeResponseAs<Ticket>();

// TODO: test support for FromForm
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ await _testContext.WithDataState(state =>
});

// when this user updates their sponsor
var changedUser = new ChangedUser
var changedUser = new UpdateUser
{
Id = userId,
Name = userName,
Expand Down
30 changes: 14 additions & 16 deletions src/Gameboard.Api.Tests.Shared/Fixtures/GameboardCustomization.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using AutoFixture;
using AutoMapper;
using Microsoft.Extensions.DependencyInjection;
using Gameboard.Api.Data;
using Gameboard.Api.Features.GameEngine;

Expand All @@ -10,6 +9,7 @@ public class GameboardCustomization : ICustomization
{
public void Customize(IFixture fixture)
{
fixture.Behaviors.Add(new OmitOnRecursionBehavior());
RegisterDefaultEntityModels(fixture);
RegisterDefaultServices(fixture);
}
Expand All @@ -18,7 +18,8 @@ private void RegisterDefaultEntityModels(IFixture fixture)
{
fixture.Register(() => fixture);
fixture.Customizations.Add(new IdBuilder());
var now = DateTimeOffset.UtcNow;
fixture.Customizations.Add(new DateTimeOffsetSpecimenBuilder());
var now = DateTimeOffset.UtcNow.ToUniversalTime();

fixture.Register(() => new Data.ArchivedChallenge
{
Expand All @@ -43,7 +44,7 @@ private void RegisterDefaultEntityModels(IFixture fixture)
PointValue = 10,
ChallengeBonusType = ChallengeBonusType.CompleteSolveRank,
ChallengeSpec = fixture.Create<Data.ChallengeSpec>(),
AwardedTo = new List<Data.AwardedChallengeBonus>()
AwardedTo = []
});

fixture.Register<ChallengeBonus>(() => new ChallengeBonusCompleteSolveRank
Expand All @@ -53,7 +54,7 @@ private void RegisterDefaultEntityModels(IFixture fixture)
PointValue = 10,
ChallengeBonusType = ChallengeBonusType.CompleteSolveRank,
ChallengeSpec = fixture.Create<Data.ChallengeSpec>(),
AwardedTo = new List<Data.AwardedChallengeBonus>()
AwardedTo = []
});

fixture.Register(() => new Data.Challenge
Expand Down Expand Up @@ -108,8 +109,8 @@ private void RegisterDefaultEntityModels(IFixture fixture)
Name = $"Sponsor {fixture.Create<string>()}",
Approved = true,
Logo = "test.svg",
SponsoredPlayers = new List<Data.Player>(),
SponsoredUsers = new List<Data.User>()
SponsoredPlayers = [],
SponsoredUsers = []
});

fixture.Register(() => new Data.Player
Expand All @@ -135,8 +136,8 @@ private void RegisterDefaultEntityModels(IFixture fixture)
Markdown = "Here is some markdown _stuff_.",
Audience = "gameboard",
LaunchpointUrl = "https://google.com",
Players = new List<TopoMojo.Api.Client.Player>
{
Players =
[
new()
{
GamespaceId = "33b9cf31-8686-4d95-b5a8-9fb1b7f8ce71",
Expand All @@ -145,14 +146,14 @@ private void RegisterDefaultEntityModels(IFixture fixture)
Permission = TopoMojo.Api.Client.Permission.None,
IsManager = true
}
},
],
WhenCreated = DateTimeOffset.UtcNow,
StartTime = DateTimeOffset.UtcNow,
EndTime = DateTimeOffset.UtcNow.AddMinutes(60),
ExpirationTime = DateTime.UtcNow.AddMinutes(60),
IsActive = true,
Vms = new TopoMojo.Api.Client.VmState[]
{
Vms =
[
new()
{
Id = "10fccb66-6916-45e2-9a39-188d3a692d4a",
Expand All @@ -169,7 +170,7 @@ private void RegisterDefaultEntityModels(IFixture fixture)
IsRunning = true,
IsVisible = false
},
},
],
Challenge = new TopoMojo.Api.Client.ChallengeView
{
Text = "A challenging challenge",
Expand Down Expand Up @@ -222,10 +223,7 @@ private void RegisterDefaultEntityModels(IFixture fixture)

private void RegisterDefaultServices(IFixture fixture)
{
var mapper = new MapperConfiguration(cfg =>
{
cfg.AddGameboardMaps();
}).CreateMapper();
var mapper = new MapperConfiguration(cfg => cfg.AddGameboardMaps()).CreateMapper();

fixture.Register(() => mapper);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Reflection;
using AutoFixture.Kernel;

namespace Gameboard.Api.Tests.Shared.Fixtures;

internal class DateTimeOffsetSpecimenBuilder : ISpecimenBuilder
{
public object Create(object request, ISpecimenContext context)
{
var argumentType = typeof(object);

if (request is PropertyInfo pi)
{
argumentType = pi.PropertyType;
}

if (request is ParameterInfo rpi)
{
argumentType = rpi.ParameterType;
}

if (argumentType == typeof(DateTimeOffset))
{
return DateTimeOffset.UtcNow.ToUniversalTime();
}

return new NoSpecimen();
}
}
40 changes: 20 additions & 20 deletions src/Gameboard.Api.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gameboard.Api", "Gameboard.Api\Gameboard.Api.csproj", "{B43DA9BD-444C-4965-8CDA-D3574F32F048}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gameboard.Api", "Gameboard.Api\Gameboard.Api.csproj", "{5D9BEF4C-EBD0-4162-830F-973DDE1BE015}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gameboard.Api.Tests.Integration", "Gameboard.Api.Tests.Integration\Gameboard.Api.Tests.Integration.csproj", "{7E62FF88-574C-4B98-A96D-47D32CFD32C9}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gameboard.Api.Tests.Integration", "Gameboard.Api.Tests.Integration\Gameboard.Api.Tests.Integration.csproj", "{070C449A-E6F3-4AEF-8405-8227CE9741E8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gameboard.Api.Tests.Shared", "Gameboard.Api.Tests.Shared\Gameboard.Api.Tests.Shared.csproj", "{848FC395-F375-4BD7-9C2D-91BD6EC1A724}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gameboard.Api.Tests.Unit", "Gameboard.Api.Tests.Unit\Gameboard.Api.Tests.Unit.csproj", "{ED488368-1E44-445D-80DE-89A01D8B0351}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gameboard.Api.Tests.Unit", "Gameboard.Api.Tests.Unit\Gameboard.Api.Tests.Unit.csproj", "{441C3EDF-824D-45BD-AA62-84BF03BBD4A5}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gameboard.Api.Tests.Shared", "Gameboard.Api.Tests.Shared\Gameboard.Api.Tests.Shared.csproj", "{E7F5E3A9-2B06-4C63-A0B7-5A031B65F45D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -20,21 +20,21 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B43DA9BD-444C-4965-8CDA-D3574F32F048}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B43DA9BD-444C-4965-8CDA-D3574F32F048}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B43DA9BD-444C-4965-8CDA-D3574F32F048}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B43DA9BD-444C-4965-8CDA-D3574F32F048}.Release|Any CPU.Build.0 = Release|Any CPU
{7E62FF88-574C-4B98-A96D-47D32CFD32C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7E62FF88-574C-4B98-A96D-47D32CFD32C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7E62FF88-574C-4B98-A96D-47D32CFD32C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E62FF88-574C-4B98-A96D-47D32CFD32C9}.Release|Any CPU.Build.0 = Release|Any CPU
{848FC395-F375-4BD7-9C2D-91BD6EC1A724}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{848FC395-F375-4BD7-9C2D-91BD6EC1A724}.Debug|Any CPU.Build.0 = Debug|Any CPU
{848FC395-F375-4BD7-9C2D-91BD6EC1A724}.Release|Any CPU.ActiveCfg = Release|Any CPU
{848FC395-F375-4BD7-9C2D-91BD6EC1A724}.Release|Any CPU.Build.0 = Release|Any CPU
{441C3EDF-824D-45BD-AA62-84BF03BBD4A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{441C3EDF-824D-45BD-AA62-84BF03BBD4A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{441C3EDF-824D-45BD-AA62-84BF03BBD4A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{441C3EDF-824D-45BD-AA62-84BF03BBD4A5}.Release|Any CPU.Build.0 = Release|Any CPU
{5D9BEF4C-EBD0-4162-830F-973DDE1BE015}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5D9BEF4C-EBD0-4162-830F-973DDE1BE015}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D9BEF4C-EBD0-4162-830F-973DDE1BE015}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D9BEF4C-EBD0-4162-830F-973DDE1BE015}.Release|Any CPU.Build.0 = Release|Any CPU
{070C449A-E6F3-4AEF-8405-8227CE9741E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{070C449A-E6F3-4AEF-8405-8227CE9741E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{070C449A-E6F3-4AEF-8405-8227CE9741E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{070C449A-E6F3-4AEF-8405-8227CE9741E8}.Release|Any CPU.Build.0 = Release|Any CPU
{ED488368-1E44-445D-80DE-89A01D8B0351}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ED488368-1E44-445D-80DE-89A01D8B0351}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED488368-1E44-445D-80DE-89A01D8B0351}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ED488368-1E44-445D-80DE-89A01D8B0351}.Release|Any CPU.Build.0 = Release|Any CPU
{E7F5E3A9-2B06-4C63-A0B7-5A031B65F45D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7F5E3A9-2B06-4C63-A0B7-5A031B65F45D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7F5E3A9-2B06-4C63-A0B7-5A031B65F45D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7F5E3A9-2B06-4C63-A0B7-5A031B65F45D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion src/Gameboard.Api/Data/Entities/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class Player : IEntity
public double? AdvancedWithScore { get; set; }

// other navigation properties
public ICollection<Challenge> Challenges { get; set; } = new List<Challenge>();
public ICollection<Challenge> Challenges { get; set; } = [];
public string SponsorId { get; set; }
public Sponsor Sponsor { get; set; }

Expand Down
3 changes: 1 addition & 2 deletions src/Gameboard.Api/Data/Entities/SupportSettingsAutoTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ public class SupportSettingsAutoTag : IEntity
public string Id { get; set; }
public required SupportSettingsAutoTagConditionType ConditionType { get; set; }
public required string ConditionValue { get; set; }
public string Description { get; set; }
public required bool IsEnabled { get; set; }
public required string Tag { get; set; }

// navigation/modelfixup
public required string SupportSettingsId { get; set; }
public string SupportSettingsId { get; set; }
public SupportSettings SupportSettings { get; set; }
}
Loading

0 comments on commit 948be03

Please sign in to comment.