< Summary - Syki

Information
Class: Syki.Back.Features.Webhooks.CreateWebhookSubscription.CreateWebhookSubscriptionService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Webhooks/CreateWebhookSubscription/CreateWebhookSubscriptionService.cs
Tag: 97_27801654829
Line coverage
0%
Covered lines: 0
Uncovered lines: 14
Coverable lines: 14
Total lines: 31
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%
.ctor()0%620%
.cctor()100%210%
Create()0%620%

File(s)

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

#LineLine coverage
 1using Syki.Back.Domain.Webhooks;
 2
 3namespace Syki.Back.Features.Webhooks.CreateWebhookSubscription;
 4
 05public class CreateWebhookSubscriptionService(SykiDbContext ctx) : ISykiService
 6{
 7    private class Validator : AbstractValidator<CreateWebhookSubscriptionIn>
 8    {
 09        public Validator()
 10        {
 011            RuleFor(x => x.Name).NotEmpty().WithError(InvalidWebhookName.I);
 012            RuleFor(x => x.Name).MaximumLength(100).WithError(InvalidWebhookName.I);
 13
 014            RuleFor(x => x.Url).NotEmpty().WithError(InvalidWebhookUrl.I);
 015            RuleFor(x => x.Url).Must(x => Uri.TryCreate(x, UriKind.Absolute, out _)).WithError(InvalidWebhookUrl.I);
 16
 017            RuleFor(x => x.Events).Must(x => x != null && x.Count > 0).WithError(InvalidWebhookEvents.I);
 018        }
 19    }
 020    private static readonly Validator V = new();
 21
 22    public async Task<OneOf<CreateWebhookSubscriptionOut, SykiError>> Create(CreateWebhookSubscriptionIn data)
 23    {
 024        if (V.Run(data, out var error)) return error;
 25
 026        var subscription = new WebhookSubscription(ctx.RequestUser.InstitutionId, data.Name, data.Url, data.Events);
 027        await ctx.SaveChangesAsync(subscription);
 28
 029        return new CreateWebhookSubscriptionOut { Id = subscription.Id };
 030    }
 31}