< Summary - Estud

Information
Class: Estud.Back.Features.Webhooks.CreateWebhookSubscription.CreateWebhookSubscriptionService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Webhooks/CreateWebhookSubscription/CreateWebhookSubscriptionService.cs
Tag: 114_29044117136
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 33
Line coverage: 100%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
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%
Create()100%22100%

File(s)

/home/runner/work/syki/syki/Back/Features/Webhooks/CreateWebhookSubscription/CreateWebhookSubscriptionService.cs

#LineLine coverage
 1using Estud.Back.Domain.Webhooks;
 2
 3namespace Estud.Back.Features.Webhooks.CreateWebhookSubscription;
 4
 365public class CreateWebhookSubscriptionService(EstudDbContext ctx) : IEstudService
 6{
 7    private class Validator : AbstractValidator<CreateWebhookSubscriptionIn>
 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);
 3815            RuleFor(x => x.Url).Must(x => Uri.TryCreate(x, UriKind.Absolute, out _)).WithError(InvalidWebhookUrl.I);
 16
 3817            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<CreateWebhookSubscriptionOut, EstudError>> Create(CreateWebhookSubscriptionIn data)
 25    {
 4826        if (V.Run(data, out var error)) return error;
 27
 2428        var subscription = new WebhookSubscription(ctx.RequestUser.InstitutionId, data.Name, data.Url, data.Events, data
 2429        await ctx.SaveChangesAsync(subscription);
 30
 2431        return new CreateWebhookSubscriptionOut { Id = subscription.Id };
 3632    }
 33}