Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5014ca5c58 | |||
| efd86bca0a | |||
| 2241568bac | |||
| 37ed697696 | |||
| 320ec18ab0 | |||
| 4424d8faad |
@@ -6,7 +6,7 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
env:
|
env:
|
||||||
VERSION: 3.9.6
|
VERSION: 3.9.8
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# ЧАСТЬ 1: Собираем образы и кладем в Gitea (чтобы делиться с ребятами)
|
# ЧАСТЬ 1: Собираем образы и кладем в Gitea (чтобы делиться с ребятами)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>3.9.6</Version>
|
<Version>3.9.8</Version>
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<LangVersion>preview</LangVersion>
|
<LangVersion>preview</LangVersion>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
|||||||
+3
-3
@@ -49,7 +49,7 @@ services:
|
|||||||
crond -f
|
crond -f
|
||||||
|
|
||||||
bot:
|
bot:
|
||||||
image: git.codeanddice.ru/toutsu/gmrelay-bot:3.9.6
|
image: git.codeanddice.ru/toutsu/gmrelay-bot:3.9.8
|
||||||
restart: always
|
restart: always
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
@@ -67,7 +67,7 @@ services:
|
|||||||
retries: 3
|
retries: 3
|
||||||
|
|
||||||
discord:
|
discord:
|
||||||
image: git.codeanddice.ru/toutsu/gmrelay-discord-bot:3.9.6
|
image: git.codeanddice.ru/toutsu/gmrelay-discord-bot:3.9.8
|
||||||
restart: always
|
restart: always
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
@@ -86,7 +86,7 @@ services:
|
|||||||
retries: 3
|
retries: 3
|
||||||
|
|
||||||
web:
|
web:
|
||||||
image: git.codeanddice.ru/toutsu/gmrelay-web:3.9.6
|
image: git.codeanddice.ru/toutsu/gmrelay-web:3.9.8
|
||||||
restart: always
|
restart: always
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
|
|||||||
@@ -229,7 +229,8 @@ public sealed class CreateSessionHandler
|
|||||||
if (p.Type == WizardCreationType.Single)
|
if (p.Type == WizardCreationType.Single)
|
||||||
{
|
{
|
||||||
if (p.Single?.ScheduledAt is null) missingFields.Add("дата/время");
|
if (p.Single?.ScheduledAt is null) missingFields.Add("дата/время");
|
||||||
if (p.Single?.MaxPlayers is null) missingFields.Add("лимит мест");
|
// MaxPlayers = null is a valid "♾ Без лимита" choice
|
||||||
|
// (see GameCreationWizard.ApplyCapacityChoice "no_limit").
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -82,7 +82,13 @@ public sealed class CreateSessionHandler(
|
|||||||
AND p.external_user_id = @ExternalGmId
|
AND p.external_user_id = @ExternalGmId
|
||||||
ON CONFLICT (group_id, player_id) DO NOTHING
|
ON CONFLICT (group_id, player_id) DO NOTHING
|
||||||
""",
|
""",
|
||||||
new { GroupId = groupId, ExternalGmId = externalUserId, OwnerRole = GroupManagerRoleExtensions.OwnerValue },
|
new
|
||||||
|
{
|
||||||
|
GroupId = groupId,
|
||||||
|
Platform = platform,
|
||||||
|
ExternalGmId = externalUserId,
|
||||||
|
OwnerRole = GroupManagerRoleExtensions.OwnerValue
|
||||||
|
},
|
||||||
transaction);
|
transaction);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -82,7 +82,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div class="nav-version">v3.9.6</div>
|
<div class="nav-version">v3.9.8</div>
|
||||||
</div>
|
</div>
|
||||||
</Authorized>
|
</Authorized>
|
||||||
<NotAuthorized>
|
<NotAuthorized>
|
||||||
|
|||||||
+130
@@ -0,0 +1,130 @@
|
|||||||
|
using GmRelay.Shared.Domain;
|
||||||
|
using GmRelay.Shared.Features.Sessions.CreateSession;
|
||||||
|
using GmRelay.Shared.Platform;
|
||||||
|
using Npgsql;
|
||||||
|
using Testcontainers.PostgreSql;
|
||||||
|
|
||||||
|
namespace GmRelay.Bot.Tests.Features.Sessions.CreateSession;
|
||||||
|
|
||||||
|
[CollectionDefinition(Name)]
|
||||||
|
public sealed class CreateSessionHandlerPostgresCollection : ICollectionFixture<CreateSessionHandlerPostgresFixture>
|
||||||
|
{
|
||||||
|
public const string Name = "Create session handler PostgreSQL";
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class CreateSessionHandlerPostgresFixture : IAsyncLifetime
|
||||||
|
{
|
||||||
|
private static readonly TimeSpan ContainerTimeout = TimeSpan.FromMinutes(2);
|
||||||
|
private readonly PostgreSqlContainer container = new PostgreSqlBuilder("postgres:17-alpine").Build();
|
||||||
|
|
||||||
|
public Task InitializeAsync()
|
||||||
|
{
|
||||||
|
return container.StartAsync().WaitAsync(ContainerTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task DisposeAsync()
|
||||||
|
{
|
||||||
|
return container.DisposeAsync().AsTask().WaitAsync(ContainerTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string> CreateMigratedDatabaseAsync()
|
||||||
|
{
|
||||||
|
var databaseName = $"create_session_{Guid.NewGuid():N}";
|
||||||
|
|
||||||
|
await using (var adminConnection = new NpgsqlConnection(container.GetConnectionString()))
|
||||||
|
{
|
||||||
|
await adminConnection.OpenAsync().WaitAsync(ContainerTimeout);
|
||||||
|
await using var createDatabase = new NpgsqlCommand($"CREATE DATABASE \"{databaseName}\"", adminConnection);
|
||||||
|
await createDatabase.ExecuteNonQueryAsync().WaitAsync(ContainerTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
var connectionString = new NpgsqlConnectionStringBuilder(container.GetConnectionString())
|
||||||
|
{
|
||||||
|
Database = databaseName,
|
||||||
|
Timeout = 10,
|
||||||
|
CommandTimeout = 30
|
||||||
|
}.ConnectionString;
|
||||||
|
|
||||||
|
await using var connection = new NpgsqlConnection(connectionString);
|
||||||
|
await connection.OpenAsync().WaitAsync(ContainerTimeout);
|
||||||
|
|
||||||
|
foreach (var migration in GetMigrationPaths())
|
||||||
|
{
|
||||||
|
await using var command = new NpgsqlCommand(await File.ReadAllTextAsync(migration), connection)
|
||||||
|
{
|
||||||
|
CommandTimeout = 30
|
||||||
|
};
|
||||||
|
await command.ExecuteNonQueryAsync().WaitAsync(ContainerTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
return connectionString;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IReadOnlyList<string> GetMigrationPaths()
|
||||||
|
{
|
||||||
|
var directory = new DirectoryInfo(AppContext.BaseDirectory);
|
||||||
|
while (directory is not null)
|
||||||
|
{
|
||||||
|
var migrationsDirectory = Path.Combine(directory.FullName, "src", "GmRelay.Bot", "Migrations");
|
||||||
|
if (Directory.Exists(migrationsDirectory))
|
||||||
|
{
|
||||||
|
return Directory.GetFiles(migrationsDirectory, "V*.sql")
|
||||||
|
.OrderBy(path => Path.GetFileName(path), StringComparer.Ordinal)
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
directory = directory.Parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new DirectoryNotFoundException("Could not locate the bot migrations directory.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Collection(CreateSessionHandlerPostgresCollection.Name)]
|
||||||
|
public sealed class CreateSessionHandlerIntegrationTests(CreateSessionHandlerPostgresFixture fixture)
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task HandleAsync_NewPlatformGroup_AddsOwnerAndPersistsSession()
|
||||||
|
{
|
||||||
|
var connectionString = await fixture.CreateMigratedDatabaseAsync();
|
||||||
|
await using var dataSource = NpgsqlDataSource.Create(connectionString);
|
||||||
|
var sut = new CreateSessionHandler(dataSource);
|
||||||
|
|
||||||
|
var result = await sut.HandleAsync(
|
||||||
|
new CreateSessionCommand(
|
||||||
|
new PlatformUser(PlatformKind.Telegram, "111111111", "Test GM", "test_gm"),
|
||||||
|
new PlatformGroup(PlatformKind.Telegram, "222222222", "Test Group"),
|
||||||
|
"Test Adventure",
|
||||||
|
string.Empty,
|
||||||
|
[DateTimeOffset.UtcNow.AddDays(1)],
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
GameSystem.Dnd5e,
|
||||||
|
"Integration regression test",
|
||||||
|
"Online",
|
||||||
|
240,
|
||||||
|
true),
|
||||||
|
CancellationToken.None);
|
||||||
|
|
||||||
|
Assert.True(result.Success, result.ErrorMessage);
|
||||||
|
Assert.NotNull(result.BatchId);
|
||||||
|
Assert.NotNull(result.GroupId);
|
||||||
|
|
||||||
|
await using var connection = await dataSource.OpenConnectionAsync();
|
||||||
|
await using var command = new NpgsqlCommand(
|
||||||
|
"""
|
||||||
|
SELECT count(*)
|
||||||
|
FROM group_managers gm
|
||||||
|
JOIN players p ON p.id = gm.player_id
|
||||||
|
WHERE gm.group_id = @group_id
|
||||||
|
AND gm.role = 'Owner'
|
||||||
|
AND p.platform = 'Telegram'
|
||||||
|
AND p.external_user_id = '111111111'
|
||||||
|
""",
|
||||||
|
connection);
|
||||||
|
command.Parameters.AddWithValue("group_id", result.GroupId.Value);
|
||||||
|
|
||||||
|
var ownerCount = (long)(await command.ExecuteScalarAsync() ?? 0L);
|
||||||
|
Assert.Equal(1, ownerCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
+43
@@ -146,4 +146,47 @@ public sealed class CreateSessionHandlerSubmitValidationTests
|
|||||||
Assert.Single(messenger.Edits);
|
Assert.Single(messenger.Edits);
|
||||||
Assert.Contains("слоты", messenger.Edits[0].Text, StringComparison.OrdinalIgnoreCase);
|
Assert.Contains("слоты", messenger.Edits[0].Text, StringComparison.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task SubmitDraftAsync_SingleWithNoLimit_DoesNotReportMaxPlayersAsMissing()
|
||||||
|
{
|
||||||
|
// Regression for #131: pressing "♾ Без лимита" sets MaxPlayers = null.
|
||||||
|
// IsComplete must NOT flag that as a missing field; null means
|
||||||
|
// "no player limit" and is a valid final state.
|
||||||
|
var drafts = new FakeWizardDraftRepository();
|
||||||
|
var messenger = new FakeWizardMessenger();
|
||||||
|
|
||||||
|
var sut = new CreateSessionHandler(
|
||||||
|
drafts,
|
||||||
|
shared: null!,
|
||||||
|
messenger,
|
||||||
|
NullLogger<CreateSessionHandler>.Instance);
|
||||||
|
|
||||||
|
var payload = new WizardPayload
|
||||||
|
{
|
||||||
|
Type = WizardCreationType.Single,
|
||||||
|
Title = "T",
|
||||||
|
System = "Dnd5e",
|
||||||
|
DurationMinutes = 240,
|
||||||
|
Visibility = WizardVisibility.Public,
|
||||||
|
Single = new WizardSingleInput
|
||||||
|
{
|
||||||
|
ScheduledAt = DateTimeOffset.UtcNow.AddDays(7),
|
||||||
|
MaxPlayers = null,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
var draft = NewDraft(WizardStepNames.Confirm, payload);
|
||||||
|
drafts.Seed(draft);
|
||||||
|
|
||||||
|
await sut.SubmitDraftAsync(draft, CancellationToken.None);
|
||||||
|
|
||||||
|
// Validation must let the no-limit payload through. The shared
|
||||||
|
// handler is null, so anything that reached the database call would
|
||||||
|
// throw a NullReferenceException — that is caught by the retry
|
||||||
|
// path and reported as a "💥 Ошибка:" edit, not a missing-fields
|
||||||
|
// edit. Therefore we assert that NO edit mentions a missing field.
|
||||||
|
Assert.NotEmpty(messenger.Edits);
|
||||||
|
var lastEdit = messenger.Edits[^1].Text;
|
||||||
|
Assert.DoesNotContain("Не заполнены", lastEdit, StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user