< Summary

Line coverage
31%
Covered lines: 10
Uncovered lines: 22
Coverable lines: 32
Total lines: 129
Line coverage: 31.2%
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
File 1: LeasePendingJobs()0%620%
File 2: Initialize(...)100%11100%

File(s)

/home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/Jobs/Mutations/LeaseJobsMutation.cs

#LineLine coverage
 1// SPDX-FileCopyrightText: 2026 Alper Çelik <alper@alper-celik.dev>
 2//
 3// SPDX-License-Identifier: AGPL-3.0-or-later
 4
 5using System.Diagnostics;
 6using Api.Auth.Handlers;
 7using Api.Auth.Utils;
 8using Api.Database;
 9using Api.Database.Utils;
 10using Api.Jobs.DTOs;
 11using Api.Utils;
 12using FluentValidation;
 13using HotChocolate.Authorization;
 14using Microsoft.EntityFrameworkCore;
 15
 16namespace Api.Jobs.Mutations;
 17
 18public record LeasePendingJobsInput(string[] JobTypes, int MaxJobs);
 19
 20public record LeasePendingJobsPayload(ILeasedJob[] Jobs);
 21
 22[MutationType]
 23public static partial class LeaseJobMutations
 24{
 25    [Authorize(PermissionPolicyProvider.RemoteServicePolicyName)]
 26    // TODO: remove once the Jobs slice is wired: there is no IJobsInterfae implementation and no
 27    // object type implementing ILeasedJob yet, which breaks schema validation and the generated
 28    // ZeroQL client. Re-add the [InterfaceType] attributes and validate the input explicitly
 29    // (validator.ValidateOrThrowInputAsync) at that point.
 30    [GraphQLIgnore]
 31    public static async Task<LeasePendingJobsPayload> LeasePendingJobs(
 32        [Service] ICurrentServiceId idGetter,
 33        [Service] IEFTransactionDIAccessorService tx,
 34        [Service] IJobsInterfae jobsInterfae,
 35        [Service] JobDTOBuilder j,
 36        LeasePendingJobsInput input,
 37        CancellationToken ct
 38    )
 039    {
 040        await tx.BeginOrGetTransactionAsync();
 041        var jobDatas = await jobsInterfae.LeasePendingJobs(
 042            0,
 043            (uint)input.MaxJobs,
 044            idGetter.Id ?? throw new ArgumentNullException(nameof(idGetter)),
 045            input.JobTypes,
 046            ct
 047        );
 048        var jobs = jobDatas
 049            .Select(jd =>
 050                (
 051                    j.CreateFrom(jd.JobType, jd)
 052                    ?? throw new UnreachableException(
 053                        "There must not exist a job with a unregistered type"
 054                    )
 055                ).AsLeased()
 056            )
 057            .ToArray();
 58
 059        await tx.SaveAndCommitTX(ct);
 60
 061        return new LeasePendingJobsPayload(jobs);
 062    }
 63}
 64
 65public class LeasePendingJobsInputValidator : AbstractValidator<LeasePendingJobsInput>
 66{
 67    public LeasePendingJobsInputValidator(
 68        PGContext db,
 69        IEFTransactionDIAccessorService tx,
 70        ICurrentServiceId idGetter
 71    )
 72    {
 73        RuleFor(i => i).BeginTransaction(tx);
 74
 75        RuleFor(i => i.MaxJobs).GreaterThan(0).LessThan(128);
 76
 77        RuleFor(i => i.JobTypes)
 78            .MustAsync(
 79                async (_, jobTypes, ctx, ct) =>
 80                    await db
 81                        .RemoteServices.Where(s => s.Id == idGetter.Id)
 82                        .Select(s => s.AllowedJobs)
 83                        .Select(allowedTypes =>
 84                            jobTypes.All(jt => allowedTypes.Contains(jt))
 85                        )
 86                        .FirstOrDefaultAsync(ct)
 87            );
 88    }
 89}

/home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/obj/Debug/net10.0/generated/HotChocolate.Types.Analyzers/HotChocolate.Types.Analyzers.GraphQLServerGenerator/LeaseJobMutations.rdOiUQx5nWfMMZK3Xv4tgw.hc.g.cs

#LineLine coverage
 1// <auto-generated/>
 2
 3#nullable enable
 4#pragma warning disable
 5
 6using System;
 7using System.Runtime.CompilerServices;
 8using HotChocolate;
 9using HotChocolate.Types;
 10using HotChocolate.Execution.Configuration;
 11using Microsoft.Extensions.DependencyInjection;
 12using HotChocolate.Internal;
 13
 14namespace Api.Jobs.Mutations
 15{
 16    public static partial class LeaseJobMutations
 17    {
 18        internal static void Initialize(global::HotChocolate.Types.IObjectTypeDescriptor descriptor)
 119        {
 120            var extension = descriptor.Extend();
 121            var configuration = extension.Configuration;
 22
 123            HotChocolate.Internal.ConfigurationHelper.ApplyConfiguration(
 124                extension.Context,
 125                descriptor,
 126                typeof(global::Api.Jobs.Mutations.LeaseJobMutations),
 127                new global::HotChocolate.Types.MutationTypeAttribute());
 128            configuration.ConfigurationsAreApplied = true;
 29
 30            Configure(descriptor);
 131        }
 32
 33        static partial void Configure(global::HotChocolate.Types.IObjectTypeDescriptor descriptor);
 34
 35        private sealed class __Resolvers
 36        {
 37        }
 38    }
 39}
 40