< Summary

Information
Class: RaidLoop.Client.Services.ProfileApiClient
Assembly: RaidLoop.Client
File(s): /home/runner/work/RaidLoop/RaidLoop/src/RaidLoop.Client/Services/ProfileApiClient.cs
Line coverage
100%
Covered lines: 23
Uncovered lines: 0
Coverable lines: 23
Total lines: 49
Line coverage: 100%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

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

File(s)

/home/runner/work/RaidLoop/RaidLoop/src/RaidLoop.Client/Services/ProfileApiClient.cs

#LineLine coverage
 1using System.Net.Http.Headers;
 2using System.Net.Http.Json;
 3using System.Text.Json;
 4using RaidLoop.Client.Configuration;
 5using RaidLoop.Core.Contracts;
 6
 7namespace RaidLoop.Client.Services;
 8
 9public sealed class ProfileApiClient : IProfileApiClient
 10{
 111    private static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web);
 12
 13    private readonly HttpClient _httpClient;
 14    private readonly ISupabaseSessionProvider _sessionProvider;
 15    private readonly string _publishableKey;
 16
 317    public ProfileApiClient(
 318        HttpClient httpClient,
 319        ISupabaseSessionProvider sessionProvider,
 320        SupabaseOptions options)
 21    {
 322        _httpClient = httpClient;
 323        _sessionProvider = sessionProvider;
 324        _publishableKey = options.PublishableKey;
 325    }
 26
 27    public async Task<AuthBootstrapResponse> BootstrapAsync(CancellationToken cancellationToken = default)
 28    {
 129        using var request = new HttpRequestMessage(HttpMethod.Post, "profile-bootstrap")
 130        {
 131            Content = JsonContent.Create(new { }, options: JsonOptions)
 132        };
 33
 134        await AuthorizeAsync(request);
 35
 136        using var response = await _httpClient.SendAsync(request, cancellationToken);
 137        response.EnsureSuccessStatusCode();
 38
 139        var payload = await response.Content.ReadFromJsonAsync<AuthBootstrapResponse>(JsonOptions, cancellationToken);
 140        return payload ?? throw new InvalidOperationException("Profile bootstrap returned no payload.");
 141    }
 42
 43    private async Task AuthorizeAsync(HttpRequestMessage request)
 44    {
 145        var accessToken = await _sessionProvider.GetAccessTokenAsync();
 146        request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
 147        request.Headers.Add("apikey", _publishableKey);
 148    }
 49}