# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Work do
  subject(:work) { build(:work, collection: collection, assign_doi: assign_doi) }

  let(:assign_doi) { false }

  let(:collection) { build(:collection, doi_option: collection_doi_option) }
  let(:collection_doi_option) { 'yes' }

  it 'belongs to a collection' do
    expect(work.collection).to be_a(Collection)
  end

  describe '#purl' do
    context 'with a druid' do
      it 'constructs purl' do
        work.update(druid: 'druid:hb093rg5848')
        expect(work.purl).to eq 'https://purl.stanford.edu/hb093rg5848'
      end
    end

    context 'with no druid' do
      it 'returns nil' do
        expect(work.purl).to be_nil
      end
    end
  end
end
