# 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