Skip to content

Commit

Permalink
Added tests for source and destination factories.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesiarmes committed Jun 6, 2024
1 parent 060425c commit 8f291c9
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions spec/support/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@

require_relative 'factories/config/destination_factory'
require_relative 'factories/config/source_factory'
require_relative 'factories/destination/one_drive_factory'
require_relative 'factories/service/one_drive_factory'
require_relative 'factories/source/url_factory'
13 changes: 13 additions & 0 deletions spec/support/factories/destination/one_drive_factory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require_relative '../../../../lib/destination/one_drive'

FactoryBot.define do
factory :destination_one_drive, class: DocumentTransfer::Destination::OneDrive do
transient do
config { build(:config_destination, type: :onedrive, path: 'rspec-docs') }
end

initialize_with { new(config) }
end
end
32 changes: 32 additions & 0 deletions spec/unit/document_transfer/destination_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

require_relative '../../../lib/destination'

RSpec.describe DocumentTransfer::Destination do
describe '.load' do
let(:config) { build(:config_destination, type: destination_type) }
let(:destination) { build(:destination_one_drive) }
let(:destination_type) { :onedrive }

before do
allow(destination.class).to receive(:new).and_return(destination)
end

it 'returns the proper destination' do
expect(described_class.load(config)).to eq(destination)
end

context 'when an invalid destination type is provided' do
before do
# If we try to set an invalid type directly on the config object, it
# will raise an error.
allow(config).to receive(:type).and_return(:invalid)
end

it 'raises an exception' do
expect { described_class.load(config) }.to \
raise_error(DocumentTransfer::Destination::InvalidDestinationError)
end
end
end
end
32 changes: 32 additions & 0 deletions spec/unit/document_transfer/source_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

require_relative '../../../lib/source'

RSpec.describe DocumentTransfer::Source do
describe '.load' do
let(:config) { build(:config_source, type: source_type) }
let(:source) { build(:source_url) }
let(:source_type) { :url }

before do
allow(source.class).to receive(:new).and_return(source)
end

it 'returns the proper source' do
expect(described_class.load(config)).to eq(source)
end

context 'when an invalid source type is provided' do
before do
# If we try to set an invalid type directly on the config object, it
# will raise an error.
allow(config).to receive(:type).and_return(:invalid)
end

it 'raises an exception' do
expect { described_class.load(config) }.to \
raise_error(DocumentTransfer::Source::InvalidSourceError)
end
end
end
end

0 comments on commit 8f291c9

Please sign in to comment.