# frozen_string_literal: true require 'spec_helper' RSpec.describe Dor::Workflow::Client::Status do subject(:instance) do described_class.new(druid: druid, version: version, lifecycle_routes: lifecycle_routes) end let(:druid) { 'druid:ab123cd4567' } let(:version) { '2' } let(:lifecycle_routes) { Dor::Workflow::Client::LifecycleRoutes.new(requestor: requestor) } let(:requestor) { instance_double(Dor::Workflow::Client::Requestor, request: xml) } describe '#display' do subject(:status) { instance.display } context 'for gv054hp4128' do context 'when current version is published, but does not have a version attribute' do let(:xml) do ' described opened submitted described published published ' end let(:version) { '4' } it 'generates a status string' do expect(status).to eq('v4 In accessioning (described, published)') end end context 'when current version matches the attribute in the milestone' do let(:xml) do ' described published ' end let(:version) { '3' } it 'generates a status string' do expect(status).to eq('v3 In accessioning (described, published)') end end end context 'for bd504dj1946' do let(:xml) do ' registered digitized submitted described published deposited accessioned opened submitted described published deposited accessioned ' end it 'handles a v2 accessioned object' do expect(status).to eq('v2 Accessioned') end context 'when there are no lifecycles for the current version, indicating malfunction in workflow' do let(:version) { '3' } it 'gives a status of unknown' do expect(status).to eq('v3 Unknown Status') end end context 'when time is requested' do subject(:status) { instance.display(include_time: true) } it 'includes a formatted date/time if one is requested' do expect(status).to eq('v2 Accessioned 2013-10-01 07:11PM') end end end context 'for an accessioned step with the exact same timestamp as the deposited step' do let(:xml) do ' registered digitized submitted described published deposited accessioned opened submitted described published deposited accessioned ' end subject(:status) { instance.display(include_time: true) } it 'has the correct status of accessioned (v2) object' do expect(status).to eq('v2 Accessioned 2013-10-01 07:10PM') end end context 'for an accessioned step with an ealier timestamp than the deposited step' do let(:xml) do ' registered digitized submitted described published deposited accessioned opened submitted described published deposited accessioned ' end subject(:status) { instance.display(include_time: true) } it 'has the correct status of accessioned (v2) object' do expect(status).to eq('v2 Accessioned 2013-09-01 07:10PM') end end context 'for a deposited step for a non-accessioned object' do let(:xml) do ' registered digitized submitted described published deposited accessioned opened submitted described published deposited ' end subject(:status) { instance.display(include_time: true) } it 'has the correct status of deposited (v2) object' do expect(status).to eq('v2 In accessioning (described, published, deposited) 2013-10-01 07:10PM') end end end describe '#display_simplified' do subject(:status) { instance.display_simplified } let(:xml) do ' described opened submitted described published published ' end it 'generates a status string' do expect(status).to eq('In accessioning') end end end