Skip to content

Refactor api admin mode shared examples

What does this MR do and why?

We have recently introduced API admin mode. You can learn more about it in the issue linked here.

We have adde some shared examples in order to test the new feature. More here, !113226 (merged), !113755 (merged) and !111198 (merged)

We were discussin in this thread how we could improve the shared examples. This MR is an approach to achieve this target.

I have removed the option to call the tests for a specific type of user, such as when user or when admin. Instead, the shared example now applies only to both user types.

For example, instead of using

it_behaves_like 'DELETE request permissions for admin mode when user'

or

it_behaves_like 'DELETE request permissions for admin mode when admin'

you should use only

it_behaves_like 'DELETE request permissions for admin mode' 

for all tests related to admin mode.

Through using the shared example, I realized that there is no scenario where we need to differentiate between the two user types. The primary purpose of the shared example is to test the admin mode, and it should remain focused on this objective. The only case where we may need to distinguish between user types is when refactoring API calls and hiding them behind shared examples but this is another story.

🛠 with at Siemens

How to set up and validate locally

  • run bin/rspec spec/requests/api/deploy_tokens_spec.rb
  • run bin/rspec spec/requests/api/deploy_keys_spec.rb
  • run bin/rspec spec/requests/api/freeze_periods_spec.rb
  • run bin/rspec spec/requests/api/admin/sidekiq_spec.rb

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Andreas Deicha

Merge request reports