Module: GdsApi::TestHelpers::AccountApi
- Defined in:
- lib/gds_api/test_helpers/account_api.rb
Constant Summary collapse
- ACCOUNT_API_ENDPOINT =
Plek.find("account-api")
Instance Method Summary collapse
- #stub_account_api_create_registration_state(attributes: nil, state_id: "state-id") ⇒ Object
- #stub_account_api_does_not_have_email_subscription(**options) ⇒ Object
- #stub_account_api_forbidden_get_attributes_names(attributes: [], needed_level_of_authentication: "level1", **options) ⇒ Object
- #stub_account_api_forbidden_get_email_subscription(needed_level_of_authentication: "level1", **options) ⇒ Object
- #stub_account_api_forbidden_has_attributes(attributes: [], needed_level_of_authentication: "level1", **options) ⇒ Object
- #stub_account_api_forbidden_set_attributes(attributes: nil, needed_level_of_authentication: "level1", **options) ⇒ Object
- #stub_account_api_forbidden_set_email_subscription(slug: nil, needed_level_of_authentication: "level1", **options) ⇒ Object
- #stub_account_api_get_attributes_names(attributes: [], **options) ⇒ Object
- #stub_account_api_get_sign_in_url(redirect_path: nil, state_id: nil, level_of_authentication: nil, auth_uri: "http://auth/provider", state: "state") ⇒ Object
- #stub_account_api_has_attributes(attributes: [], values: {}, **options) ⇒ Object
- #stub_account_api_has_email_subscription(**options) ⇒ Object
- #stub_account_api_rejects_auth_response(code: nil, state: nil) ⇒ Object
- #stub_account_api_request(method, path, with: {}, response_status: 200, response_body: {}, govuk_account_session: nil, new_govuk_account_session: nil) ⇒ Object
- #stub_account_api_set_attributes(attributes: nil, **options) ⇒ Object
- #stub_account_api_set_email_subscription(slug: nil, **options) ⇒ Object
- #stub_account_api_unauthorized_get_attributes_names(attributes: [], **options) ⇒ Object
- #stub_account_api_unauthorized_get_email_subscription(**options) ⇒ Object
- #stub_account_api_unauthorized_has_attributes(attributes: [], **options) ⇒ Object
- #stub_account_api_unauthorized_set_attributes(attributes: nil, **options) ⇒ Object
- #stub_account_api_unauthorized_set_email_subscription(slug: nil, **options) ⇒ Object
- #stub_account_api_validates_auth_response(code: nil, state: nil, govuk_account_session: "govuk-account-session", redirect_path: "/", ga_client_id: "ga-client-id") ⇒ Object
Instance Method Details
#stub_account_api_create_registration_state(attributes: nil, state_id: "state-id") ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 32 def stub_account_api_create_registration_state(attributes: nil, state_id: "state-id") stub_request(:post, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/state") .with(body: hash_including({ attributes: attributes }.compact)) .to_return( status: 200, body: { state_id: state_id }.to_json, ) end |
#stub_account_api_does_not_have_email_subscription(**options) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 50 def stub_account_api_does_not_have_email_subscription(**) stub_account_api_request( :get, "/api/transition-checker-email-subscription", response_body: { has_subscription: false }, **, ) end |
#stub_account_api_forbidden_get_attributes_names(attributes: [], needed_level_of_authentication: "level1", **options) ⇒ Object
189 190 191 192 193 194 195 196 197 198 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 189 def stub_account_api_forbidden_get_attributes_names(attributes: [], needed_level_of_authentication: "level1", **) querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact) stub_account_api_request( :get, "/api/attributes/names?#{querystring}", response_status: 403, response_body: { needed_level_of_authentication: needed_level_of_authentication }, **, ) end |
#stub_account_api_forbidden_get_email_subscription(needed_level_of_authentication: "level1", **options) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 68 def stub_account_api_forbidden_get_email_subscription(needed_level_of_authentication: "level1", **) stub_account_api_request( :get, "/api/transition-checker-email-subscription", response_status: 403, response_body: { needed_level_of_authentication: needed_level_of_authentication }, **, ) end |
#stub_account_api_forbidden_has_attributes(attributes: [], needed_level_of_authentication: "level1", **options) ⇒ Object
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 128 def stub_account_api_forbidden_has_attributes(attributes: [], needed_level_of_authentication: "level1", **) querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact) stub_account_api_request( :get, "/api/attributes?#{querystring}", response_status: 403, response_body: { needed_level_of_authentication: needed_level_of_authentication }, **, ) end |
#stub_account_api_forbidden_set_attributes(attributes: nil, needed_level_of_authentication: "level1", **options) ⇒ Object
158 159 160 161 162 163 164 165 166 167 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 158 def stub_account_api_forbidden_set_attributes(attributes: nil, needed_level_of_authentication: "level1", **) stub_account_api_request( :patch, "/api/attributes", with: { body: hash_including({ attributes: attributes }.compact) }, response_status: 403, response_body: { needed_level_of_authentication: needed_level_of_authentication }, **, ) end |
#stub_account_api_forbidden_set_email_subscription(slug: nil, needed_level_of_authentication: "level1", **options) ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 97 def stub_account_api_forbidden_set_email_subscription(slug: nil, needed_level_of_authentication: "level1", **) stub_account_api_request( :post, "/api/transition-checker-email-subscription", with: { body: hash_including({ slug: slug }.compact) }, response_status: 403, response_body: { needed_level_of_authentication: needed_level_of_authentication }, **, ) end |
#stub_account_api_get_attributes_names(attributes: [], **options) ⇒ Object
169 170 171 172 173 174 175 176 177 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 169 def stub_account_api_get_attributes_names(attributes: [], **) querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact) stub_account_api_request( :get, "/api/attributes/names?#{querystring}", response_body: { values: attributes }, **, ) end |
#stub_account_api_get_sign_in_url(redirect_path: nil, state_id: nil, level_of_authentication: nil, auth_uri: "http://auth/provider", state: "state") ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 8 def stub_account_api_get_sign_in_url(redirect_path: nil, state_id: nil, level_of_authentication: nil, auth_uri: "http://auth/provider", state: "state") querystring = Rack::Utils.build_nested_query({ redirect_path: redirect_path, state_id: state_id, level_of_authentication: level_of_authentication }.compact) stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/sign-in?#{querystring}") .to_return( status: 200, body: { auth_uri: auth_uri, state: state }.to_json, ) end |
#stub_account_api_has_attributes(attributes: [], values: {}, **options) ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 108 def stub_account_api_has_attributes(attributes: [], values: {}, **) querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact) stub_account_api_request( :get, "/api/attributes?#{querystring}", response_body: { values: values }, **, ) end |
#stub_account_api_has_email_subscription(**options) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 41 def stub_account_api_has_email_subscription(**) stub_account_api_request( :get, "/api/transition-checker-email-subscription", response_body: { has_subscription: true }, **, ) end |
#stub_account_api_rejects_auth_response(code: nil, state: nil) ⇒ Object
26 27 28 29 30 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 26 def stub_account_api_rejects_auth_response(code: nil, state: nil) stub_request(:post, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/callback") .with(body: hash_including({ code: code, state: state }.compact)) .to_return(status: 401) end |
#stub_account_api_request(method, path, with: {}, response_status: 200, response_body: {}, govuk_account_session: nil, new_govuk_account_session: nil) ⇒ Object
200 201 202 203 204 205 206 207 208 209 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 200 def stub_account_api_request(method, path, with: {}, response_status: 200, response_body: {}, govuk_account_session: nil, new_govuk_account_session: nil) with.merge!(headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session }) if govuk_account_session new_govuk_account_session = nil if response_status >= 400 to_return = { status: response_status, body: response_body.merge(govuk_account_session: new_govuk_account_session).compact.to_json } if with.empty? stub_request(method, "#{ACCOUNT_API_ENDPOINT}#{path}").to_return(**to_return) else stub_request(method, "#{ACCOUNT_API_ENDPOINT}#{path}").with(**with).to_return(**to_return) end end |
#stub_account_api_set_attributes(attributes: nil, **options) ⇒ Object
139 140 141 142 143 144 145 146 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 139 def stub_account_api_set_attributes(attributes: nil, **) stub_account_api_request( :patch, "/api/attributes", with: { body: hash_including({ attributes: attributes }.compact) }, **, ) end |
#stub_account_api_set_email_subscription(slug: nil, **options) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 78 def stub_account_api_set_email_subscription(slug: nil, **) stub_account_api_request( :post, "/api/transition-checker-email-subscription", with: { body: hash_including({ slug: slug }.compact) }, **, ) end |
#stub_account_api_unauthorized_get_attributes_names(attributes: [], **options) ⇒ Object
179 180 181 182 183 184 185 186 187 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 179 def (attributes: [], **) querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact) stub_account_api_request( :get, "/api/attributes/names?#{querystring}", response_status: 401, **, ) end |
#stub_account_api_unauthorized_get_email_subscription(**options) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 59 def (**) stub_account_api_request( :get, "/api/transition-checker-email-subscription", response_status: 401, **, ) end |
#stub_account_api_unauthorized_has_attributes(attributes: [], **options) ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 118 def (attributes: [], **) querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact) stub_account_api_request( :get, "/api/attributes?#{querystring}", response_status: 401, **, ) end |
#stub_account_api_unauthorized_set_attributes(attributes: nil, **options) ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 148 def (attributes: nil, **) stub_account_api_request( :patch, "/api/attributes", with: { body: hash_including({ attributes: attributes }.compact) }, response_status: 401, **, ) end |
#stub_account_api_unauthorized_set_email_subscription(slug: nil, **options) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 87 def (slug: nil, **) stub_account_api_request( :post, "/api/transition-checker-email-subscription", with: { body: hash_including({ slug: slug }.compact) }, response_status: 401, **, ) end |
#stub_account_api_validates_auth_response(code: nil, state: nil, govuk_account_session: "govuk-account-session", redirect_path: "/", ga_client_id: "ga-client-id") ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/gds_api/test_helpers/account_api.rb', line 17 def stub_account_api_validates_auth_response(code: nil, state: nil, govuk_account_session: "govuk-account-session", redirect_path: "/", ga_client_id: "ga-client-id") stub_request(:post, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/callback") .with(body: hash_including({ code: code, state: state }.compact)) .to_return( status: 200, body: { govuk_account_session: govuk_account_session, redirect_path: redirect_path, ga_client_id: ga_client_id }.to_json, ) end |