Module: DeviseScim::Minitest::ScimAssertions
- Defined in:
- lib/devise_scim/minitest.rb
Instance Method Summary collapse
- #assert_scim_content_type(response) ⇒ Object
- #assert_scim_error(response, expected_status: nil) ⇒ Object
- #assert_scim_list_response(response) ⇒ Object
- #assert_scim_schema(response, expected_schema) ⇒ Object
- #assert_scim_status(response, expected_status) ⇒ Object
- #scim_auth_headers(token) ⇒ Object
- #scim_json(response) ⇒ Object
- #scim_patch_payload(*operations) ⇒ Object
- #scim_user_payload(user_name:, **attrs) ⇒ Object
Instance Method Details
#assert_scim_content_type(response) ⇒ Object
11 12 13 14 |
# File 'lib/devise_scim/minitest.rb', line 11 def assert_scim_content_type(response) assert_includes response.content_type, "application/scim+json", "Expected Content-Type application/scim+json" end |
#assert_scim_error(response, expected_status: nil) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/devise_scim/minitest.rb', line 29 def assert_scim_error(response, expected_status: nil) body = JSON.parse(response.body) assert_includes body["schemas"], DeviseScim::Scim::ERROR_SCHEMA, "Expected SCIM error schema in response" assert_equal expected_status.to_s, body["status"] if expected_status end |
#assert_scim_list_response(response) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/devise_scim/minitest.rb', line 22 def assert_scim_list_response(response) body = JSON.parse(response.body) assert_scim_schema(response, DeviseScim::Scim::LIST_RESPONSE_SCHEMA) assert body.key?("totalResults"), "Expected totalResults key in ListResponse" assert body.key?("Resources"), "Expected Resources key in ListResponse" end |
#assert_scim_schema(response, expected_schema) ⇒ Object
16 17 18 19 20 |
# File 'lib/devise_scim/minitest.rb', line 16 def assert_scim_schema(response, expected_schema) body = JSON.parse(response.body) assert_includes body["schemas"], expected_schema, "Expected schema #{expected_schema.inspect} in #{body["schemas"].inspect}" end |
#assert_scim_status(response, expected_status) ⇒ Object
6 7 8 9 |
# File 'lib/devise_scim/minitest.rb', line 6 def assert_scim_status(response, expected_status) assert_equal expected_status.to_s, response.status.to_s, "Expected SCIM status #{expected_status}, got #{response.status}\n#{response.body}" end |
#scim_auth_headers(token) ⇒ Object
40 41 42 |
# File 'lib/devise_scim/minitest.rb', line 40 def scim_auth_headers(token) { "Authorization" => "Bearer #{token}", "Content-Type" => "application/json" } end |
#scim_json(response) ⇒ Object
36 37 38 |
# File 'lib/devise_scim/minitest.rb', line 36 def scim_json(response) JSON.parse(response.body) end |
#scim_patch_payload(*operations) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/devise_scim/minitest.rb', line 49 def scim_patch_payload(*operations) { "schemas" => ["urn:ietf:params:scim:api:messages:2.0:PatchOp"], "Operations" => operations } end |
#scim_user_payload(user_name:, **attrs) ⇒ Object
44 45 46 47 |
# File 'lib/devise_scim/minitest.rb', line 44 def scim_user_payload(user_name:, **attrs) { "schemas" => [DeviseScim::Scim::USER_SCHEMA], "userName" => user_name } .merge(attrs.transform_keys(&:to_s)) end |