Files

46 lines
1.3 KiB
Ruby

# frozen_string_literal: true
require "json"
require "base64"
require "fiken"
require "webmock/rspec"
require "vcr"
VCR.configure do |config|
config.cassette_library_dir = "spec/cassettes"
config.hook_into :webmock
config.configure_rspec_metadata!
config.default_cassette_options = { record: :none }
config.filter_sensitive_data("<FIKEN_TOKEN>") { ENV.fetch("FIKEN_TOKEN", nil) }
end
RSpec.configure do |config|
config.expect_with(:rspec) { |c| c.syntax = :expect }
config.disable_monkey_patching!
config.order = :random
Kernel.srand config.seed
config.example_status_persistence_file_path = ".rspec_status"
end
API_BASE = "https://api.fiken.no/api/v2"
def stub_fiken(method, path, status: 200, body: "", headers: {})
stub_request(method, "#{API_BASE}#{path}")
.to_return(
status: status,
body: body.is_a?(String) ? body : JSON.generate(body),
headers: { "Content-Type" => "application/json" }.merge(headers)
)
end
# Convenience: a Location response header pointing at an API path.
def location(path)
{ "Location" => "#{API_BASE}#{path}" }
end
# Stub a create endpoint that returns 201 with a Location header (no body).
def stub_created(method, path, to:)
stub_fiken(method, path, status: 201, headers: location(to))
end