< Summary - Syki

Information
Class: Syki.Back.Features.Webhooks.UpdateWebhookSubscription.UpdateWebhookSubscriptionService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Webhooks/UpdateWebhookSubscription/UpdateWebhookSubscriptionService.cs
Tag: 97_27801654829
Line coverage
0%
Covered lines: 0
Uncovered lines: 17
Coverable lines: 17
Total lines: 33
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
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%
.ctor()0%620%
.cctor()100%210%
Update()0%2040%

File(s)

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

#LineLine coverage
 1namespace Syki.Back.Features.Webhooks.UpdateWebhookSubscription;
 2
 03public class UpdateWebhookSubscriptionService(SykiDbContext ctx) : ISykiService
 4{
 5    private class Validator : AbstractValidator<UpdateWebhookSubscriptionIn>
 6    {
 07        public Validator()
 8        {
 09            RuleFor(x => x.Name).NotEmpty().WithError(InvalidWebhookName.I);
 010            RuleFor(x => x.Name).MaximumLength(100).WithError(InvalidWebhookName.I);
 11
 012            RuleFor(x => x.Url).NotEmpty().WithError(InvalidWebhookUrl.I);
 013            RuleFor(x => x.Url).Must(x => Uri.TryCreate(x, UriKind.Absolute, out _)).WithError(InvalidWebhookUrl.I);
 14
 015            RuleFor(x => x.Events).Must(x => x != null && x.Count > 0).WithError(InvalidWebhookEvents.I);
 016        }
 17    }
 018    private static readonly Validator V = new();
 19
 20    public async Task<OneOf<UpdateWebhookSubscriptionOut, SykiError>> Update(UpdateWebhookSubscriptionIn data)
 21    {
 022        if (V.Run(data, out var error)) return error;
 23
 024        var subscription = await ctx.WebhookSubscriptions
 025            .FirstOrDefaultAsync(x => x.InstitutionId == ctx.RequestUser.InstitutionId && x.Id == data.Id);
 026        if (subscription == null) return WebhookSubscriptionNotFound.I;
 27
 028        subscription.Update(data.Name, data.Url, data.Events, data.IsActive);
 029        await ctx.SaveChangesAsync();
 30
 031        return new UpdateWebhookSubscriptionOut { Id = subscription.Id };
 032    }
 33}