Skip to content

Commit

Permalink
[JEDI-382] Forward pagination parameters to SCIM (#397)
Browse files Browse the repository at this point in the history
https://runway.powerhrg.com/backlog_items/JEDI-382

Before, both
```
curl -X GET 'http://localhost:3000/audiences/scim/Titles?count=1' | json_pp
```
and
```
curl -X GET 'http://localhost:3000/audiences/scim/Titles?startIndex=101' | json_pp
```
returned the same response as a simple `GET /audiences/scim/Titles`. The
`count` and `startIndex` parameters are valid for paginating SCIM and
work when querying `https://id.powerhrg.com/api/scim` directly. This
change forwards both parameters (if present) so that the SCIM request
includes them.
  • Loading branch information
codemonium authored Oct 9, 2024
1 parent 17bf46c commit b89149e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Audiences
class ScimProxyController < ApplicationController
def get
resources = Audiences::Scim.resource(params[:scim_path].to_sym)
.query(filter: params[:filter])
.query(filter: params[:filter], startIndex: params[:startIndex], count: params[:count])

render json: resources, except: %w[schemas meta]
end
Expand Down
28 changes: 26 additions & 2 deletions audiences/spec/requests/scim_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
context "GET /audiences/scim" do
it "returns the Resources key from the response" do
attrs = "id,externalId,displayName"
stub_request(:get, "http://example.com/scim/v2/MyResources?attributes=#{attrs}&filter=name eq John")
query = "attributes=#{attrs}&count&filter=name eq John&startIndex"
stub_request(:get, "http://example.com/scim/v2/MyResources?#{query}")
.to_return(status: 200, body: response_body, headers: {})

get audience_scim_proxy_path(scim_path: "MyResources", filter: "name eq John")
Expand All @@ -42,9 +43,32 @@
])
end

it "returns 'count' resources" do
attrs = "id,externalId,displayName"
query = "attributes=#{attrs}&count=1&filter&startIndex"
stub_request(:get, "http://example.com/scim/v2/MyResources?#{query}")
.to_return(status: 200, body: { Resources: resources.slice(0, 1) }.to_json, headers: {})

get audience_scim_proxy_path(scim_path: "MyResources", count: 1)

expect(response.parsed_body).to match([{ "displayName" => "A Name", "externalId" => "1", "photos" => "photo 1" }])
end

it "returns resources starting from 'startIndex'" do
attrs = "id,externalId,displayName"
query = "attributes=#{attrs}&count&filter&startIndex=3"
stub_request(:get, "http://example.com/scim/v2/MyResources?#{query}")
.to_return(status: 200, body: { Resources: resources.slice(2, 1) }.to_json, headers: {})

get audience_scim_proxy_path(scim_path: "MyResources", startIndex: 3)

expect(response.parsed_body).to match([{ "displayName" => "YAN", "externalId" => "3", "photos" => "photo 3" }])
end

it "removes the schemas and meta from the resources" do
attrs = "id,externalId,displayName"
stub_request(:get, "http://example.com/scim/v2/MyResources?attributes=#{attrs}&filter=name eq John")
query = "attributes=#{attrs}&count&filter=name eq John&startIndex"
stub_request(:get, "http://example.com/scim/v2/MyResources?#{query}")
.to_return(status: 200, body: response_body, headers: {})

get audience_scim_proxy_path(scim_path: "MyResources", filter: "name eq John")
Expand Down

0 comments on commit b89149e

Please sign in to comment.