-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add activity timestamp to csv export
- Loading branch information
1 parent
3a88043
commit 5c4b3e5
Showing
4 changed files
with
93 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{-# OPTIONS -Wno-ambiguous-fields #-} | ||
-- This file is part of the Wire Server implementation. | ||
-- | ||
-- Copyright (C) 2024 Wire Swiss GmbH <[email protected]> | ||
|
@@ -22,6 +23,7 @@ import qualified API.BrigInternal as I | |
import API.Common | ||
import API.Galley (getTeam, getTeamMembers, getTeamMembersCsv, getTeamNotifications) | ||
import API.GalleyInternal (setTeamFeatureStatus) | ||
import API.Gundeck | ||
import Control.Monad.Codensity (Codensity (runCodensity)) | ||
import Control.Monad.Extra (findM) | ||
import Control.Monad.Reader (asks) | ||
|
@@ -283,16 +285,28 @@ testUpgradePersonalToTeamAlreadyInATeam = do | |
|
||
testTeamMemberCsvExport :: (HasCallStack) => App () | ||
testTeamMemberCsvExport = do | ||
(owner, tid, members) <- createTeam OwnDomain 10 | ||
let numClients = [0, 1, 2] <> repeat 0 | ||
modifiedMembers <- for (zip numClients (owner : members)) $ \(n, m) -> do | ||
handle <- randomHandle | ||
putHandle m handle >>= assertSuccess | ||
replicateM_ n $ addClient m def | ||
void $ I.putSSOId m def {I.scimExternalId = Just "foo"} >>= getBody 200 | ||
setField "handle" handle m | ||
>>= setField "role" (if m == owner then "owner" else "member") | ||
>>= setField "num_clients" (show n) | ||
(owner, tid, members) <- createTeam OwnDomain 5 | ||
|
||
modifiedMembers <- for | ||
( zip | ||
([0, 1, 2] <> repeat 0) | ||
(owner : members) | ||
) | ||
$ \(n, m) -> do | ||
handle <- randomHandle | ||
putHandle m handle >>= assertSuccess | ||
clients <- | ||
replicateM n | ||
$ addClient m def | ||
>>= getJSON 201 | ||
>>= (%. "id") | ||
>>= asString | ||
for_ (listToMaybe clients) $ \c -> | ||
getNotifications m def {client = Just c} | ||
void $ I.putSSOId m def {I.scimExternalId = Just "foo"} >>= getBody 200 | ||
setField "handle" handle m | ||
>>= setField "role" (if m == owner then "owner" else "member") | ||
>>= setField "num_clients" n | ||
|
||
memberMap :: Map.Map String Value <- fmap Map.fromList $ for (modifiedMembers) $ \m -> do | ||
uid <- m %. "id" & asString | ||
|
@@ -301,14 +315,16 @@ testTeamMemberCsvExport = do | |
bindResponse (getTeamMembersCsv owner tid) $ \resp -> do | ||
resp.status `shouldMatchInt` 200 | ||
let rows = sort $ tail $ B8.lines $ resp.body | ||
length rows `shouldMatchInt` 10 | ||
length rows `shouldMatchInt` 5 | ||
for_ rows $ \row -> do | ||
let cols = B8.split ',' row | ||
let uid = read $ B8.unpack $ cols !! 11 | ||
let mem = memberMap Map.! uid | ||
|
||
ownerId <- owner %. "id" & asString | ||
let ownerMember = memberMap Map.! ownerId | ||
now <- formatTime defaultTimeLocale "%Y-%m-%d" <$> liftIO getCurrentTime | ||
numClients <- mem %. "num_clients" & asInt | ||
|
||
let parseField = unquote . read . B8.unpack . (cols !!) | ||
|
||
|
@@ -318,12 +334,14 @@ testTeamMemberCsvExport = do | |
role <- mem %. "role" & asString | ||
parseField 3 `shouldMatch` role | ||
when (role /= "owner") $ do | ||
now <- formatTime defaultTimeLocale "%Y-%m-%d" <$> liftIO getCurrentTime | ||
take 10 (parseField 4) `shouldMatch` now | ||
parseField 5 `shouldMatch` (ownerMember %. "handle") | ||
parseField 7 `shouldMatch` "wire" | ||
parseField 9 `shouldMatch` "foo" | ||
parseField 12 `shouldMatch` (mem %. "num_clients") | ||
parseField 12 `shouldMatch` show numClients | ||
(if numClients > 0 then shouldNotMatch else shouldMatch) | ||
(parseField 13) | ||
"" | ||
where | ||
unquote :: String -> String | ||
unquote ('\'' : x) = x | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters