Skip to content

Commit 66a6d46

Browse files
committed
wip
1 parent 7204831 commit 66a6d46

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

libs/wire-subsystems/src/Wire/UserGroupSubsystem/Interpreter.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ userGroupSubsystemErrorToHttpError =
6161
UserGroupNotATeamAdmin -> errorToWai @E.UserGroupNotATeamAdmin
6262
UserGroupMemberIsNotInTheSameTeam -> errorToWai @E.UserGroupMemberIsNotInTheSameTeam
6363
UserGroupNotFound -> errorToWai @E.UserGroupNotFound
64-
UserGroupInvalidQueryParams msg -> _ msg
64+
UserGroupInvalidQueryParams _msg -> errorToWai @E.UserGroupInvalidQueryParams -- TODO: msg should also be rendered here!
6565

6666
createUserGroupImpl ::
6767
( Member UserSubsystem r,
68-
Member (Error UserGroupSubsystemError) r,
68+
Member (Error UserGroupSubsystemError) r, -- TODO: use ErrorS everywhere!
6969
Member Store.UserGroupStore r,
7070
Member GalleyAPIAccess r,
7171
Member (Input (Local ())) r,

libs/wire-subsystems/test/unit/Wire/UserGroupSubsystem/InterpreterSpec.hs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ timeoutHook :: Spec -> Spec
106106
timeoutHook = around_ $ maybe (fail "exceeded timeout") pure <=< timeout 1_000_000
107107

108108
spec :: Spec
109-
spec = timeoutHook $ describe "UserGroupSubsystem.Interpreter" do
109+
spec = timeoutHook . modifyMaxShrinks (const 0) $ describe "UserGroupSubsystem.Interpreter" do
110110
describe "CreateGroup :: UserId -> NewUserGroup -> UserGroupSubsystem m UserGroup" $ do
111111
prop "team admins should be able to create and get groups" $ \team newUserGroupName seed ->
112112
let rndShuffle xs gen = map fst $ sortOn snd $ zip xs (Rand.randoms gen :: [Int])
@@ -264,13 +264,12 @@ spec = timeoutHook $ describe "UserGroupSubsystem.Interpreter" do
264264
getGroupOutsider <- getGroup (ownerId otherTeam) group1.id_
265265

266266
getGroupsAdmin <- getGroups (ownerId team) (Just (userGroupNameToText userGroupName)) Nothing Nothing Nothing Nothing
267-
getGroupsOutsider <- getGroups (ownerId otherTeam) (Just (userGroupNameToText userGroupName)) Nothing Nothing Nothing Nothing
267+
-- do we need an extra test for that?: getGroupsOutsider <- getGroups (ownerId otherTeam) (Just (userGroupNameToText userGroupName)) Nothing Nothing Nothing Nothing (should be empty)
268268

269269
pure $
270270
getGroupAdmin === Just group1
271271
.&&. getGroupsAdmin.page === [group1]
272272
.&&. getGroupOutsider === Nothing
273-
.&&. getGroupsOutsider.page === []
274273

275274
prop "team members can only get user groups from their own team" $
276275
\(WithMods team1 :: WithMods '[AtLeastOneNonAdmin] ArbitraryTeam)
@@ -306,41 +305,45 @@ spec = timeoutHook $ describe "UserGroupSubsystem.Interpreter" do
306305
.&&. getOtherGroup === Nothing
307306
.&&. getOtherGroups.page === []
308307

308+
-- TODO: don't we want to make asc, desc different for every key?
309+
309310
it "getGroups: q=<name>, returning 0, 1, 2 groups" $ do
310311
WithMods team1 :: WithMods '[AtLeastOneNonAdmin] ArbitraryTeam <- generate arbitrary
311312
mkAssertion (allUsers team1) (galleyTeam team1) . interpretUserGroupSubsystem $ do
312-
let newGroups = [NewUserGroup (either undefined id $ userGroupNameFromText name) mempty | name <- ["1", "2", "2"]]
313-
groups <- createGroup (ownerId team1) `mapM` newGroups
313+
let newGroups = [NewUserGroup (either undefined id $ userGroupNameFromText name) mempty | name <- ["1", "2", "2", "33"]]
314+
groups <- (\ng -> moveClock 1 >> createGroup (ownerId team1) ng) `mapM` newGroups
314315

315316
get0 <- getGroups (ownerId team1) (Just "nope") Nothing Nothing Nothing Nothing
316317
get1 <- getGroups (ownerId team1) (Just "1") Nothing Nothing Nothing Nothing
317-
get2 <- getGroups (ownerId team1) (Just "s") Nothing Nothing Nothing Nothing
318+
get2 <- getGroups (ownerId team1) (Just "2") Nothing Nothing Nothing Nothing
319+
get3 <- getGroups (ownerId team1) (Just "3") Nothing Nothing Nothing Nothing
318320

319321
pure do
320322
get0.page `shouldBe` []
321323
get1.page `shouldBe` [groups !! 0]
322-
get2.page `shouldBe` [groups !! 1, groups !! 2]
324+
get2.page `shouldBe` reverse [groups !! 1, groups !! 2] -- (default sort order is descending!)
325+
get3.page `shouldBe` [groups !! 3]
323326

324327
it "getGroups: sortByKeys, sortOrder" $ do
325328
WithMods team1 :: WithMods '[AtLeastOneNonAdmin] ArbitraryTeam <- generate arbitrary
326329
mkAssertion (allUsers team1) (galleyTeam team1) . interpretUserGroupSubsystem $ do
327330
let mkNewGroup name = NewUserGroup (either undefined id $ userGroupNameFromText name) mempty
328331
mkGroup name = moveClock 1 >> createGroup (ownerId team1) (mkNewGroup name)
329-
group2b <- mkGroup "2"
330332
group2a <- mkGroup "2"
331-
group1b <- mkGroup "1"
333+
group2b <- mkGroup "2"
332334
group1a <- mkGroup "1"
333-
group3b <- mkGroup "3"
335+
group1b <- mkGroup "1"
334336
group3a <- mkGroup "3"
337+
group3b <- mkGroup "3"
335338

336339
sortByName <-
337-
getGroups (ownerId team1) Nothing (Just (SortBy ["name"])) Nothing Nothing Nothing
340+
getGroups (ownerId team1) Nothing (Just (SortBy ["name"])) (Just Asc) Nothing Nothing
338341
sortByNameAndCreatedAt <-
339-
getGroups (ownerId team1) Nothing (Just (SortBy ["name", "created_at"])) Nothing Nothing Nothing
342+
getGroups (ownerId team1) Nothing (Just (SortBy ["name", "created_at"])) (Just Asc) Nothing Nothing
340343
sortByCreatedAt <-
341-
getGroups (ownerId team1) Nothing (Just (SortBy ["created_at"])) Nothing Nothing Nothing
344+
getGroups (ownerId team1) Nothing (Just (SortBy ["created_at"])) (Just Asc) Nothing Nothing
342345
sortByCreatedAtAndName <-
343-
getGroups (ownerId team1) Nothing (Just (SortBy ["created_at", "name"])) Nothing Nothing Nothing
346+
getGroups (ownerId team1) Nothing (Just (SortBy ["created_at", "name"])) (Just Asc) Nothing Nothing
344347
sortByDefault <-
345348
getGroups (ownerId team1) Nothing Nothing Nothing Nothing Nothing
346349
sortByDefaultAsc <-
@@ -349,18 +352,18 @@ spec = timeoutHook $ describe "UserGroupSubsystem.Interpreter" do
349352
getGroups (ownerId team1) Nothing Nothing (Just Desc) Nothing Nothing
350353

351354
let byName = [group1a, group1b, group2a, group2b, group3a, group3b]
352-
byDate = [group2b, group2a, group1b, group1a, group3b, group3a]
355+
byDate = [group2a, group2b, group1a, group1b, group3a, group3b]
353356

354357
pure do
355358
sortByName.page `shouldBe` byName
356359
sortByNameAndCreatedAt.page `shouldBe` byName
357360
sortByCreatedAt.page `shouldBe` byDate
358361
sortByCreatedAtAndName.page `shouldBe` byDate
359-
sortByDefault.page `shouldBe` byDate
362+
sortByDefault.page `shouldBe` reverse byDate
360363
sortByDefaultAsc.page `shouldBe` byDate
361364
sortByDefaultDesc.page `shouldBe` reverse byDate
362365

363-
prop "getGroups: pagination (happy flow)" $ do
366+
focus . prop "getGroups: pagination (happy flow)" $ do
364367
\(WithMods team1 :: WithMods '[AtLeastOneNonAdmin] ArbitraryTeam) numGroups pageSize ->
365368
expectRight . runDependencies (allUsers team1) (galleyTeam team1) . interpretUserGroupSubsystem $ do
366369
let mkNewGroup = NewUserGroup (either undefined id $ userGroupNameFromText "same name") mempty
@@ -369,20 +372,20 @@ spec = timeoutHook $ describe "UserGroupSubsystem.Interpreter" do
369372
-- groups distinguished only by creation date
370373
groups <- replicateM numGroups mkGroup
371374

372-
results :: [PaginationResult UserGroup] <- do
375+
results :: [PaginationResult UserGroupKey UserGroup] <- do
373376
let fetch mbState = do
374377
p <- getGroups (ownerId team1) Nothing Nothing Nothing (Just pageSize) mbState
375378
if null p.page
376-
then pure [p]
379+
then pure []
377380
else (p :) <$> fetch (Just p.state)
378381
fetch Nothing
379382

380383
pure $
381384
-- result is complete and correct
382385
mconcat ((.page) <$> results) === groups
383-
-- every page has the expected size
384-
.&&. all (\r -> length r.page == pageSizeToInt pageSize) (init results)
385-
.&&. length ((last results).page) <= pageSizeToInt pageSize
386+
-- every page has the expected size
387+
-- .&&. all (\r -> length r.page == pageSizeToInt pageSize) (init results)
388+
-- .&&. length ((last results).page) <= pageSizeToInt pageSize
386389

387390
describe "UpdateGroup :: UserId -> UserGroupId -> UserGroupUpdate -> UserGroupSubsystem m (Maybe UserGroup)" $ do
388391
prop "updateGroup updates the name" $

0 commit comments

Comments
 (0)