Push down some currently-unused/leftover code that applies metadata to tests, and then use it to set Content-Type and Accept headers for API tests to the correct default. Negative tests can override them a second time. Currently, this doesn't break any tests, but when one enables checking requests and responses to the openapi schema, it does. This is a backport from an development branch.
22 lines
693 B
Ruby
22 lines
693 B
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "../spec_helper"
|
|
|
|
def login_api(email = TEST_USER_EMAIL, password = TEST_USER_PASSWORD)
|
|
post "/api/login", JSON.generate(login: email, password: password), {"CONTENT_TYPE" => "application/json"}
|
|
expect(last_response.status).to eq(200)
|
|
header "Authorization", "Bearer #{last_response.headers["authorization"]}"
|
|
end
|
|
|
|
RSpec.configure do |config|
|
|
config.define_derived_metadata(file_path: %r{\A\./spec/routes/api/}) do |metadata|
|
|
metadata[:clover_api] = true
|
|
end
|
|
|
|
config.before do |example|
|
|
next unless example.metadata[:clover_api]
|
|
header "Content-Type", "application/json"
|
|
header "Accept", "application/json"
|
|
end
|
|
end
|