< Summary

Information
Class: Elsa.Tenants.Endpoints.Tenants.Update.UpdatedTenant
Assembly: Elsa.Tenants
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Tenants/Endpoints/Tenants/Update/Endpoint.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 4
Coverable lines: 4
Total lines: 43
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Id()100%210%
get_TenantId()100%210%
get_Name()100%210%
get_Configuration()100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Tenants/Endpoints/Tenants/Update/Endpoint.cs

#LineLine coverage
 1using System.Text.Json;
 2using Elsa.Abstractions;
 3using Elsa.Common.Multitenancy;
 4using Elsa.Common.Serialization;
 5
 6namespace Elsa.Tenants.Endpoints.Tenants.Update;
 7
 8public class Endpoint(ITenantService tenantService, ITenantStore tenantStore) : ElsaEndpoint<UpdatedTenant, Tenant>
 9{
 10    public override void Configure()
 11    {
 12        Post("/tenants/{id}");
 13        ConfigurePermissions("write:tenants");
 14    }
 15
 16    public override async Task HandleAsync(UpdatedTenant req, CancellationToken ct)
 17    {
 18        var id = Route<string>("id")!;
 19        if (id == "-") id = string.Empty;
 20        var tenant = await tenantStore.FindAsync(id, ct);
 21
 22        if (tenant == null)
 23        {
 24            await Send.NotFoundAsync(ct);
 25            return;
 26        }
 27
 28        tenant.TenantId = req.TenantId;
 29        tenant.Name = req.Name.Trim();
 30        tenant.Configuration = Serializers.DeserializeConfiguration(req.Configuration);
 31        await tenantStore.UpdateAsync(tenant, ct);
 32        await tenantService.RefreshAsync(ct);
 33        await Send.OkAsync(tenant, ct);
 34    }
 35}
 36
 37public class UpdatedTenant
 38{
 039    public string Id { get; set; } = default!;
 040    public string? TenantId { get; set; }
 041    public string Name { get; set; } = default!;
 042    public JsonElement? Configuration { get; set; }
 43}