dropbox_file_url_agent_spec.rb 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. require 'spec_helper'
  2. describe Agents::DropboxFileUrlAgent do
  3. before(:each) do
  4. @agent = Agents::DropboxFileUrlAgent.new(
  5. name: 'dropbox file to url',
  6. options: {}
  7. )
  8. @agent.user = users(:bob)
  9. @agent.service = services(:generic)
  10. @agent.save!
  11. end
  12. it 'cannot be scheduled' do
  13. expect(@agent.cannot_be_scheduled?).to eq true
  14. end
  15. it 'has agent description' do
  16. expect(@agent.description).to_not be_nil
  17. end
  18. it 'has event description' do
  19. expect(@agent.event_description).to_not be_nil
  20. end
  21. describe "#receive" do
  22. let(:first_dropbox_url_payload) { { 'url' => 'http://dropbox.com/first/path/url' } }
  23. let(:second_dropbox_url_payload) { { 'url' => 'http://dropbox.com/second/path/url' } }
  24. let(:third_dropbox_url_payload) { { 'url' => 'http://dropbox.com/third/path/url' } }
  25. def create_event(payload)
  26. event = Event.new(payload: payload)
  27. event.agent = agents(:bob_manual_event_agent)
  28. event.save!
  29. event
  30. end
  31. before(:each) do
  32. stub.proxy(Dropbox::API::Client).new do |api|
  33. stub(api).find('/first/path') { stub(Dropbox::API::File.new).direct_url { first_dropbox_url_payload } }
  34. stub(api).find('/second/path') { stub(Dropbox::API::File.new).direct_url { second_dropbox_url_payload } }
  35. stub(api).find('/third/path') { stub(Dropbox::API::File.new).direct_url { third_dropbox_url_payload } }
  36. end
  37. end
  38. context 'with a single path' do
  39. before(:each) { @event = create_event(paths: '/first/path') }
  40. it 'creates one event with the temporary dropbox link' do
  41. expect { @agent.receive([@event]) }.to change(Event, :count).by(1)
  42. expect(Event.last.payload).to eq(first_dropbox_url_payload)
  43. end
  44. end
  45. context 'with multiple comma-separated paths' do
  46. before(:each) { @event = create_event(paths: '/first/path, /second/path, /third/path') }
  47. it 'creates one event with the temporary dropbox link for each path' do
  48. expect { @agent.receive([@event]) }.to change(Event, :count).by(3)
  49. last_events = Event.last(3)
  50. expect(last_events[0].payload).to eq(first_dropbox_url_payload)
  51. expect(last_events[1].payload).to eq(second_dropbox_url_payload)
  52. expect(last_events[2].payload).to eq(third_dropbox_url_payload)
  53. end
  54. end
  55. end
  56. end