< Summary

Information
Class: Services.SupplierStatusServices.Providers.ShateMSupplierStatusProvider
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/SupplierStatusServices/Providers/ShateMSupplierStatusProvider.cs
Line coverage
100%
Covered lines: 28
Uncovered lines: 0
Coverable lines: 28
Total lines: 61
Line coverage: 100%
Branch coverage
93%
Covered branches: 28
Total branches: 30
Branch coverage: 93.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_ProviderKey()100%11100%
FetchCartAsync()100%1616100%
FetchOrderAsync()100%11100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/SupplierStatusServices/Providers/ShateMSupplierStatusProvider.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using Newtonsoft.Json.Linq;
 3using OzonDomains.Models;
 4using OzonDomains.Models.SupplierStatuses;
 5using OzonRepositories.Context;
 6using Services.ApiServices.ShateMApi;
 7
 8namespace Services.SupplierStatusServices.Providers;
 9
 10/// <summary>Сверяет внешнюю корзину и заказы Шате‑М, не меняя статус при ошибке API.</summary>
 11public sealed class ShateMSupplierStatusProvider : ISupplierStatusProvider
 12{
 13    private readonly ApplicationDbContext _db;
 14    private readonly ShateMDataManager _api;
 5015    public ShateMSupplierStatusProvider(ApplicationDbContext db, ShateMDataManager api) => (_db, _api) = (db, api);
 216    public string ProviderKey => ApiSupplierSettings.ShateMProviderKey;
 17
 18    public async Task<IReadOnlyList<SupplierStatusSnapshot>> FetchCartAsync(IReadOnlyList<OrderSupplierStateRef> states,
 19    {
 20        try
 21        {
 1222            var response = await _api.GetAsync("/api/v1/cartitems", null, ct);
 3323            var external = (response as JArray ?? new JArray()).OfType<JObject>().Select(x => x.Value<string>("id")).Whe
 924            var local = await _db.ShateMCartItems.Where(x => states.Select(s => s.OrderId).Contains(x.StudioOrderId) && 
 925            var result = new List<SupplierStatusSnapshot>();
 3826            foreach (var state in states)
 27            {
 2028                var row = local.FirstOrDefault(x => x.StudioOrderId == state.OrderId);
 1029                var exists = row is not null && !string.IsNullOrWhiteSpace(row.ExternalBasketItemId) && external.Contain
 2230                if (!exists && row is not null) { row.Status = ShateMCartItemStatus.Removed; row.ActiveStudioOrderId = n
 1031                result.Add(new SupplierStatusSnapshot { OrderId = state.OrderId, Kind = SupplierStatusKind.Cart, Externa
 32            }
 1833            await _db.SaveChangesAsync(ct); return result;
 34        }
 335        catch (Exception ex) when (ex is ShateMApiException or HttpRequestException or TaskCanceledException)
 36        {
 637            return states.Select(x => new SupplierStatusSnapshot { OrderId = x.OrderId, Kind = SupplierStatusKind.Cart, 
 38        }
 1239    }
 40
 41    public async Task<IReadOnlyList<SupplierStatusSnapshot>> FetchOrderAsync(IReadOnlyList<OrderSupplierStateRef> states
 42    {
 43        try
 44        {
 1245            var response = await _api.GetAsync("/api/v1/orders", new Dictionary<string, string?> { ["page"] = "1", ["pag
 1746            var orders = (response as JArray ?? new JArray()).OfType<JObject>().ToDictionary(x => x.Value<string>("id") 
 947            return states.Select(state =>
 948            {
 1249                var id = state.ExternalOrderId ?? state.ExternalOrderNumber;
 1850                if (string.IsNullOrWhiteSpace(id) || !orders.TryGetValue(id, out var order)) return new SupplierStatusSn
 651                var line = (order["orderItems"] as JArray)?.OfType<JObject>().FirstOrDefault();
 652                var code = line?.Value<string>("statusCode");
 653                return new SupplierStatusSnapshot { OrderId = state.OrderId, Kind = SupplierStatusKind.Order, ExternalCo
 954            }).ToList();
 55        }
 356        catch (Exception ex) when (ex is ShateMApiException or HttpRequestException or TaskCanceledException)
 57        {
 658            return states.Select(x => new SupplierStatusSnapshot { OrderId = x.OrderId, Kind = SupplierStatusKind.Order,
 59        }
 1260    }
 61}