require 'sfba_transit/dashboard_manager'

module SfbaTransit
  describe DashboardManager do
    SESSION_ID = '!2cudABGzh9tqWp/nr85wKjrI+8zQDqcJqWKc5rdvcx21dLj1FA=='.freeze
    EMAIL = 'redacted@example.com'.freeze # Email in the dashboard.jsf test data file.
    subject(:dashboard_manager) { DashboardManager.new(SESSION_ID, base_url: 'https://localhost') }
    before(:each) do
      stub_request(:get, 'https://localhost/ClipperCard/dashboard.jsf')
        .to_return(body: File.read(data_file_path('dashboard.jsf')),
                   status: 200)
    end
    it 'stores session id' do
      expect(dashboard_manager.session_id).to eq SESSION_ID
    end

    it 'loads dashboard and retrieves email' do
      dashboard_manager.load_dashboard!
      expect(dashboard_manager.email).to eq EMAIL
    end

    it 'throws error if dashboard not loaded in' do
      expect { dashboard_manager.email }.to raise_error(RuntimeError)
    end
  end
end
