{-# OPTIONS_GHC -Wno-ambiguous-fields #-}

module Test.UserGroup where

import API.Brig
import API.Galley
import Control.Error (lastMay)
import Notifications (isUserGroupCreatedNotif, isUserGroupUpdatedNotif)
import SetupHelpers
import Testlib.Prelude

testUserGroupSmoke :: (HasCallStack) => App ()
testUserGroupSmoke :: HasCallStack => App ()
testUserGroupSmoke = do
  (Value
owner, String
team, [Value
mem1, Value
mem2, Value
mem3, Value
mem4, Value
mem5, Value
mem6, Value
admin2]) <- Domain -> Int -> App (Value, String, [Value])
forall domain.
(HasCallStack, MakesValue domain) =>
domain -> Int -> App (Value, String, [Value])
createTeam Domain
OwnDomain Int
8
  String -> Value -> Value -> TeamPermissions -> App Response
forall user member.
(HasCallStack, MakesValue user, MakesValue member) =>
String -> user -> member -> TeamPermissions -> App Response
updateTeamMember String
team Value
owner Value
admin2 TeamPermissions
Admin App Response -> (Response -> App ()) -> App ()
forall a b. App a -> (a -> App b) -> App b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= HasCallStack => Response -> App ()
Response -> App ()
assertSuccess
  String
mem1id <- App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (App Value -> App String) -> App Value -> App String
forall a b. (a -> b) -> a -> b
$ Value
mem1 Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"id"
  String
mem2id <- App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (App Value -> App String) -> App Value -> App String
forall a b. (a -> b) -> a -> b
$ Value
mem2 Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"id"
  String
mem3id <- App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (App Value -> App String) -> App Value -> App String
forall a b. (a -> b) -> a -> b
$ Value
mem3 Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"id"
  String
mem4id <- App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (App Value -> App String) -> App Value -> App String
forall a b. (a -> b) -> a -> b
$ Value
mem4 Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"id"
  String
mem5id <- App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (App Value -> App String) -> App Value -> App String
forall a b. (a -> b) -> a -> b
$ Value
mem5 Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"id"
  String
mem6id <- App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (App Value -> App String) -> App Value -> App String
forall a b. (a -> b) -> a -> b
$ Value
mem6 Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"id"

  let badGid :: String
badGid = String
"225c4d54-1ae7-11f0-8e9c-cbb31865d602"
      badMemid :: String
badMemid = String
"7bf23c0b-0be6-4432-bc5d-ab301bf75a99"

  String
gid <- [Value] -> ([WebSocket] -> App String) -> App String
forall a w.
(HasCallStack, ToWSConnect w) =>
[w] -> ([WebSocket] -> App a) -> App a
withWebSockets [Value
owner, Value
admin2] (([WebSocket] -> App String) -> App String)
-> ([WebSocket] -> App String) -> App String
forall a b. (a -> b) -> a -> b
$ \[WebSocket]
wss -> do
    String
gid <- App Response -> (Response -> App String) -> App String
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> Value -> App Response
forall user newUserGroup.
(MakesValue user, MakesValue newUserGroup) =>
user -> newUserGroup -> App Response
createUserGroup Value
owner ([Pair] -> Value
object [String
"name" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
"none", String
"members" String -> [String] -> Pair
forall a. ToJSON a => String -> a -> Pair
.= ([String
mem1id, String
mem2id])])) ((Response -> App String) -> App String)
-> (Response -> App String) -> App String
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
      Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
200
      Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"name" App Value -> String -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` String
"none"
      Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"members" App Value -> [String] -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` [String
mem1id, String
mem2id]
      App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (App Value -> App String) -> App Value -> App String
forall a b. (a -> b) -> a -> b
$ (Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"id")
    [WebSocket] -> (WebSocket -> App ()) -> App ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ [WebSocket]
wss ((WebSocket -> App ()) -> App ())
-> (WebSocket -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \WebSocket
ws -> do
      Value
notif <- HasCallStack => (Value -> App Bool) -> WebSocket -> App Value
(Value -> App Bool) -> WebSocket -> App Value
awaitMatch Value -> App Bool
forall a. MakesValue a => a -> App Bool
isUserGroupCreatedNotif WebSocket
ws
      Value
notif Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"payload.0.user_group.id" App Value -> String -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` String
gid
    String -> App String
forall a. a -> App a
forall (f :: * -> *) a. Applicative f => a -> f a
pure String
gid

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> String -> App Response
forall user. MakesValue user => user -> String -> App Response
getUserGroup Value
owner String
badGid) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
404

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> String -> App Response
forall user. MakesValue user => user -> String -> App Response
getUserGroup Value
mem3 String
badGid) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
404

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> String -> App Response
forall user. MakesValue user => user -> String -> App Response
getUserGroup Value
owner String
gid) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
200
    Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"members" App Value -> [String] -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` [String
mem1id, String
mem2id]

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> String -> Value -> App Response
forall user userGroupUpdate.
(MakesValue user, MakesValue userGroupUpdate) =>
user -> String -> userGroupUpdate -> App Response
updateUserGroup Value
owner String
badGid ([Pair] -> Value
object [String
"name" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
""])) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
400
    Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"label" App Value -> String -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` String
"bad-request"

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> String -> Value -> App Response
forall user userGroupUpdate.
(MakesValue user, MakesValue userGroupUpdate) =>
user -> String -> userGroupUpdate -> App Response
updateUserGroup Value
owner String
badGid ([Pair] -> Value
object [String
"name" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
"good name"])) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
404

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> String -> Value -> App Response
forall user userGroupUpdate.
(MakesValue user, MakesValue userGroupUpdate) =>
user -> String -> userGroupUpdate -> App Response
updateUserGroup Value
owner String
gid ([Pair] -> Value
object [String
"name" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
"also good"])) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
200

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> String -> String -> App Response
forall user.
MakesValue user =>
user -> String -> String -> App Response
addUserToGroup Value
owner String
gid String
mem3id) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
204

  [Value] -> ([WebSocket] -> App ()) -> App ()
forall a w.
(HasCallStack, ToWSConnect w) =>
[w] -> ([WebSocket] -> App a) -> App a
withWebSockets [Value
owner, Value
admin2] (([WebSocket] -> App ()) -> App ())
-> ([WebSocket] -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \[WebSocket]
wssAdmins -> do
    App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> String -> [String] -> App Response
forall user.
MakesValue user =>
user -> String -> [String] -> App Response
addUsersToGroup Value
owner String
gid [String
mem3id, String
mem4id, String
mem5id]) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
      Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
204
    [WebSocket] -> (WebSocket -> App ()) -> App ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ [WebSocket]
wssAdmins ((WebSocket -> App ()) -> App ())
-> (WebSocket -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \WebSocket
ws -> do
      Value
notif <- HasCallStack => (Value -> App Bool) -> WebSocket -> App Value
(Value -> App Bool) -> WebSocket -> App Value
awaitMatch Value -> App Bool
forall a. MakesValue a => a -> App Bool
isUserGroupUpdatedNotif WebSocket
ws
      Value
notif Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"payload.0.user_group.id" App Value -> String -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` String
gid

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> String -> [String] -> App Response
forall user.
MakesValue user =>
user -> String -> [String] -> App Response
addUsersToGroup Value
owner String
gid [String
badMemid, String
mem6id]) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
400

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> String -> String -> App Response
forall user.
MakesValue user =>
user -> String -> String -> App Response
removeUserFromGroup Value
owner String
gid String
mem1id) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
204

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> String -> App Response
forall user. MakesValue user => user -> String -> App Response
getUserGroup Value
owner String
gid) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
200
    Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"name" App Value -> String -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` String
"also good"
    Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"members" App Value -> [String] -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` [String
mem2id, String
mem3id, String
mem4id, String
mem5id]

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> GetUserGroupsArgs -> App Response
forall user.
MakesValue user =>
user -> GetUserGroupsArgs -> App Response
getUserGroups Value
owner GetUserGroupsArgs
forall a. Default a => a
def) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
200
    Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"page.0.name" App Value -> String -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` String
"also good"

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> String -> App Response
forall user. MakesValue user => user -> String -> App Response
deleteUserGroup Value
owner String
badGid) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
404

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> String -> App Response
forall user. MakesValue user => user -> String -> App Response
deleteUserGroup Value
owner String
gid) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
204

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> String -> Value -> App Response
forall user userGroupUpdate.
(MakesValue user, MakesValue userGroupUpdate) =>
user -> String -> userGroupUpdate -> App Response
updateUserGroup Value
owner String
gid ([Pair] -> Value
object [String
"name" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
"also good"])) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
404

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> String -> String -> App Response
forall user.
MakesValue user =>
user -> String -> String -> App Response
addUserToGroup Value
owner String
gid String
mem1id) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
404

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> String -> [String] -> App Response
forall user.
MakesValue user =>
user -> String -> [String] -> App Response
addUsersToGroup Value
owner String
gid [String
mem1id, String
mem5id]) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
404

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> String -> String -> App Response
forall user.
MakesValue user =>
user -> String -> String -> App Response
removeUserFromGroup Value
owner String
gid String
mem1id) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
404

testUserGroupAddGroupDenied :: (HasCallStack) => App ()
testUserGroupAddGroupDenied :: HasCallStack => App ()
testUserGroupAddGroupDenied = do
  let noMember :: [()]
noMember = [] :: [()]

  (Value
owner0, String
_team0, []) <- Domain -> Int -> App (Value, String, [Value])
forall domain.
(HasCallStack, MakesValue domain) =>
domain -> Int -> App (Value, String, [Value])
createTeam Domain
OwnDomain Int
1
  String
gid0 <- App Response -> (Response -> App String) -> App String
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> Value -> App Response
forall user newUserGroup.
(MakesValue user, MakesValue newUserGroup) =>
user -> newUserGroup -> App Response
createUserGroup Value
owner0 ([Pair] -> Value
object [String
"name" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
"none", String
"members" String -> [()] -> Pair
forall a. ToJSON a => String -> a -> Pair
.= [()]
noMember])) ((Response -> App String) -> App String)
-> (Response -> App String) -> App String
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
200
    Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"name" App Value -> String -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` String
"none"
    Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"members" App Value -> [()] -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` [()]
noMember
    App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (App Value -> App String) -> App Value -> App String
forall a b. (a -> b) -> a -> b
$ (Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"id")

  (Value
owner1, String
_team1, [Value
mem10]) <- Domain -> Int -> App (Value, String, [Value])
forall domain.
(HasCallStack, MakesValue domain) =>
domain -> Int -> App (Value, String, [Value])
createTeam Domain
OwnDomain Int
2
  String
_gid1 <- App Response -> (Response -> App String) -> App String
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> Value -> App Response
forall user newUserGroup.
(MakesValue user, MakesValue newUserGroup) =>
user -> newUserGroup -> App Response
createUserGroup Value
owner1 ([Pair] -> Value
object [String
"name" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
"none", String
"members" String -> [()] -> Pair
forall a. ToJSON a => String -> a -> Pair
.= [()]
noMember])) ((Response -> App String) -> App String)
-> (Response -> App String) -> App String
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
200
    Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"name" App Value -> String -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` String
"none"
    Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"members" App Value -> [()] -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` [()]
noMember
    App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (App Value -> App String) -> App Value -> App String
forall a b. (a -> b) -> a -> b
$ (Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"id")
  String
mem10id <- App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (App Value -> App String) -> App Value -> App String
forall a b. (a -> b) -> a -> b
$ Value
mem10 Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"id"

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> String -> [String] -> App Response
forall user.
MakesValue user =>
user -> String -> [String] -> App Response
addUsersToGroup Value
owner1 String
gid0 [String
mem10id]) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
404

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> String -> App Response
forall user. MakesValue user => user -> String -> App Response
getUserGroup Value
owner0 String
gid0) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
200
    Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"name" App Value -> String -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` String
"none"
    Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"members" App Value -> [()] -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` [()]
noMember

testUserGroupGetGroups :: (HasCallStack) => App ()
testUserGroupGetGroups :: HasCallStack => App ()
testUserGroupGetGroups = do
  (Value
owner, String
_team, []) <- Domain -> Int -> App (Value, String, [Value])
forall domain.
(HasCallStack, MakesValue domain) =>
domain -> Int -> App (Value, String, [Value])
createTeam Domain
OwnDomain Int
1

  let groupNames :: [String]
groupNames = [String
"First group", String
"CC", String
"CCC"] [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<> ((Char -> String -> String
forall a. a -> [a] -> [a]
: []) (Char -> String) -> String -> [String]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Char
'A' .. Char
'G'])
  [String] -> (String -> App ()) -> App ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [String]
groupNames ((String -> App ()) -> App ()) -> (String -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \String
gname -> do
    let newGroup :: Value
newGroup = [Pair] -> Value
object [String
"name" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
gname, String
"members" String -> [()] -> Pair
forall a. ToJSON a => String -> a -> Pair
.= ([] :: [()])]
    App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> Value -> App Response
forall user newUserGroup.
(MakesValue user, MakesValue newUserGroup) =>
user -> newUserGroup -> App Response
createUserGroup Value
owner Value
newGroup) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
      Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
200
      Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"name" App Value -> String -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` String
gname
      Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"members" App Value -> [()] -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` ([] :: [()])

  -- Default sort by is createdAt, and sortOrder is DESC
  Maybe (String, String, String)
_ <- Value
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
forall owner.
(HasCallStack, MakesValue owner) =>
owner
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
runSearch Value
owner GetUserGroupsArgs
forall a. Default a => a
def {q = Just "C"} [String
"C", String
"CCC", String
"CC"]

  -- Default sortOrder is DESC, regardless of sortBy
  Maybe (String, String, String)
_ <- Value
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
forall owner.
(HasCallStack, MakesValue owner) =>
owner
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
runSearch Value
owner GetUserGroupsArgs
forall a. Default a => a
def {q = Just "CC", sortByKeys = Just "name"} [String
"CCC", String
"CC"]

  -- Test combinations of sortBy and sortOrder:
  Maybe (String, String, String)
_ <-
    Value
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
forall owner.
(HasCallStack, MakesValue owner) =>
owner
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
runSearch
      Value
owner
      GetUserGroupsArgs
forall a. Default a => a
def {sortByKeys = Just "name", sortOrder = Just "asc"}
      [ String
"A",
        String
"B",
        String
"C",
        String
"CC",
        String
"CCC",
        String
"D",
        String
"E",
        String
"F",
        String
"First group",
        String
"G"
      ]
  Maybe (String, String, String)
_ <-
    Value
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
forall owner.
(HasCallStack, MakesValue owner) =>
owner
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
runSearch
      Value
owner
      GetUserGroupsArgs
forall a. Default a => a
def {sortByKeys = Just "name", sortOrder = Just "desc"}
      ( [String] -> [String]
forall a. [a] -> [a]
reverse
          [ String
"A",
            String
"B",
            String
"C",
            String
"CC",
            String
"CCC",
            String
"D",
            String
"E",
            String
"F",
            String
"First group",
            String
"G"
          ]
      )
  Maybe (String, String, String)
_ <-
    Value
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
forall owner.
(HasCallStack, MakesValue owner) =>
owner
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
runSearch
      Value
owner
      GetUserGroupsArgs
forall a. Default a => a
def {sortByKeys = Just "created_at", sortOrder = Just "asc"}
      [ String
"First group",
        String
"CC",
        String
"CCC",
        String
"A",
        String
"B",
        String
"C",
        String
"D",
        String
"E",
        String
"F",
        String
"G"
      ]
  Maybe (String, String, String)
_ <-
    Value
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
forall owner.
(HasCallStack, MakesValue owner) =>
owner
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
runSearch
      Value
owner
      GetUserGroupsArgs
forall a. Default a => a
def {sortByKeys = Just "created_at", sortOrder = Just "desc"}
      ( [String] -> [String]
forall a. [a] -> [a]
reverse
          [ String
"First group",
            String
"CC",
            String
"CCC",
            String
"A",
            String
"B",
            String
"C",
            String
"D",
            String
"E",
            String
"F",
            String
"G"
          ]
      )

  -- Test sorting and filtering works across pages
  let firstPageParams :: GetUserGroupsArgs
firstPageParams = GetUserGroupsArgs
forall a. Default a => a
def {sortByKeys = Just "name", sortOrder = Just "desc", pSize = Just 3}
  Just (String
name1, String
createdAt1, String
id1) <-
    Value
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
forall owner.
(HasCallStack, MakesValue owner) =>
owner
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
runSearch
      Value
owner
      GetUserGroupsArgs
firstPageParams
      [ String
"G",
        String
"First group",
        String
"F"
      ]
  Just (String
name2, String
createdAt2, String
id2) <-
    Value
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
forall owner.
(HasCallStack, MakesValue owner) =>
owner
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
runSearch
      Value
owner
      GetUserGroupsArgs
firstPageParams {lastName = Just name1, lastCreatedAt = Just createdAt1, lastId = Just id1}
      [ String
"E",
        String
"D",
        String
"CCC"
      ]
  Just (String
name3, String
createdAt3, String
id3) <-
    Value
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
forall owner.
(HasCallStack, MakesValue owner) =>
owner
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
runSearch
      Value
owner
      GetUserGroupsArgs
firstPageParams {lastName = Just name2, lastCreatedAt = Just createdAt2, lastId = Just id2}
      [ String
"CC",
        String
"C",
        String
"B"
      ]

  App (Maybe (String, String, String)) -> App ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void
    (App (Maybe (String, String, String)) -> App ())
-> App (Maybe (String, String, String)) -> App ()
forall a b. (a -> b) -> a -> b
$ Value
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
forall owner.
(HasCallStack, MakesValue owner) =>
owner
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
runSearch
      Value
owner
      GetUserGroupsArgs
firstPageParams {lastName = Just name3, lastCreatedAt = Just createdAt3, lastId = Just id3}
      [String
"A"]

runSearch :: (HasCallStack, MakesValue owner) => owner -> GetUserGroupsArgs -> [String] -> App (Maybe (String, String, String))
runSearch :: forall owner.
(HasCallStack, MakesValue owner) =>
owner
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
runSearch owner
owner GetUserGroupsArgs
args [String]
expected =
  App Response
-> (Response -> App (Maybe (String, String, String)))
-> App (Maybe (String, String, String))
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (owner -> GetUserGroupsArgs -> App Response
forall user.
MakesValue user =>
user -> GetUserGroupsArgs -> App Response
getUserGroups owner
owner GetUserGroupsArgs
args) ((Response -> App (Maybe (String, String, String)))
 -> App (Maybe (String, String, String)))
-> (Response -> App (Maybe (String, String, String)))
-> App (Maybe (String, String, String))
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
200
    [Value]
found <- ((Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"name") `mapM`) ([Value] -> App [Value]) -> App [Value] -> App [Value]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Value -> App [Value]
forall a. (HasCallStack, MakesValue a) => a -> App [Value]
asList (Value -> App [Value]) -> App Value -> App [Value]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"page"
    [Value]
found [Value] -> [String] -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` [String]
expected
    [Value]
results <- App Value -> App [Value]
forall a. (HasCallStack, MakesValue a) => a -> App [Value]
asList (App Value -> App [Value]) -> App Value -> App [Value]
forall a b. (a -> b) -> a -> b
$ Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"page"
    Maybe Value
-> (Value -> App (String, String, String))
-> App (Maybe (String, String, String))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for ([Value] -> Maybe Value
forall a. [a] -> Maybe a
lastMay [Value]
results) ((Value -> App (String, String, String))
 -> App (Maybe (String, String, String)))
-> (Value -> App (String, String, String))
-> App (Maybe (String, String, String))
forall a b. (a -> b) -> a -> b
$ \Value
lastGroup ->
      (,,)
        (String -> String -> String -> (String, String, String))
-> App String -> App (String -> String -> (String, String, String))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (Value
lastGroup Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"name")
        App (String -> String -> (String, String, String))
-> App String -> App (String -> (String, String, String))
forall a b. App (a -> b) -> App a -> App b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (Value
lastGroup Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"createdAt")
        App (String -> (String, String, String))
-> App String -> App (String, String, String)
forall a b. App (a -> b) -> App a -> App b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (Value
lastGroup Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"id")

testUserGroupGetGroupsAllInputs :: (HasCallStack) => App ()
testUserGroupGetGroupsAllInputs :: HasCallStack => App ()
testUserGroupGetGroupsAllInputs = do
  (Value
owner, String
_team, []) <- Domain -> Int -> App (Value, String, [Value])
forall domain.
(HasCallStack, MakesValue domain) =>
domain -> Int -> App (Value, String, [Value])
createTeam Domain
OwnDomain Int
1
  [String] -> (String -> App ()) -> App ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ ((Char -> String -> String
forall a. a -> [a] -> [a]
: []) (Char -> String) -> String -> [String]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Char
'A' .. Char
'Z']) ((String -> App ()) -> App ()) -> (String -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \String
gname -> do
    let newGroup :: Value
newGroup = [Pair] -> Value
object [String
"name" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
gname, String
"members" String -> [()] -> Pair
forall a. ToJSON a => String -> a -> Pair
.= ([] :: [()])]
    Value -> Value -> App Response
forall user newUserGroup.
(MakesValue user, MakesValue newUserGroup) =>
user -> newUserGroup -> App Response
createUserGroup Value
owner Value
newGroup App Response -> (Response -> App ()) -> App ()
forall a b. App a -> (a -> App b) -> App b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= HasCallStack => Response -> App ()
Response -> App ()
assertSuccess

  Just (String
ln, String
ltz, String
lid) <- Value
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
forall owner.
(HasCallStack, MakesValue owner) =>
owner
-> GetUserGroupsArgs
-> [String]
-> App (Maybe (String, String, String))
runSearch Value
owner GetUserGroupsArgs
forall a. Default a => a
def {pSize = Just 3} [String
"Z", String
"Y", String
"X"]
  let getUserGroupArgs :: [GetUserGroupsArgs]
getUserGroupArgs = String -> String -> String -> [GetUserGroupsArgs]
getUserGroupArgsCombinations String
ln String
ltz String
lid
  [GetUserGroupsArgs] -> (GetUserGroupsArgs -> App ()) -> App ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ [GetUserGroupsArgs]
getUserGroupArgs ((GetUserGroupsArgs -> App ()) -> App ())
-> (GetUserGroupsArgs -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \GetUserGroupsArgs
args -> do
    App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> GetUserGroupsArgs -> App Response
forall user.
MakesValue user =>
user -> GetUserGroupsArgs -> App Response
getUserGroups Value
owner GetUserGroupsArgs
args) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
      -- most important check is that all combinations return 200
      Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
200
      -- additionally we can check a few invariants
      [Value]
groups <- Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"page" App Value -> (Value -> App [Value]) -> App [Value]
forall a b. App a -> (a -> App b) -> App b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Value -> App [Value]
forall a. (HasCallStack, MakesValue a) => a -> App [Value]
asList
      case (GetUserGroupsArgs
args.q, GetUserGroupsArgs
args.lastName, GetUserGroupsArgs
args.lastCreatedAt, GetUserGroupsArgs
args.lastId) of
        (Maybe String
Nothing, Maybe String
Nothing, Maybe String
Nothing, Maybe String
Nothing) -> [Value] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Value]
groups Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` (Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe Int
15 GetUserGroupsArgs
args.pSize)
        (Just String
_, Maybe String
Nothing, Maybe String
Nothing, Maybe String
Nothing) -> [Value] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Value]
groups Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
1
        (Maybe String, Maybe String, Maybe String, Maybe String)
_ -> () -> App ()
forall a. a -> App a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
  where
    getUserGroupArgsCombinations :: String -> String -> String -> [GetUserGroupsArgs]
    getUserGroupArgsCombinations :: String -> String -> String -> [GetUserGroupsArgs]
getUserGroupArgsCombinations String
ln String
ltz String
lid =
      [ GetUserGroupsArgs
          { q :: Maybe String
q = Maybe String
q',
            sortByKeys :: Maybe String
sortByKeys = Maybe String
sortBy',
            sortOrder :: Maybe String
sortOrder = Maybe String
sortOrder',
            pSize :: Maybe Int
pSize = Maybe Int
pSize',
            lastName :: Maybe String
lastName = Maybe String
lastName',
            lastCreatedAt :: Maybe String
lastCreatedAt = Maybe String
lastCreatedAt',
            lastId :: Maybe String
lastId = Maybe String
lastId',
            includeMemberCount :: Bool
includeMemberCount = Bool
includeMemberCount'
          }
        | Maybe String
q' <- [Maybe String]
qs,
          Maybe String
sortBy' <- [Maybe String]
sortByKeysList,
          Maybe String
sortOrder' <- [Maybe String]
sortOrders,
          Maybe Int
pSize' <- [Maybe Int]
pSizes,
          Maybe String
lastName' <- [Maybe String]
lastNames,
          Maybe String
lastCreatedAt' <- [Maybe String]
lastCreatedAts,
          Maybe String
lastId' <- [Maybe String]
lastIds,
          Bool
includeMemberCount' <- [Bool
False, Bool
True]
      ]
      where
        qs :: [Maybe String]
qs = [Maybe String
forall a. Maybe a
Nothing, String -> Maybe String
forall a. a -> Maybe a
Just String
"A"]
        sortByKeysList :: [Maybe String]
sortByKeysList = [Maybe String
forall a. Maybe a
Nothing, String -> Maybe String
forall a. a -> Maybe a
Just String
"name", String -> Maybe String
forall a. a -> Maybe a
Just String
"created_at"]
        sortOrders :: [Maybe String]
sortOrders = [Maybe String
forall a. Maybe a
Nothing, String -> Maybe String
forall a. a -> Maybe a
Just String
"asc", String -> Maybe String
forall a. a -> Maybe a
Just String
"desc"]
        pSizes :: [Maybe Int]
pSizes = [Maybe Int
forall a. Maybe a
Nothing, Int -> Maybe Int
forall a. a -> Maybe a
Just Int
3]
        lastNames :: [Maybe String]
lastNames = [Maybe String
forall a. Maybe a
Nothing, String -> Maybe String
forall a. a -> Maybe a
Just String
ln]
        lastCreatedAts :: [Maybe String]
lastCreatedAts = [Maybe String
forall a. Maybe a
Nothing, String -> Maybe String
forall a. a -> Maybe a
Just String
ltz]
        lastIds :: [Maybe String]
lastIds = [Maybe String
forall a. Maybe a
Nothing, String -> Maybe String
forall a. a -> Maybe a
Just String
lid]

testUserGroupMembersCount :: (HasCallStack) => App ()
testUserGroupMembersCount :: HasCallStack => App ()
testUserGroupMembersCount = do
  (Value
owner, String
_team, [Value
mem1, Value
mem2]) <- Domain -> Int -> App (Value, String, [Value])
forall domain.
(HasCallStack, MakesValue domain) =>
domain -> Int -> App (Value, String, [Value])
createTeam Domain
OwnDomain Int
3
  String
mem1id <- App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (App Value -> App String) -> App Value -> App String
forall a b. (a -> b) -> a -> b
$ Value
mem1 Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"id"
  String
mem2id <- App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString (App Value -> App String) -> App Value -> App String
forall a b. (a -> b) -> a -> b
$ Value
mem2 Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"id"

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> Value -> App Response
forall user newUserGroup.
(MakesValue user, MakesValue newUserGroup) =>
user -> newUserGroup -> App Response
createUserGroup Value
owner ([Pair] -> Value
object [String
"name" String -> String -> Pair
forall a. ToJSON a => String -> a -> Pair
.= String
"none", String
"members" String -> [String] -> Pair
forall a. ToJSON a => String -> a -> Pair
.= ([String
mem1id, String
mem2id])])) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
200
    Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"name" App Value -> String -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` String
"none"
    Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"members" App Value -> [String] -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatch` [String
mem1id, String
mem2id]

  App Response -> (Response -> App ()) -> App ()
forall a.
HasCallStack =>
App Response -> (Response -> App a) -> App a
bindResponse (Value -> GetUserGroupsArgs -> App Response
forall user.
MakesValue user =>
user -> GetUserGroupsArgs -> App Response
getUserGroups Value
owner (GetUserGroupsArgs
forall a. Default a => a
def {includeMemberCount = True})) ((Response -> App ()) -> App ()) -> (Response -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Response
resp -> do
    Response
resp.status Int -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
200
    Response
resp.json App Value -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"page.0.membersCount" App Value -> Int -> App ()
forall a. (MakesValue a, HasCallStack) => a -> Int -> App ()
`shouldMatchInt` Int
2