Skip to content

Commit 8ec2565

Browse files
committed
Cherry-pick copilot's test corner cases.
1 parent 2be95d5 commit 8ec2565

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

integration/test/API/Spar.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,17 @@ deleteScimUserGroup domain token groupId = do
135135
submit "DELETE" $ req & addHeader "Authorization" ("Bearer " <> token)
136136

137137
filterScimUserGroup :: (HasCallStack, MakesValue domain) => domain -> String -> Maybe String -> App Response
138-
filterScimUserGroup domain token mbFilter = filterScimUserGroupPaginate domain token mbFilter Nothing
138+
filterScimUserGroup domain token mbFilter = filterScimUserGroupPaginate domain token mbFilter Nothing Nothing
139139

140-
filterScimUserGroupPaginate :: (HasCallStack, MakesValue domain) => domain -> String -> Maybe String -> Maybe (Int, Int) -> App Response
141-
filterScimUserGroupPaginate domain token mbFilter mbPage = do
140+
filterScimUserGroupPaginate :: (HasCallStack, MakesValue domain) => domain -> String -> Maybe String -> Maybe Int -> Maybe Int -> App Response
141+
filterScimUserGroupPaginate domain token mbFilter mbStartIndex mbCount = do
142142
req <- baseRequest domain Spar Versioned "/scim/v2/Groups"
143143
submit "GET" $ req
144144
& scimCommonHeaders token
145145
& addQueryParams
146146
( maybe [] (\f -> [("filter", f)]) mbFilter
147-
<> maybe [] (\(startIndex, count) -> [("startIndex", show startIndex), ("count", show count)]) mbPage
147+
<> maybe [] (\startIndex -> [("startIndex", show startIndex)]) mbStartIndex
148+
<> maybe [] (\count -> [("count", show count)]) mbCount
148149
)
149150

150151
mkScimGroup :: String -> [Value] -> Value

integration/test/Test/Spar.hs

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ testSparScimCreateGetSearchUserGroup = do
455455
OwnDomain
456456
tok
457457
(Just $ "displayName co \"" <> substr <> "\"")
458-
(Just (startIndex, count))
458+
(Just startIndex)
459+
(Just count)
459460
createGroup name = createScimUserGroup OwnDomain tok $ mkScimGroup name [mkScimUser scimUserId]
460461

461462
-- Create 20 groups
@@ -468,13 +469,54 @@ testSparScimCreateGetSearchUserGroup = do
468469
count = 7
469470
expectedItemsPerPage = max 0 (min count (expectedTotalResults - startIndex + 1)) -- expected between 0 and `count` depending on if it's a full, half or empty page
470471
in searchPage "newGroupNo" startIndex count `bindResponse` \resp -> do
471-
json' <- resp.json
472-
json' %. "startIndex" `shouldMatchInt` startIndex
473-
json' %. "totalResults" `shouldMatchInt` expectedTotalResults
474-
json' %. "itemsPerPage" `shouldMatchInt` expectedItemsPerPage
475-
resources <- json' %. "Resources" & asList
472+
resp.json %. "startIndex" `shouldMatchInt` startIndex
473+
resp.json %. "totalResults" `shouldMatchInt` expectedTotalResults
474+
resp.json %. "itemsPerPage" `shouldMatchInt` expectedItemsPerPage
475+
resources <- resp.json %. "Resources" & asList
476476
length resources `shouldMatchInt` expectedItemsPerPage
477477

478+
-- 5. Additional pagination edge cases
479+
480+
-- no filter
481+
filterScimUserGroupPaginate OwnDomain tok Nothing (Just 1) (Just 3) `bindResponse` \resp -> do
482+
resp.json %. "startIndex" `shouldMatchInt` 1
483+
resources <- resp.json %. "Resources" & asList
484+
length resources `shouldMatchInt` 3
485+
486+
-- startIndex=0 edge case (should be treated as 1 according to SCIM spec)
487+
filterScimUserGroupPaginate OwnDomain tok (Just "displayName co \"newGroupNo\"") (Just 0) (Just 5) `bindResponse` \resp -> do
488+
-- startIndex of 0 should be treated as 1
489+
resources <- resp.json %. "Resources" & asList
490+
length resources `shouldMatchInt` 5
491+
492+
-- Only startIndex, no count
493+
filterScimUserGroupPaginate OwnDomain tok (Just "displayName co \"newGroupNo\"") (Just 5) Nothing `bindResponse` \resp -> do
494+
resp.json %. "startIndex" `shouldMatchInt` 5
495+
resp.json %. "totalResults" `shouldMatchInt` expectedTotalResults
496+
497+
-- Only count, no startIndex
498+
filterScimUserGroupPaginate OwnDomain tok (Just "displayName co \"newGroupNo\"") Nothing (Just 3) `bindResponse` \resp -> do
499+
resp.json %. "startIndex" `shouldMatchInt` 1
500+
resp.json %. "itemsPerPage" `shouldMatchInt` 3
501+
resources <- resp.json %. "Resources" & asList
502+
length resources `shouldMatchInt` 3
503+
504+
-- 5e. Filter with empty result
505+
filterScimUserGroupPaginate OwnDomain tok (Just "displayName co \"nonexistent-filter-xyz\"") (Just 1) (Just 10) `bindResponse` \resp -> do
506+
resp.json %. "startIndex" `shouldMatchInt` 1
507+
resp.json %. "totalResults" `shouldMatchInt` 0
508+
resp.json %. "itemsPerPage" `shouldMatchInt` 0
509+
resources <- resp.json %. "Resources" & asList
510+
length resources `shouldMatchInt` 0
511+
512+
-- 5f. All results in less than one page
513+
filterScimUserGroupPaginate OwnDomain tok (Just "displayName co \"newGroupNo\"") (Just 1) (Just 100) `bindResponse` \resp -> do
514+
resp.json %. "startIndex" `shouldMatchInt` 1
515+
resp.json %. "totalResults" `shouldMatchInt` expectedTotalResults
516+
resp.json %. "itemsPerPage" `shouldMatchInt` expectedTotalResults
517+
resources <- resp.json %. "Resources" & asList
518+
length resources `shouldMatchInt` expectedTotalResults
519+
478520
testSparScimUpdateUserGroup :: (HasCallStack) => App ()
479521
testSparScimUpdateUserGroup = do
480522
(alice, tid, []) <- createTeam OwnDomain 1

0 commit comments

Comments
 (0)