< Summary

Class:UserProfileModel
Assembly:UserProfile
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/UserProfile/UserProfileModel.cs
Covered lines:13
Uncovered lines:57
Coverable lines:70
Total lines:190
Line coverage:18.5% (13 of 70)
Covered branches:0
Total branches:0
Covered methods:5
Total methods:14
Method coverage:35.7% (5 of 14)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Link()0%2100%
Link(...)0%110100%
Equals(...)0%6200%
Equals(...)0%6200%
GetHashCode()0%2100%
Equals(...)0%20400%
Equals(...)0%30500%
UserProfileModel()0%110100%
Clone()0%2100%
FallbackModel(...)0%2100%
Equals(...)0%13323600%
ComposeCorrectUrl(...)0%4.134080%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/UserProfile/UserProfileModel.cs

#LineLine coverage
 1using DCL.UserProfiles;
 2using System;
 3using System.Collections.Generic;
 4
 5[Serializable]
 6public class UserProfileModel
 7{
 8    [Serializable]
 9    public class Link
 10    {
 11        public string title;
 12        public string url;
 13
 014        public Link()
 15        {
 016        }
 17
 2718        public Link(string title, string url)
 19        {
 2720            this.title = title;
 2721            this.url = url;
 2722        }
 23
 24        public override bool Equals(object obj) =>
 025            obj is Link link && Equals(link);
 26
 27        private bool Equals(Link other) =>
 028            title == other.title && url == other.url;
 29
 30        public override int GetHashCode() =>
 031            HashCode.Combine(title, url);
 32    }
 33
 34    [Serializable]
 35    public class Snapshots
 36    {
 37        public string face256;
 38        public string body;
 39
 40        public bool Equals(Snapshots snapshots)
 41        {
 042            if (snapshots == null) return false;
 043            if (snapshots.face256 != face256) return false;
 044            if (snapshots.body != body) return false;
 045            return true;
 46        }
 47    }
 48
 49    [Serializable]
 50    public class ParcelsWithAccess
 51    {
 52        public int x;
 53        public int y;
 54        public LandRole landRole;
 55
 56        [Serializable]
 57        public enum LandRole
 58        {
 59            OWNER = 0,
 60            OPERATOR = 1
 61        }
 62
 63        public bool Equals(ParcelsWithAccess parcelsWithAccess)
 64        {
 065            if (parcelsWithAccess == null) return false;
 066            if (parcelsWithAccess.x != x) return false;
 067            if (parcelsWithAccess.y != y) return false;
 068            if (parcelsWithAccess.landRole != landRole) return false;
 069            return true;
 70        }
 71    }
 72
 73    public string userId;
 74    public string ethAddress;
 75    public string name;
 76    public string email;
 77    public string description;
 78    public string baseUrl;
 79    public ParcelsWithAccess[] parcelsWithAccess;
 80    public ulong created_at;
 81    public ulong updated_at;
 82    public int version;
 83    public AvatarModel avatar;
 148184    public Snapshots snapshots = new ();
 085    public UserProfileModel Clone() => (UserProfileModel)MemberwiseClone();
 86
 148187    public bool hasConnectedWeb3 = true;
 88
 89    public int tutorialFlagsMask;
 148190    public List<string> blocked = new ();
 148191    public List<string> muted = new ();
 92    public int tutorialStep;
 93    public bool hasClaimedName;
 94    public List<Link> links;
 299595    public AdditionalInfo AdditionalInfo { get; set; } = new ();
 96
 97    public static UserProfileModel FallbackModel(string name, int id)
 98    {
 099        var fallbackId = $"{name}_{id}";
 100
 0101        return new UserProfileModel
 102        {
 103            // Required fields (otherwise exceptions will be thrown by UserProfile.OnUpdate subscribers)
 104            userId = fallbackId,
 105            name = name,
 106            description = "There was a problem with loading this profile. This is a fallback profile",
 107
 108            avatar = AvatarModel.FallbackModel(name, id),
 109
 110            // Optional (exceptions-free) fields
 111            ethAddress = fallbackId,
 112            email = fallbackId,
 113            baseUrl = fallbackId,
 114        };
 115    }
 116
 117    public bool Equals(UserProfileModel model)
 118    {
 0119        if (model == null) return false;
 0120        if (model.userId != userId) return false;
 0121        if (model.ethAddress != ethAddress) return false;
 0122        if (model.name != name) return false;
 0123        if (model.email != email) return false;
 0124        if (model.description != description) return false;
 0125        if (model.baseUrl != baseUrl) return false;
 0126        if (model.created_at != created_at) return false;
 0127        if (model.updated_at != updated_at) return false;
 0128        if (model.version != version) return false;
 0129        if (!model.avatar.Equals(avatar)) return false;
 130
 0131        if (model.parcelsWithAccess != null)
 132        {
 0133            if (!model.parcelsWithAccess.Equals(parcelsWithAccess))
 0134                return false;
 135        }
 0136        else if (parcelsWithAccess != null)
 0137            return false;
 138
 0139        if (model.hasConnectedWeb3 != hasConnectedWeb3) return false;
 0140        if (model.tutorialFlagsMask != tutorialFlagsMask) return false;
 0141        if (model.tutorialFlagsMask != tutorialFlagsMask) return false;
 142
 0143        if (model.blocked != null && blocked != null)
 144        {
 145            // We're comparing only the lenght of the 'blocked' list because we found several cases where it is too big 
 146            // Also, taking into account that this list should be removed from the profile data in the catalysts, we dec
 0147            if (model.blocked.Count != blocked.Count)
 0148                return false;
 149        }
 0150        else if (model.blocked != null || blocked != null)
 0151            return false;
 152
 0153        if (model.muted != null && muted != null)
 154        {
 155            // We're comparing only the lenght of the 'muted' list because we found several cases where it is too big an
 156            // Also, taking into account that this list should be removed from the profile data in the catalysts, we dec
 0157            if (model.muted.Count != muted.Count)
 0158                return false;
 159        }
 0160        else if (model.muted != null || muted != null)
 0161            return false;
 162
 0163        if (model.tutorialStep != tutorialStep) return false;
 0164        if (model.hasClaimedName != hasClaimedName) return false;
 165
 0166        if (model.links != null && links != null)
 167        {
 0168            if (model.links.Count != links.Count)
 0169                return false;
 170        }
 0171        else if (model.links != null || links != null)
 0172            return false;
 173
 0174        if (!AdditionalInfo.Equals(model.AdditionalInfo))
 0175            return false;
 176
 0177        return true;
 178    }
 179
 180    public string ComposeCorrectUrl(string url)
 181    {
 130182        if (string.IsNullOrEmpty(url))
 68183            return url;
 184
 62185        if (!url.StartsWith("Qm") && !url.StartsWith("ba"))
 62186            return url;
 187
 0188        return baseUrl + url;
 189    }
 190}