Sha256: 51a1d4497badccb6f8130f69d5434d92b46eb3450807b416aeec08c19e7752d6

Contents?: true

Size: 2 KB

Versions: 10

Compression:

Stored size: 2 KB

Contents

require 'spec_helper'

describe Hyrax::Arkivo::CreateSubscriptionJob do
  let(:user) { create(:user) }

  context 'with a bogus user' do
    before { allow(User).to receive(:find_by_user_key) { nil } }
    it 'raises because user not found' do
      expect { described_class.perform_now(user.user_key) }.to raise_error(Hyrax::Arkivo::SubscriptionError, 'User not found')
    end
  end

  context 'without an arkivo token' do
    before { allow_any_instance_of(User).to receive(:arkivo_token) { nil } }
    it 'raises because user lacks arkivo token' do
      expect { described_class.perform_now(user.user_key) }.to raise_error(Hyrax::Arkivo::SubscriptionError, 'User does not have an Arkivo token')
    end
  end

  context 'without a zotero userid' do
    it 'raises because user did not oauth' do
      expect { described_class.perform_now(user.user_key) }.to raise_error(Hyrax::Arkivo::SubscriptionError, 'User has not yet connected with Zotero')
    end
  end

  context 'with an existing subscription' do
    before do
      allow_any_instance_of(User).to receive(:zotero_userid) { '45352' }
      allow_any_instance_of(User).to receive(:arkivo_subscription) { 'http://localhost/foo/bar' }
    end

    it 'raises because user already has subscription' do
      expect { described_class.perform_now(user.user_key) }.to raise_error(Hyrax::Arkivo::SubscriptionError, 'User already has a subscription')
    end
  end

  context 'when expected to succeed' do
    before do
      allow_any_instance_of(User).to receive(:zotero_userid) { '45352' }
      allow_any_instance_of(described_class).to receive(:post_to_api) { response }
    end

    let(:response) { double('response', headers: { 'Location' => subscription_uri }) }
    let(:subscription_uri) { '/api/subscription/abcxyz1234' }

    it 'stores a subscription URL for possible later invalidation' do
      expect(user.arkivo_subscription).to be_blank
      described_class.perform_now(user.user_key)
      expect(user.reload.arkivo_subscription).to eq subscription_uri
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
hyrax-1.1.1 spec/lib/hyrax/arkivo/create_subscription_job_spec.rb
hyrax-1.1.0 spec/lib/hyrax/arkivo/create_subscription_job_spec.rb
hyrax-1.0.5 spec/lib/hyrax/arkivo/create_subscription_job_spec.rb
hyrax-1.0.4 spec/lib/hyrax/arkivo/create_subscription_job_spec.rb
hyrax-1.0.3 spec/lib/hyrax/arkivo/create_subscription_job_spec.rb
hyrax-1.0.2 spec/lib/hyrax/arkivo/create_subscription_job_spec.rb
hyrax-1.0.1 spec/lib/hyrax/arkivo/create_subscription_job_spec.rb
hyrax-1.0.0.rc2 spec/lib/hyrax/arkivo/create_subscription_job_spec.rb
hyrax-1.0.0.rc1 spec/lib/hyrax/arkivo/create_subscription_job_spec.rb
test_hyrax-0.0.1.alpha spec/lib/hyrax/arkivo/create_subscription_job_spec.rb