Skip to content

Commit

Permalink
Merge pull request #1283 from Shopify/api-tests-as-json
Browse files Browse the repository at this point in the history
Improve API tests
  • Loading branch information
casperisfine committed Sep 15, 2022
2 parents 01eb91c + 18ce175 commit bcf8adf
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion test/controllers/api/base_controller_test.rb
Expand Up @@ -3,7 +3,7 @@

module Shipit
module Api
class BaseControllerTest < ActionController::TestCase
class BaseControllerTest < ApiControllerTestCase
test "authentication is required" do
get :index
assert_response :unauthorized
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/ccmenu_controller_test.rb
Expand Up @@ -3,7 +3,7 @@

module Shipit
module Api
class CCMenuControllerTest < ActionController::TestCase
class CCMenuControllerTest < ApiControllerTestCase
setup do
authenticate!
@stack = shipit_stacks(:shipit)
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/commits_controller_test.rb
Expand Up @@ -3,7 +3,7 @@

module Shipit
module Api
class CommitsControllerTest < ActionController::TestCase
class CommitsControllerTest < ApiControllerTestCase
setup do
@stack = shipit_stacks(:shipit)
authenticate!
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/deploys_controller_test.rb
Expand Up @@ -3,7 +3,7 @@

module Shipit
module Api
class DeploysControllerTest < ActionController::TestCase
class DeploysControllerTest < ApiControllerTestCase
setup do
authenticate!
@user = shipit_users(:walrus)
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/hooks_controller_test.rb
Expand Up @@ -3,7 +3,7 @@

module Shipit
module Api
class HooksControllerTest < ActionController::TestCase
class HooksControllerTest < ApiControllerTestCase
setup do
authenticate!
@stack = shipit_stacks(:shipit)
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/locks_controller_test.rb
Expand Up @@ -3,7 +3,7 @@

module Shipit
module Api
class LocksControllerTest < ActionController::TestCase
class LocksControllerTest < ApiControllerTestCase
setup do
authenticate!
@stack = shipit_stacks(:shipit)
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/merge_requests_controller_test.rb
Expand Up @@ -3,7 +3,7 @@

module Shipit
module Api
class MergeRequestsControllerTest < ActionController::TestCase
class MergeRequestsControllerTest < ApiControllerTestCase
setup do
@stack = shipit_stacks(:shipit)
@merge_request = shipit_merge_requests(:shipit_pending)
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/outputs_controller_test.rb
Expand Up @@ -3,7 +3,7 @@

module Shipit
module Api
class OutputsControllerTest < ActionController::TestCase
class OutputsControllerTest < ApiControllerTestCase
setup do
@stack = shipit_stacks(:shipit)
authenticate!
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/release_statuses_controller_test.rb
Expand Up @@ -3,7 +3,7 @@

module Shipit
module Api
class ReleaseStatusesControllerTest < ActionController::TestCase
class ReleaseStatusesControllerTest < ApiControllerTestCase
setup do
authenticate!
@stack = shipit_stacks(:shipit_canaries)
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/rollback_controller_test.rb
Expand Up @@ -3,7 +3,7 @@

module Shipit
module Api
class RollbacksControllerTest < ActionController::TestCase
class RollbacksControllerTest < ApiControllerTestCase
setup do
authenticate!
@user = shipit_users(:walrus)
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/stacks_controller_test.rb
Expand Up @@ -3,7 +3,7 @@

module Shipit
module Api
class StacksControllerTest < ActionController::TestCase
class StacksControllerTest < ApiControllerTestCase
setup do
authenticate!
@stack = shipit_stacks(:shipit)
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/tasks_controller_test.rb
Expand Up @@ -3,7 +3,7 @@

module Shipit
module Api
class TasksControllerTest < ActionController::TestCase
class TasksControllerTest < ApiControllerTestCase
setup do
@stack = shipit_stacks(:shipit)
@user = shipit_users(:walrus)
Expand Down
13 changes: 13 additions & 0 deletions test/helpers/api_helper.rb
Expand Up @@ -8,3 +8,16 @@ def authenticate!(client = @client || :spy)
request.headers['Authorization'] = "Basic #{Base64.encode64(client.authentication_token)}"
end
end

module Shipit
class ApiControllerTestCase < ActionController::TestCase
private

def process(_action, **kwargs)
if kwargs[:method] != "GET"
kwargs[:as] ||= :json
end
super
end
end
end

0 comments on commit bcf8adf

Please sign in to comment.