Given(/^I update the first statement period to the current_statement_period_id$/) do
  response_get_statement_periods = Support::Services::OwsRoyalties.retrieve_recent_statement_periods
  current_period = JSON.parse(response_get_statement_periods.body)
                       .find { |period| period["statement_period_status"] == "current" }
  @current_statement_period_id = current_period["statement_period_id"].to_s

  @accounting_user ||= @users.accounting_user
  vendor_id = @accounting_user.info[:id]
  Support::Helpers::Queries.update_first_statement_period(vendor_id, @current_statement_period_id)
end

Then(/^I should see the starting form period to be current_statement_period_id$/) do
  on(Accounting::StatementsPage) do |page|
    expect(page.first_statement_period).to eq(@current_statement_period_id)
  end
end

Given(/^I update the first statement period to "([^"]*)"$/) do |period_id|
  @accounting_user ||= @users.accounting_user
  vendor_id = @accounting_user.info[:id]
  Support::Helpers::Queries.update_first_statement_period(vendor_id, period_id)
end

Then(/^I should see the starting form period to be "([^"]*)"$/) do |period_id|
  on(Accounting::StatementsPage) do |page|
    expect(page.first_statement_period).to eq(period_id)
  end
end

Then(/^I should see the starting form period to be "([^"]*)" in dropdown filter$/) do |period_id|
  on(Workstation::AccountingBreakdownPage) do |page|
    expect(page.first_period_dropdown_values.last[:period_id]).to eq(period_id)
  end
end
