require 'rails_helper'

describe WorkflowInstance do
  describe ".sorted_state_count" do
    it "returns the counts sorted in the required way" do
      create(:workflow_instance_scenario1).owner_initialization.reject!
      create(:workflow_instance_scenario1, :unplanned)
      create(:workflow_instance_scenario1).owner_initialization.is_overdue!
      create(:workflow_instance_scenario1, :unplanned)
      create(:workflow_instance_scenario1).owner_initialization.complete!
      create(:workflow_instance_scenario1).owner_initialization.process!

      create(:workflow_instance_scenario2, :unplanned)

      result = OwnerInitialization::Scenario1.sorted_state_count
      result.to_a.should eq [
        ["pending", 2], ["overdue", 1], ["processing", 1], ["rejected", 1], ["completed", 1]
      ]
    end
  end
end
