< Summary

Information
Class: Elsa.Tenants.Endpoints.Tenants.Update.Endpoint
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: 17
Coverable lines: 17
Total lines: 43
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
Configure()100%210%
HandleAsync()0%2040%

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
 08public class Endpoint(ITenantService tenantService, ITenantStore tenantStore) : ElsaEndpoint<UpdatedTenant, Tenant>
 9{
 10    public override void Configure()
 11    {
 012        Post("/tenants/{id}");
 013        ConfigurePermissions("write:tenants");
 014    }
 15
 16    public override async Task HandleAsync(UpdatedTenant req, CancellationToken ct)
 17    {
 018        var id = Route<string>("id")!;
 019        if (id == "-") id = string.Empty;
 020        var tenant = await tenantStore.FindAsync(id, ct);
 21
 022        if (tenant == null)
 23        {
 024            await Send.NotFoundAsync(ct);
 025            return;
 26        }
 27
 028        tenant.TenantId = req.TenantId;
 029        tenant.Name = req.Name.Trim();
 030        tenant.Configuration = Serializers.DeserializeConfiguration(req.Configuration);
 031        await tenantStore.UpdateAsync(tenant, ct);
 032        await tenantService.RefreshAsync(ct);
 033        await Send.OkAsync(tenant, ct);
 034    }
 35}
 36
 37public class UpdatedTenant
 38{
 39    public string Id { get; set; } = default!;
 40    public string? TenantId { get; set; }
 41    public string Name { get; set; } = default!;
 42    public JsonElement? Configuration { get; set; }
 43}