Files
growstuff/spec/support/api_request_helpers.rb
T
Brenda Wallace 73f62d4983 Add API resources for photos, plantings, and seeds; update application configuration
- Introduced `PhotoResource`, `PlantingResource`, and `SeedResource` to manage respective models.
- Updated application configuration to include API base URL.
- Modified production and test environments to set API base URL dynamically.
- Removed outdated JSONAPI resources initializers and patches.
- Refactored routes to use resourceful routing for API endpoints.
- Updated request specs to reflect changes in API responses and relationships.
- Added helper methods for generating related links in request specs.
2026-10-24 18:19:11 +13:00

30 lines
950 B
Ruby

# frozen_string_literal: true
# Headers, a member holding an API token, and the parsed response body for specs of /api/v1.
RSpec.shared_context 'with an API member' do
let(:member) { create(:member) }
let(:token) do
member.regenerate_api_token
member.api_token.token
end
let(:read_headers) { { 'Accept' => 'application/vnd.api+json' } }
let(:write_headers) { read_headers.merge('Content-Type' => 'application/vnd.api+json') }
let(:auth_headers) { write_headers.merge('Authorization' => "Bearer #{token}") }
# Not a memoised let: specs that make several requests need the body of the latest.
def json
JSON.parse(response.body)
end
end
module ApiLinkHelpers
# How a resource links to what it is related to.
def related_link(path)
{ 'links' => { 'related' => "http://www.example.com/api/v1/#{path}" } }
end
end
RSpec.configure do |config|
config.include ApiLinkHelpers, file_path: %r{spec/requests/api}
end