< Summary

Information
Class: Services.ApiServices.ForumAutoApi.ForumAutoPriceMapper
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/ApiServices/ForumAutoApi/ForumAutoPriceMapper.cs
Line coverage
100%
Covered lines: 62
Uncovered lines: 0
Coverable lines: 62
Total lines: 87
Line coverage: 100%
Branch coverage
84%
Covered branches: 22
Total branches: 26
Branch coverage: 84.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Map(...)84.61%2626100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/ApiServices/ForumAutoApi/ForumAutoPriceMapper.cs

#LineLine coverage
 1using System.Globalization;
 2using Newtonsoft.Json.Linq;
 3using OzonDomains;
 4using Services.ApiServices.TradesoftApi.Models.Response;
 5
 6namespace Services.ApiServices.ForumAutoApi;
 7
 8public static class ForumAutoPriceMapper
 9{
 10    public static IReadOnlyList<PreOrderItem> Map(JToken response, string requestedArticle,
 11        int? preferredSupplierId, CurrencyCode? preferredSupplierCurrency,
 12        string accountKey = "ForumAuto", string title = "Форум-Авто")
 13    {
 1314        var items = new List<PreOrderItem>();
 1315        var requested = requestedArticle.Trim();
 5016        foreach (var row in response.OfType<JObject>())
 17        {
 1218            var article = row.Value<string>("art") ?? string.Empty;
 19            // Контракт "только оригиналы запрошенного артикула" — фильтруем даже если сервер
 20            // при cross=0 всё же вернёт что-то ещё.
 1221            if (!string.Equals(article.Trim(), requested, StringComparison.OrdinalIgnoreCase))
 22                continue;
 23
 1124            var price = row.Value<decimal?>("price");
 1125            if (price is null) continue;
 26
 1127            var gid = row.Value<string>("gid") ?? string.Empty;
 1128            var brand = row.Value<string>("brand") ?? string.Empty;
 1129            var name = row.Value<string>("name") ?? article;
 1130            var num = row.Value<int?>("num") ?? 0;
 1131            var kr = row.Value<int?>("kr") ?? 1;
 1132            var whse = row.Value<string>("whse");
 1133            var isReturnable = row.Value<int?>("is_returnable") == 1;
 1134            var dDeliv = row.Value<int?>("d_deliv") ?? 0;
 1135            var hDeliv = row.Value<int?>("h_deliv");
 36
 1137            var minDays = dDeliv;
 1138            var maxDays = hDeliv is > 0 ? dDeliv + (int)Math.Ceiling(hDeliv.Value / 24.0) : dDeliv;
 39
 1140            var direction = string.IsNullOrWhiteSpace(whse) ? "Москва" : whse;
 41
 1142            items.Add(new PreOrderItem
 1143            {
 1144                Caption = name,
 1145                Producer = brand,
 1146                Code = article,
 1147                Rest = num.ToString(CultureInfo.InvariantCulture),
 1148                MinQuantity = kr,
 1149                DeliveryDays = minDays.ToString(CultureInfo.InvariantCulture),
 1150                DeliveryDaysMin = minDays,
 1151                DeliveryDaysMax = maxDays,
 1152                Price = price.Value.ToString("0.##", CultureInfo.InvariantCulture),
 1153                CostPrice = price.Value.ToString("0.##", CultureInfo.InvariantCulture),
 1154                CostPriceFormatted = price.Value.ToString("0.##", CultureInfo.InvariantCulture),
 1155                CurrencyCode = "RUB",
 1156                SourcePrice = price,
 1157                SourceCurrencyCode = "RUB",
 1158                Direction = direction,
 1159                Title = title,
 1160                SiteUrl = "https://itrade.forum-auto.ru/",
 1161                ItemId = gid,
 1162                // Каталог Forum-Auto общий для всех аккаунтов — gid один и тот же для «Союза»
 1163                // и «Интерпартс», поэтому хэш строки замешивает accountKey, иначе строки двух
 1164                // аккаунтов в общей таблице проценки схлопнутся по одинаковому ItemHash.
 1165                ItemHash = $"{accountKey}:{gid}".GetHashCode(StringComparison.Ordinal).ToString("X", CultureInfo.Invaria
 1166                Description = string.Join("; ", new[]
 1167                {
 1168                    $"Артикул: {article}", $"Бренд: {brand}", $"Склад: {direction}",
 1169                    $"Наличие: {num}", $"Срок: {minDays}–{maxDays} дн.",
 1170                    isReturnable ? "Возврат: разрешён" : "Возврат: не разрешён"
 1171                }),
 1172                PriceDescription = $"Цена {title}: {price.Value:0.##} RUB",
 1173                PreferredSupplierId = preferredSupplierId,
 1174                PreferredSupplierCurrencyCode = preferredSupplierCurrency?.ToString(),
 1175                ProviderData = new Dictionary<string, string?>
 1176                {
 1177                    ["providerKey"] = accountKey,
 1178                    // Переиспользуем общий UI-маркер "условия поставки" (иконка у направления,
 1179                    // как у ML-Auto) — единственный универсальный канал донести факт невозврата
 1180                    // до строки таблицы проценки без правок разметки.
 1181                    ["deliveryConditions"] = isReturnable ? null : "Товар невозвратный"
 1182                }
 1183            });
 84        }
 1385        return items;
 86    }
 87}