Files
redux-scraper/spec/factories/http_log_entries.rb
2025-02-25 19:59:41 +00:00

56 lines
1.3 KiB
Ruby

# typed: false
FactoryBot.define do
factory :http_log_entry do
transient { uri_str { "https://example.com/path" } }
uri_host { URI.parse(uri_str).host }
uri_scheme { URI.parse(uri_str).scheme }
uri_path { URI.parse(uri_str).path }
uri_query { URI.parse(uri_str).query }
verb { :get }
status_code { 200 }
content_type { "text/html" }
response_time_ms { 100 }
requested_at { Time.current }
created_at { Time.current }
performed_by { "direct" }
# Create associated records
association :response, factory: :blob_file
association :request_headers, factory: :http_log_entry_header
association :response_headers, factory: :http_log_entry_header
# Set the response_sha256 to match the associated response
after(:build) do |entry|
entry.response_sha256 = entry.response.sha256 if entry.response
end
trait :post_request do
verb { :post }
end
trait :with_query do
uri_query { "foo=bar&baz=qux" }
end
trait :with_fragment do
uri_hash { "section1" }
end
trait :with_error do
status_code { 404 }
end
trait :with_caused_by do
association :caused_by_entry, factory: :http_log_entry
end
trait :legacy do
performed_by { "legacy" }
end
trait :proxy do
performed_by { "proxy-1" }
end
end
end