Skip to content

Commit

Permalink
[FS-1008] Golden tests for event schemas (#2861)
Browse files Browse the repository at this point in the history
  • Loading branch information
battermann authored Nov 23, 2022
1 parent 64d1c2a commit b6f1e36
Show file tree
Hide file tree
Showing 27 changed files with 669 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/5-internal/pr-2861
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Golden tests for conversation and feature config event schemas
30 changes: 29 additions & 1 deletion libs/wire-api/src/Wire/API/Event/FeatureConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import Data.Schema
import qualified Data.Swagger as S
import GHC.TypeLits (KnownSymbol)
import Imports
import Test.QuickCheck.Gen (oneof)
import Wire.API.Team.Feature
import Wire.Arbitrary (Arbitrary (..), GenericUniform (..))

data Event = Event
{ _eventType :: EventType,
Expand All @@ -40,8 +42,34 @@ data Event = Event
deriving (Eq, Show, Generic)
deriving (A.ToJSON, A.FromJSON) via Schema Event

instance Arbitrary Event where
arbitrary =
do
let arbConfig =
oneof
[ arbitrary @(WithStatus SSOConfig) <&> toJSON,
arbitrary @(WithStatus SearchVisibilityAvailableConfig) <&> toJSON,
arbitrary @(WithStatus ValidateSAMLEmailsConfig) <&> toJSON,
arbitrary @(WithStatus DigitalSignaturesConfig) <&> toJSON,
arbitrary @(WithStatus AppLockConfig) <&> toJSON,
arbitrary @(WithStatus FileSharingConfig) <&> toJSON,
arbitrary @(WithStatus ClassifiedDomainsConfig) <&> toJSON,
arbitrary @(WithStatus ConferenceCallingConfig) <&> toJSON,
arbitrary @(WithStatus SelfDeletingMessagesConfig) <&> toJSON,
arbitrary @(WithStatus GuestLinksConfig) <&> toJSON,
arbitrary @(WithStatus SndFactorPasswordChallengeConfig) <&> toJSON,
arbitrary @(WithStatus SearchVisibilityInboundConfig) <&> toJSON,
arbitrary @(WithStatus MLSConfig) <&> toJSON,
arbitrary @(WithStatus ExposeInvitationURLsToTeamAdminConfig) <&> toJSON
]
Event
<$> arbitrary
<*> arbitrary
<*> arbConfig

data EventType = Update
deriving (Eq, Show)
deriving (Eq, Show, Generic)
deriving (Arbitrary) via GenericUniform EventType

instance ToSchema EventType where
schema =
Expand Down
33 changes: 32 additions & 1 deletion libs/wire-api/test/golden/Test/Wire/API/Golden/Generated.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ import qualified Test.Wire.API.Golden.Generated.EmailUpdate_user
import qualified Test.Wire.API.Golden.Generated.Email_user
import qualified Test.Wire.API.Golden.Generated.EventType_team
import qualified Test.Wire.API.Golden.Generated.EventType_user
import qualified Test.Wire.API.Golden.Generated.Event_conversation
import qualified Test.Wire.API.Golden.Generated.Event_featureConfig
import qualified Test.Wire.API.Golden.Generated.Event_team
import qualified Test.Wire.API.Golden.Generated.Event_user
import qualified Test.Wire.API.Golden.Generated.HandleUpdate_user
Expand Down Expand Up @@ -1389,5 +1391,34 @@ tests =
testGroup
"Golden: WithStatusPatch_team 19"
$ testObjects
[(Test.Wire.API.Golden.Generated.WithStatusPatch_team.testObject_WithStatusPatch_team_19, "testObject_WithStatusPatch_team_19.json")]
[(Test.Wire.API.Golden.Generated.WithStatusPatch_team.testObject_WithStatusPatch_team_19, "testObject_WithStatusPatch_team_19.json")],
testGroup
"Golden: Event_FeatureConfig"
$ testObjects
[ (Test.Wire.API.Golden.Generated.Event_featureConfig.testObject_Event_featureConfig_1, "testObject_Event_featureConfig_1.json"),
(Test.Wire.API.Golden.Generated.Event_featureConfig.testObject_Event_featureConfig_2, "testObject_Event_featureConfig_2.json"),
(Test.Wire.API.Golden.Generated.Event_featureConfig.testObject_Event_featureConfig_3, "testObject_Event_featureConfig_3.json"),
(Test.Wire.API.Golden.Generated.Event_featureConfig.testObject_Event_featureConfig_4, "testObject_Event_featureConfig_4.json"),
(Test.Wire.API.Golden.Generated.Event_featureConfig.testObject_Event_featureConfig_5, "testObject_Event_featureConfig_5.json"),
(Test.Wire.API.Golden.Generated.Event_featureConfig.testObject_Event_featureConfig_6, "testObject_Event_featureConfig_6.json"),
(Test.Wire.API.Golden.Generated.Event_featureConfig.testObject_Event_featureConfig_7, "testObject_Event_featureConfig_7.json"),
(Test.Wire.API.Golden.Generated.Event_featureConfig.testObject_Event_featureConfig_8, "testObject_Event_featureConfig_8.json"),
(Test.Wire.API.Golden.Generated.Event_featureConfig.testObject_Event_featureConfig_9, "testObject_Event_featureConfig_9.json"),
(Test.Wire.API.Golden.Generated.Event_featureConfig.testObject_Event_featureConfig_10, "testObject_Event_featureConfig_10.json")
],
testGroup
"Golden: Event_Conversation"
$ testObjects
[ (Test.Wire.API.Golden.Generated.Event_conversation.testObject_Event_conversation_1, "testObject_Event_conversation_1.json"),
(Test.Wire.API.Golden.Generated.Event_conversation.testObject_Event_conversation_2, "testObject_Event_conversation_2.json"),
(Test.Wire.API.Golden.Generated.Event_conversation.testObject_Event_conversation_3, "testObject_Event_conversation_3.json"),
(Test.Wire.API.Golden.Generated.Event_conversation.testObject_Event_conversation_4, "testObject_Event_conversation_4.json"),
(Test.Wire.API.Golden.Generated.Event_conversation.testObject_Event_conversation_5, "testObject_Event_conversation_5.json"),
(Test.Wire.API.Golden.Generated.Event_conversation.testObject_Event_conversation_6, "testObject_Event_conversation_6.json"),
(Test.Wire.API.Golden.Generated.Event_conversation.testObject_Event_conversation_7, "testObject_Event_conversation_7.json"),
(Test.Wire.API.Golden.Generated.Event_conversation.testObject_Event_conversation_8, "testObject_Event_conversation_8.json"),
(Test.Wire.API.Golden.Generated.Event_conversation.testObject_Event_conversation_9, "testObject_Event_conversation_9.json"),
(Test.Wire.API.Golden.Generated.Event_conversation.testObject_Event_conversation_11, "testObject_Event_conversation_11.json"),
(Test.Wire.API.Golden.Generated.Event_conversation.testObject_Event_conversation_10, "testObject_Event_conversation_10.json")
]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
{-# LANGUAGE OverloadedLists #-}

-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2022 Wire Swiss GmbH <opensource@wire.com>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Test.Wire.API.Golden.Generated.Event_conversation where

import Data.Code
import Data.Domain (Domain (..))
import Data.Id
import Data.Misc (HttpsUrl (HttpsUrl))
import Data.Qualified (Qualified (..))
import Data.Range
import Data.Time
import qualified Data.UUID as UUID
import GHC.Exts (IsList (fromList))
import Imports
import URI.ByteString (Authority (..), Host (..), Query (..), Scheme (..), URIRef (..))
import Wire.API.Conversation (Access (..), MutedStatus (..))
import Wire.API.Conversation.Role
import Wire.API.Conversation.Typing
import Wire.API.Event.Conversation

testObject_Event_conversation_1 :: Event
testObject_Event_conversation_1 =
Event
{ evtConv = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "oym59-06.i423w"}},
evtFrom = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "n8nl6tp.h5"}},
evtTime = UTCTime {utctDay = ModifiedJulianDay 58119, utctDayTime = 0},
evtData = EdConvCodeDelete
}

testObject_Event_conversation_2 :: Event
testObject_Event_conversation_2 =
Event
{ evtConv = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "2m99----34.id7u09"}},
evtFrom = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "b.0-7.0.rg"}},
evtTime = UTCTime {utctDay = ModifiedJulianDay 58119, utctDayTime = 0},
evtData =
EdMemberUpdate
( MemberUpdateData
{ misTarget = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "oy8yz.f1"}},
misOtrMutedStatus = Just (MutedStatus {fromMutedStatus = 1}),
misOtrMutedRef = Nothing,
misOtrArchived = Nothing,
misOtrArchivedRef = Nothing,
misHidden = Nothing,
misHiddenRef = Nothing,
misConvRoleName = Just roleNameWireAdmin
}
)
}

testObject_Event_conversation_3 :: Event
testObject_Event_conversation_3 =
Event
{ evtConv = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "91.ii9vf.mbwj9k7lmk"}},
evtFrom = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "k3.f.z"}},
evtTime = UTCTime {utctDay = ModifiedJulianDay 58119, utctDayTime = 0},
evtData =
EdConvCodeUpdate
( ConversationCode
{ conversationKey = Key {asciiKey = unsafeRange "CRdONS7988O2QdyndJs1"},
conversationCode = Value {asciiValue = unsafeRange "7d6713"},
conversationUri = Just $ HttpsUrl (URI {uriScheme = Scheme {schemeBS = "https"}, uriAuthority = Just (Authority {authorityUserInfo = Nothing, authorityHost = Host {hostBS = "example.com"}, authorityPort = Nothing}), uriPath = "", uriQuery = Query {queryPairs = []}, uriFragment = Nothing})
}
)
}

testObject_Event_conversation_4 :: Event
testObject_Event_conversation_4 =
Event
{ evtConv = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "ma--6us.i8o--0440"}},
evtFrom = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "97k-u0.b-5c"}},
evtTime = UTCTime {utctDay = ModifiedJulianDay 58119, utctDayTime = 0},
evtData = EdConvAccessUpdate (ConversationAccessData {cupAccess = fromList [PrivateAccess, CodeAccess], cupAccessRoles = fromList []})
}

testObject_Event_conversation_5 :: Event
testObject_Event_conversation_5 =
Event
{ evtConv = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "q.6lm833.o95.l.y2"}},
evtFrom = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "7.m4f7p.ez4zs61"}},
evtTime = UTCTime {utctDay = ModifiedJulianDay 58119, utctDayTime = 0},
evtData = EdMLSWelcome ""
}

testObject_Event_conversation_6 :: Event
testObject_Event_conversation_6 =
Event
{ evtConv = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "391.r"}},
evtFrom = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "8.0-6.t7pxv"}},
evtTime = UTCTime {utctDay = ModifiedJulianDay 58119, utctDayTime = 0},
evtData = EdOtrMessage (OtrMessage {otrSender = ClientId {client = "1"}, otrRecipient = ClientId {client = "1"}, otrCiphertext = "", otrData = Just "I\68655"})
}

testObject_Event_conversation_7 :: Event
testObject_Event_conversation_7 =
Event
{ evtConv = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "b2.ue4k"}},
evtFrom = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "64b3--h.u"}},
evtTime = UTCTime {utctDay = ModifiedJulianDay 58119, utctDayTime = 0},
evtData = EdOtrMessage (OtrMessage {otrSender = ClientId {client = "3"}, otrRecipient = ClientId {client = "3"}, otrCiphertext = "%\SI", otrData = Nothing})
}

testObject_Event_conversation_8 :: Event
testObject_Event_conversation_8 =
Event
{ evtConv = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "36.e9.s-o-17"}},
evtFrom = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "0--gy.705nsa8.j4m"}},
evtTime = UTCTime {utctDay = ModifiedJulianDay 58119, utctDayTime = 0},
evtData = EdTyping (TypingData {tdStatus = StartedTyping})
}

testObject_Event_conversation_9 :: Event
testObject_Event_conversation_9 =
Event
{ evtConv = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "743846p6-pp33.1.ktb9.0bmn.efm2bly"}},
evtFrom = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "9--5grmn.j39y3--9n"}},
evtTime = UTCTime {utctDay = ModifiedJulianDay 58119, utctDayTime = 0},
evtData =
EdMembersLeave
( QualifiedUserIdList
{ qualifiedUserIdList =
[ Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "ow8i3fhr.v"}},
Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "8kshw-2l.3w44.6c8763a-77r4.gk13zq"}},
Qualified
{ qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")),
qDomain = Domain {_domainText = "xk-no.m5--f8b7"}
},
Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "x02.p.69y-6.8ncr.u"}},
Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "1-47tume1e5l32i.v75is-q4-o.u7qc"}},
Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "8ay.ec.k-8"}},
Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "u-8.m-42ns2c"}},
Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "08kh83-8.vu.i24"}},
Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "t1t683.o3--2.3k5.it-5.e1"}},
Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "q.ajw-5"}},
Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "73m4g.c24em3.v"}},
Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "i7zn.li"}},
Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "42y78.yekf"}},
Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "n63-p87m2.dtq"}},
Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "ns.v2p"}}
]
}
)
}

testObject_Event_conversation_10 :: Event
testObject_Event_conversation_10 =
Event
{ evtConv = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "1852a.o-4"}},
evtFrom = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "4-p.d7b8d3.6.c8--jds3-1acy"}},
evtTime = UTCTime {utctDay = ModifiedJulianDay 58119, utctDayTime = 0},
evtData = EdMLSMessage "s\b\138w\236\231P(\ESC\216\205"
}

testObject_Event_conversation_11 :: Event
testObject_Event_conversation_11 =
Event
{ evtConv = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "wwzw-ly4jk5.6790-y.j04o-21.ltl"}},
evtFrom = Qualified {qUnqualified = Id (fromJust (UUID.fromString "2126ea99-ca79-43ea-ad99-a59616468e8e")), qDomain = Domain {_domainText = "70-o.ncd"}},
evtTime = UTCTime {utctDay = ModifiedJulianDay 58119, utctDayTime = 0},
evtData = EdTyping (TypingData {tdStatus = StoppedTyping})
}
Loading

0 comments on commit b6f1e36

Please sign in to comment.