require 'spec_helper' describe ActiveFedora::FixityService do let(:service) { described_class.new(uri) } let(:uri) { RDF::URI("http://path/to/resource") } let(:passing_fedora44_response_body) { <<-EOF @prefix premis: . premis:hasFixity . a premis:Fixity , premis:EventOutcomeDetail ; premis:hasEventOutcome "SUCCESS"^^ ; premis:hasMessageDigest ; premis:hasSize "103945"^^ . EOF } let(:failing_fedora44_response_body) { <<-EOF @prefix premis: . premis:hasFixity . a premis:Fixity , premis:EventOutcomeDetail ; premis:hasEventOutcome "BAD_CHECKSUM"^^ , "BAD_SIZE"^^ ; premis:hasMessageDigest ; premis:hasSize "1878582"^^ . EOF } describe "the instance" do subject { described_class.new(uri) } it { is_expected.to respond_to(:response) } end describe "initialize" do context "with a string" do subject { service.target } let(:uri) { 'http://path/to/resource' } it { is_expected.to eq 'http://path/to/resource' } end context "with an RDF::URI" do subject { service.target } it { is_expected.to eq 'http://path/to/resource' } end end describe "#verified?" do before { allow(service).to receive(:fixity_response_from_fedora).and_return(response) } subject { service.verified? } context "with Fedora version >= 4.4.0" do context "with a passing result" do let(:response) do instance_double("Response", body: passing_fedora44_response_body) end it { is_expected.to be true } end context "with a failing result" do let(:response) do instance_double("Response", body: failing_fedora44_response_body) end it { is_expected.to be false } end end context "with Fedora version < 4.4.0" do context "with a passing result" do let(:response) do instance_double("Response", body: ' "SUCCESS"^^ .') end it { is_expected.to be true } end context "with a failing result" do let(:response) do instance_double("Response", body: ' "BAD_CHECKSUM"^^ .') end it { is_expected.to be false } end end context "with a non-existent predicate" do let(:response) do instance_double("Response", body: ' "SUCCESS"^^ .') end it { is_expected.to be false } end end describe "expected_message_digest" do before { allow(service).to receive(:fixity_response_from_fedora).and_return(response) } subject { service.expected_message_digest } context "with success response" do let(:response) do instance_double("Response", body: passing_fedora44_response_body) end it { is_expected.to match(/urn:sha1:[a-f0-9]+/) } end context "with failure response" do let(:response) do instance_double("Response", body: failing_fedora44_response_body) end it { is_expected.to match(/urn:sha1:[a-f0-9]+/) } end end describe "expected_size" do before { allow(service).to receive(:fixity_response_from_fedora).and_return(response) } subject { service.expected_size } context "with success response" do let(:response) do instance_double("Response", body: passing_fedora44_response_body) end it { is_expected.to be_kind_of Numeric } end context "with failure response" do let(:response) do instance_double("Response", body: failing_fedora44_response_body) end it { is_expected.to be_kind_of Numeric } end end end