Files
MatchLiveTv/backend/spec/requests/analytics/snapshots_spec.rb
eminuxandCursor 70fccc493e Usa screenshot di pagina come sfondo heatmap al posto dell’iframe.
Cattura periodica client-side (con consenso), storage ActiveStorage e overlay allineato all’immagine.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-20 23:14:47 +02:00

45 lines
1.2 KiB
Ruby

# frozen_string_literal: true
require "rails_helper"
RSpec.describe "Analytics snapshots", type: :request do
def jpeg_upload
path = Rails.root.join("tmp/analytics-snap-test.jpg")
FileUtils.mkdir_p(path.dirname)
# minimal valid-ish jpeg bytes for ActiveStorage
File.binwrite(path, "\xFF\xD8\xFF\xE0#{'x' * 12_000}\xFF\xD9")
Rack::Test::UploadedFile.new(path, "image/jpeg")
end
it "accetta uno screenshot e lo associa al path" do
post "/analytics/snapshot",
params: {
path: "/prezzi",
device: "desktop",
width: 1440,
height: 2200,
image: jpeg_upload
}
expect(response).to have_http_status(:accepted)
snap = AnalyticsPageSnapshot.find_by(page_path: "/prezzi", device: "desktop")
expect(snap).to be_present
expect(snap.image).to be_attached
expect(snap.width).to eq(1440)
end
it "rifiuta path esclusi" do
post "/analytics/snapshot",
params: {
path: "/admin/analytics",
device: "desktop",
width: 1440,
height: 900,
image: jpeg_upload
}
expect(response).to have_http_status(:unprocessable_content)
expect(AnalyticsPageSnapshot.count).to eq(0)
end
end