require 'rails_helper'

RSpec.describe MaterialFileSha256 do
  describe '.metadata_sha256' do
    it 'reads sha256 from Hash metadata' do
      blob = instance_double(ActiveStorage::Blob, metadata: { 'sha256' => 'abc123' })

      expect(described_class.metadata_sha256(blob)).to eq('abc123')
    end

    it 'reads sha256 from JSON string metadata' do
      blob = instance_double(ActiveStorage::Blob, metadata: '{"sha256":"abc123"}')

      expect(described_class.metadata_sha256(blob)).to eq('abc123')
    end

    it 'returns nil for invalid metadata' do
      blob = instance_double(ActiveStorage::Blob, metadata: '{')

      expect(described_class.metadata_sha256(blob)).to be_nil
    end
  end
end
