Sha256: ae9d5ff493056a36e6313e0899c5664510b4dc8b2d0aac634310052400b70b2c

Contents?: true

Size: 1.9 KB

Versions: 8

Compression:

Stored size: 1.9 KB

Contents

require 'spec_helper'

describe Sufia::Arkivo::CreateSubscriptionJob do
  let(:user) { FactoryGirl.find_or_create(:archivist) }

  subject { described_class.new(user.user_key) }

  context 'with a bogus user' do
    before { allow(User).to receive(:find_by_user_key) { nil } }
    it 'raises because user not found' do
      expect { subject.run }.to raise_error(Sufia::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 { subject.run }.to raise_error(Sufia::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 { subject.run }.to raise_error(Sufia::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 { subject.run }.to raise_error(Sufia::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(subject).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
      subject.run
      expect(user.reload.arkivo_subscription).to eq subscription_uri
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sufia-6.7.0 spec/lib/sufia/arkivo/create_subscription_job_spec.rb
sufia-6.6.1 spec/lib/sufia/arkivo/create_subscription_job_spec.rb
sufia-6.6.0 spec/lib/sufia/arkivo/create_subscription_job_spec.rb
sufia-6.5.0 spec/lib/sufia/arkivo/create_subscription_job_spec.rb
sufia-6.4.0 spec/lib/sufia/arkivo/create_subscription_job_spec.rb
sufia-6.3.0 spec/lib/sufia/arkivo/create_subscription_job_spec.rb
sufia-6.2.0 spec/lib/sufia/arkivo/create_subscription_job_spec.rb
sufia-6.1.0 spec/lib/sufia/arkivo/create_subscription_job_spec.rb