< Summary

Class:EmotesCatalogServiceProxy
Assembly:EmotesCatalog
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/EmotesCatalog/EmotesCatalogService/EmotesCatalogServiceProxy.cs
Covered lines:26
Uncovered lines:30
Coverable lines:56
Total lines:141
Line coverage:46.4% (26 of 56)
Covered branches:0
Total branches:0
Covered methods:7
Total methods:20
Method coverage:35% (7 of 20)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
EmotesCatalogServiceProxy(...)0%110100%
Initialize()0%2.52050%
<CheckFeatureFlag()0%3.333066.67%
CheckFeatureFlag(...)0%2.032080%
SetCurrentService(...)0%2.022083.33%
Dispose()0%2.52050%
TryGetLoadedEmote(...)0%6200%
RequestEmoteFromBuilderAsync()0%42600%
RequestOwnedEmotes(...)0%2100%
RequestOwnedEmotesAsync(...)0%2100%
RequestEmoteCollectionAsync()0%42600%
RequestEmote(...)0%2100%
RequestEmotes(...)0%2100%
RequestEmoteAsync(...)0%2100%
RequestEmotesAsync(...)0%2100%
GetEmbeddedEmotes()0%660100%
RequestEmoteCollectionInBuilderAsync()0%42600%
ForgetEmote(...)0%2100%
ForgetEmotes(...)0%2100%
TryGetOwnedUrn(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/EmotesCatalog/EmotesCatalogService/EmotesCatalogServiceProxy.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL.Emotes;
 3using DCL.Helpers;
 4using DCLServices.EmotesCatalog.EmotesCatalogService;
 5using System.Collections.Generic;
 6using System.Threading;
 7
 8public class EmotesCatalogServiceProxy : IEmotesCatalogService
 9{
 10    private const string FORCE_TO_REQUEST_WEARABLES_THROUGH_KERNEL_FF = "force_to_request_wearables_through_kernel";
 11
 12    private readonly LambdasEmotesCatalogService lambdasEmotesCatalogService;
 13    private readonly WebInterfaceEmotesCatalogService webInterfaceEmotesCatalogService;
 14    private readonly KernelConfig kernelConfig;
 15    private readonly BaseVariable<FeatureFlag> featureFlags;
 16    private IEmotesCatalogService emotesCatalogServiceInUse;
 17    private bool isInitialized;
 18
 4019    public EmotesCatalogServiceProxy(LambdasEmotesCatalogService lambdasEmotesCatalogService,
 20        WebInterfaceEmotesCatalogService webInterfaceEmotesCatalogService,
 21        BaseVariable<FeatureFlag> featureFlags, KernelConfig kernelCofig)
 22    {
 4023        this.lambdasEmotesCatalogService = lambdasEmotesCatalogService;
 4024        this.webInterfaceEmotesCatalogService = webInterfaceEmotesCatalogService;
 4025        this.featureFlags = featureFlags;
 4026        this.kernelConfig = kernelCofig;
 4027    }
 28
 29    public void Initialize()
 30    {
 4031        if (!featureFlags.Get().IsInitialized)
 4032            featureFlags.OnChange += CheckFeatureFlag;
 33        else
 034            CheckFeatureFlag(featureFlags.Get());
 035    }
 36
 37    private void CheckFeatureFlag(FeatureFlag currentFeatureFlags, FeatureFlag _ = null)
 38    {
 39        async UniTaskVoid SetServiceInUseDependingOnKernelConfig()
 40        {
 1141            var currentKernelConfig = kernelConfig.EnsureConfigInitialized();
 1142            await currentKernelConfig;
 1143            SetCurrentService(currentKernelConfig.value.urlParamsForWearablesDebug);
 1144        }
 45
 1146        featureFlags.OnChange -= CheckFeatureFlag;
 47
 1148        if (currentFeatureFlags.IsFeatureEnabled(FORCE_TO_REQUEST_WEARABLES_THROUGH_KERNEL_FF))
 049            SetCurrentService(true);
 50        else
 1151            SetServiceInUseDependingOnKernelConfig().Forget();
 1152    }
 53
 54    private void SetCurrentService(bool useKernel)
 55    {
 1156        if (useKernel)
 057            emotesCatalogServiceInUse = webInterfaceEmotesCatalogService;
 58        else
 1159            emotesCatalogServiceInUse = lambdasEmotesCatalogService;
 60
 1161        emotesCatalogServiceInUse.Initialize();
 1162        isInitialized = true;
 1163    }
 64
 65    public void Dispose()
 66    {
 4067        emotesCatalogServiceInUse?.Dispose();
 068    }
 69
 70    public bool TryGetLoadedEmote(string id, out WearableItem emote)
 71    {
 072        if (!isInitialized)
 73        {
 074            emote = null;
 075            return false;
 76        }
 77
 078        return emotesCatalogServiceInUse.TryGetLoadedEmote(id, out emote);
 79    }
 80
 81    public async UniTask<WearableItem> RequestEmoteFromBuilderAsync(string emoteId, CancellationToken cancellationToken)
 82    {
 083        if (!isInitialized)
 084            await UniTask.WaitUntil(() => isInitialized, cancellationToken: cancellationToken);
 85
 086        return await lambdasEmotesCatalogService.RequestEmoteFromBuilderAsync(emoteId, cancellationToken);
 087    }
 88
 89    public Promise<IReadOnlyList<WearableItem>> RequestOwnedEmotes(string userId) =>
 090        emotesCatalogServiceInUse.RequestOwnedEmotes(userId);
 91
 92    public UniTask<IReadOnlyList<WearableItem>> RequestOwnedEmotesAsync(string userId, CancellationToken ct = default) =
 093        emotesCatalogServiceInUse.RequestOwnedEmotesAsync(userId, ct);
 94
 95    public async UniTask<IReadOnlyList<WearableItem>> RequestEmoteCollectionAsync(IEnumerable<string> collectionIds,
 96        CancellationToken cancellationToken, List<WearableItem> emoteBuffer = null)
 97    {
 098        if (!isInitialized)
 099            await UniTask.WaitUntil(() => isInitialized, cancellationToken: cancellationToken);
 100
 0101        return await lambdasEmotesCatalogService.RequestEmoteCollectionAsync(collectionIds, cancellationToken, emoteBuff
 0102    }
 103
 104    public Promise<WearableItem> RequestEmote(string id) =>
 0105        emotesCatalogServiceInUse.RequestEmote(id);
 106
 107    public List<Promise<WearableItem>> RequestEmotes(IList<string> ids) =>
 0108        emotesCatalogServiceInUse.RequestEmotes(ids);
 109
 110    public UniTask<WearableItem> RequestEmoteAsync(string id, CancellationToken ct = default) =>
 0111        emotesCatalogServiceInUse.RequestEmoteAsync(id, ct);
 112
 113    public UniTask<IReadOnlyList<WearableItem>> RequestEmotesAsync(IList<string> ids, CancellationToken ct = default) =>
 0114        emotesCatalogServiceInUse.RequestEmotesAsync(ids, ct);
 115
 116    public async UniTask<EmbeddedEmotesSO> GetEmbeddedEmotes()
 117    {
 40118        if (!isInitialized)
 475014119            await UniTask.WaitUntil(() => isInitialized);
 120
 33121        return await emotesCatalogServiceInUse.GetEmbeddedEmotes();
 11122    }
 123
 124    public async UniTask<IReadOnlyList<WearableItem>> RequestEmoteCollectionInBuilderAsync(IEnumerable<string> collectio
 125        CancellationToken cancellationToken, List<WearableItem> emoteBuffer = null)
 126    {
 0127        if (!isInitialized)
 0128            await UniTask.WaitUntil(() => isInitialized, cancellationToken: cancellationToken);
 129
 0130        return await lambdasEmotesCatalogService.RequestEmoteCollectionInBuilderAsync(collectionIds, cancellationToken, 
 0131    }
 132
 133    public void ForgetEmote(string id) =>
 0134        emotesCatalogServiceInUse.ForgetEmote(id);
 135
 136    public void ForgetEmotes(IList<string> ids) =>
 0137        emotesCatalogServiceInUse.ForgetEmotes(ids);
 138
 139    public bool TryGetOwnedUrn(string shortenedUrn, out string extendedUrn) =>
 0140        emotesCatalogServiceInUse.TryGetOwnedUrn(shortenedUrn, out extendedUrn);
 141}