< Summary - Estud

Information
Class: Estud.Back.Features.Webhooks.UpdateWebhookSubscription.UpdateWebhookSubscriptionService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Webhooks/UpdateWebhookSubscription/UpdateWebhookSubscriptionService.cs
Tag: 114_29044117136
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 37
Line coverage: 100%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.ctor()50%22100%
.cctor()100%11100%
Update()100%44100%

File(s)

/home/runner/work/syki/syki/Back/Features/Webhooks/UpdateWebhookSubscription/UpdateWebhookSubscriptionService.cs

#LineLine coverage
 1using Estud.Back.Domain.Webhooks;
 2
 3namespace Estud.Back.Features.Webhooks.UpdateWebhookSubscription;
 4
 165public class UpdateWebhookSubscriptionService(EstudDbContext ctx) : IEstudService
 6{
 7    private class Validator : AbstractValidator<UpdateWebhookSubscriptionIn>
 8    {
 29        public Validator()
 10        {
 211            RuleFor(x => x.Name).NotEmpty().WithError(InvalidWebhookName.I);
 212            RuleFor(x => x.Name).MaximumLength(100).WithError(InvalidWebhookName.I);
 13
 214            RuleFor(x => x.Url).NotEmpty().WithError(InvalidWebhookUrl.I);
 1815            RuleFor(x => x.Url).Must(x => Uri.TryCreate(x, UriKind.Absolute, out _)).WithError(InvalidWebhookUrl.I);
 16
 1817            RuleFor(x => x.Events).Must(x => x != null && x.Count > 0).WithError(InvalidWebhookEvents.I);
 18
 219            RuleFor(x => x.CustomHeaders).Must(WebhookCustomHeaders.IsValid).WithError(InvalidWebhookCustomHeaders.I);
 220        }
 21    }
 222    private static readonly Validator V = new();
 23
 24    public async Task<OneOf<UpdateWebhookSubscriptionOut, EstudError>> Update(UpdateWebhookSubscriptionIn data)
 25    {
 2826        if (V.Run(data, out var error)) return error;
 27
 428        var subscription = await ctx.WebhookSubscriptions
 429            .FirstOrDefaultAsync(x => x.InstitutionId == ctx.RequestUser.InstitutionId && x.Id == data.Id);
 630        if (subscription == null) return WebhookSubscriptionNotFound.I;
 31
 232        subscription.Update(data.Name, data.Url, data.Events, data.CustomHeaders, data.IsActive);
 233        await ctx.SaveChangesAsync();
 34
 235        return new UpdateWebhookSubscriptionOut { Id = subscription.Id };
 1636    }
 37}