Skip to content

[WPB-17534] user groups: getGroups, getGroupsForUser #4571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 96 commits into
base: WPB-16870-user-groups-everything
Choose a base branch
from

Conversation

fisx
Copy link
Contributor

@fisx fisx commented May 12, 2025

https://wearezeta.atlassian.net/browse/WPB-17534

Checklist

  • Add a new entry in an appropriate subdirectory of changelog.d
  • Read and follow the PR guidelines

fisx and others added 30 commits May 6, 2025 13:18
featuring:
- effect
- data types
- test skeleton
- mock interpreter skeleton
the qualified import in Main is needed for some test setups involving
ghcid and cabal-repl; moving all deps to the common section in the
cabal file just seemed more ergonomic?
Create multiple reset targets, so they can be individually run
@zebot zebot added the ok-to-test Approved for running tests in CI, overrides not-ok-to-test if both labels exist label May 12, 2025
@fisx fisx force-pushed the WPB-16870-user-groups-get-many branch from 51af4c6 to 4a22507 Compare May 12, 2025 12:15
@fisx fisx changed the base branch from develop to WPB-16870-user-groups-everything May 12, 2025 12:22
@fisx fisx force-pushed the WPB-16870-user-groups-everything branch from 0728806 to 1771be6 Compare May 12, 2025 12:24
@fisx fisx force-pushed the WPB-16870-user-groups-get-many branch from 4a22507 to e762830 Compare May 12, 2025 12:31
@fisx fisx force-pushed the WPB-16870-user-groups-everything branch from e475cbe to 057d319 Compare May 13, 2025 11:51
@fisx
Copy link
Contributor Author

fisx commented May 13, 2025

forgot to add this:

    describe "GetGroups :: UserId -> Maybe Int -> Maybe UUID -> UserGroupSubsystem m UserGroupPage" $ do
      let nugs = [1 .. 15] <&> \(i :: Int) -> NewUserGroup (either (error . show) id $ userGroupNameFromText $ cs $ show i) mempty

          check :: UserGroupPage -> [UserGroupId] -> Bool -> Property
          check have wantPage wantHasMore = (have.page <&> (.id_)) === wantPage .&&. have.hasMore === wantHasMore

          lastKeyOf :: UserGroupPage -> UserGroupId
          lastKeyOf = Id . toUUID . (.id_) . last . (.page)

      prop "pagination (static case): eventually gives you the entire data set (nothing gets removed or duplicated)" $
        \team ->
          expectRight
            . runDependencies (allUsers team) (galleyTeam team)
            . interpretUserGroupSubsystem
            $ do
              let owner = qUnqualified (fst team.owner).userQualifiedId
              gids <- (sort . ((.id_) <$>)) <$> createGroup owner `mapM` nugs
              allOfThem <- getGroups owner Nothing Nothing
              first3 <- getGroups owner (Just 3) Nothing
              next4 <- getGroups owner (Just 4) (Just $ lastKeyOf first3)

              pure $
                check allOfThem gids False
                  .&&. check first3 (take 3 gids) True
                  .&&. check next4 (take 4 (drop 3 gids)) True

      prop "paginates well under updates" $ do
        \team ->
          expectRight
            . runDependencies (allUsers team) (galleyTeam team)
            . interpretUserGroupSubsystem
            $ do
              let owner = qUnqualified (fst team.owner).userQualifiedId
              gids <- (sort . ((.id_) <$>)) <$> createGroup owner `mapM` nugs

              -- read first page
              beforeNewCreate <- getGroups owner (Just 8) Nothing
              -- mess with database
              newGroup <- createGroup owner (NewUserGroup (either (error . show) id $ userGroupNameFromText "the new one") mempty)
              -- read second page
              afterNewCreate <- getGroups owner Nothing (Just $ lastKeyOf beforeNewCreate)

              pure $
                check beforeNewCreate (take 8 gids) True
                  .&&. let afterGids = drop 8 (sort (newGroup.id_ : gids))
                        in check afterNewCreate afterGids False

@fisx fisx force-pushed the WPB-16870-user-groups-everything branch 5 times, most recently from 26779f6 to 490c879 Compare May 21, 2025 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Approved for running tests in CI, overrides not-ok-to-test if both labels exist
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants