# 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 '#complete?' do
subject { instance.complete? }
context 'when all steps are complete' do
let(:xml) do
<<~XML
XML
end
it { is_expected.to be true }
end
context 'when some steps are not complete' do
let(:xml) do
<<~XML
XML
end
it { is_expected.to be false }
end
end
describe '#complete_for?' do
let(:xml) do
<<~XML
XML
end
context 'when all steps are complete' do
it 'returns true' do
expect(instance.complete_for?(version: 2)).to be true
end
end
context 'when some steps are not complete' do
it 'returns false' do
expect(instance.complete_for?(version: 1)).to be false
end
end
end
describe '#active_for?' 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
describe '#incomplete_processes' do
subject(:processes) { instance.incomplete_processes }
context 'when all steps are complete' do
let(:xml) do
<<~XML
XML
end
it { is_expected.to be_empty }
end
context 'when some steps are not complete' do
let(:xml) do
<<~XML
XML
end
it 'returns the incomplete processes' do
expect(processes.size).to eq 1
expect(processes.first.name).to eq 'jp2-create'
end
end
end
describe '#incomplete_processes_for' do
let(:xml) do
<<~XML
XML
end
context 'when all steps are complete' do
it 'returns empty' do
expect(instance.incomplete_processes_for(version: 2)).to be_empty
end
end
context 'when some steps are not complete' do
it 'returns false' do
expect(instance.incomplete_processes_for(version: 1).size).to eq 1
end
end
end
end