# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Dor::Workflow::Response::Workflow do
subject(:instance) { described_class.new(xml: xml) }
describe '#pid' do
subject { instance.pid }
let(:xml) do
<<~XML
XML
end
it { is_expected.to eq 'druid:mw971zk1113' }
end
describe '#workflow_name' do
subject { instance.workflow_name }
let(:xml) do
<<~XML
XML
end
it { is_expected.to eq 'assemblyWF' }
end
describe '#active?' do
subject { instance.active_for?(version: 2) }
context 'when the workflow has not been instantiated for the given version' do
let(:xml) do
<<~XML
XML
end
it { is_expected.to be false }
end
context 'when the workflow has been instantiated for the given version' do
let(:xml) do
<<~XML
XML
end
it { is_expected.to be true }
end
end
describe '#empty?' do
subject { instance.empty? }
context 'when there is xml' do
let(:xml) do
'
'
end
it { is_expected.to be false }
end
context 'when the xml is empty' do
let(:xml) { '' }
it { is_expected.to be true }
end
end
describe '#process_for_recent_version' do
subject(:process) { instance.process_for_recent_version(name: 'jp2-create') }
context 'when the workflow has not been instantiated for the given version' do
let(:xml) do
<<~XML
XML
end
it 'returns a process' do
expect(process).to be_kind_of Dor::Workflow::Response::Process
expect(process.status).to eq 'completed'
expect(process.name).to eq 'jp2-create'
end
end
context 'when the workflow has been instantiated for the given version' do
let(:xml) do
<<~XML
XML
end
it 'returns a process' do
expect(process).to be_kind_of Dor::Workflow::Response::Process
expect(process.status).to eq 'error'
expect(process.error_message).to eq 'it just broke'
expect(process.name).to eq 'jp2-create'
end
end
end
end