Skip to content

Commit

Permalink
feat(metadata): replace DiscordAccount with DiscordLink
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-manole committed Sep 25, 2023
1 parent 392919c commit 5d47037
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/Plutus/Certification/Metadata/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,15 @@ instance ToSchema CertificationType where
type GitHubAccount = DB.PatternedText "GitHubAccount"
"^(?=.{1,39}$)[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$"

type DiscordAccount = DB.PatternedText "DiscordAccount"
"^.{3,32}#[0-9]{4}$"
type DiscordLink = DB.PatternedText "DiscordLink"
"^(?:https?:\\/\\/)?discord(?:\\.gg|app\\.com\\/invite|\\.com\\/invite)\\/[\\w-]+$"

data Social = Social
{ twitter :: !(Maybe DB.Twitter)
, github :: !(Maybe GitHubAccount)
, contact :: !DB.Email
, website :: !DB.Website
, discord :: !(Maybe DiscordAccount)
, discord :: !(Maybe DiscordLink)
} deriving (Show, Eq, Generic)

instance ToJSON Social where
Expand All @@ -281,7 +281,7 @@ instance ToSchema Social where
uriSchema <- declareSchemaRef (Proxy :: Proxy DB.Website)
twitterSchema <- declareSchemaRef (Proxy :: Proxy DB.Twitter)
githubSchema <- declareSchemaRef (Proxy :: Proxy GitHubAccount)
discordSchema <- declareSchemaRef (Proxy :: Proxy DiscordAccount)
discordSchema <- declareSchemaRef (Proxy :: Proxy DiscordLink)
return $ NamedSchema (Just "Social") $ mempty
& type_ ?~ SwaggerObject
& properties .~
Expand Down
25 changes: 17 additions & 8 deletions test/Instances/Persistence.hs
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,24 @@ instance Arbitrary GitHubAccount where
suffix <- replicateM (len - whereToSplit) (elements alphaNum)
return $ pack $ prefix ++ (if hasHyphen then "-" else "") ++ suffix


instance Arbitrary DiscordAccount where
arbitrary = genPatternedTextWith discordAccount
-- Pattern for Discord ^(?:https?:\/\/)?discord(?:\.gg|app\.com\/invite|\.com\/invite)\/[\w-]+$
-- Valid examples:
-- https://discordapp.com/invite/asda
-- https://discord.com/invite/asda
-- https://discord.gg/asda
instance Arbitrary DiscordLink where
arbitrary = genPatternedTextWith discordLink
where
discordAccount = do
len <- choose (3, 32)
prefix <- replicateM len (elements alphaNum)
suffix <- replicateM 4 (elements "0123456789")
return $ pack $ prefix ++ "#" ++ suffix
discordLink = do
prefix <- elements ["https://", "http://"]
domain <- elements ["discordapp.com", "discord.com", "discord.gg"]
invite <- elements ["/invite/"]
account <- genDiscordAccount
return $ pack $ prefix ++ domain ++ (if domain == "discord.gg" then "/" else invite) ++ account
where
genDiscordAccount = do
len <- choose (1, 15)
replicateM len (elements "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_")

instance Arbitrary Social where
arbitrary = Social
Expand Down
2 changes: 1 addition & 1 deletion test/JSONSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec = do
testJSON' "Email" (na :: Email)
testJSON' "Subject" (na :: Subject)
testJSON' "GitHubAccount" (na :: GitHubAccount)
testJSON' "DiscordAccount" (na :: DiscordAccount)
testJSON' "DiscordLink" (na :: DiscordLink)
testJSON' "CertificationIssuerName" (na :: CertificationIssuerName)
testJSON' "ProfileWalletAddress" (na :: ProfileWalletAddress)
testJSON' "Website" (na :: Website)
Expand Down

0 comments on commit 5d47037

Please sign in to comment.