|
@@ -5,8 +5,21 @@ describe Agents::BasecampAgent do
|
|
|
it_behaves_like Oauthable
|
|
|
|
|
|
before(:each) do
|
|
|
- stub_request(:get, /json$/).to_return(:body => File.read(Rails.root.join("spec/data_fixtures/basecamp.json")), :status => 200, :headers => {"Content-Type" => "text/json"})
|
|
|
- stub_request(:get, /02:00$/).to_return(:body => File.read(Rails.root.join("spec/data_fixtures/basecamp.json")), :status => 200, :headers => {"Content-Type" => "text/json"})
|
|
|
+ stub_request(:get, /events.json$/).to_return(
|
|
|
+ :body => File.read(Rails.root.join("spec/data_fixtures/basecamp.json")),
|
|
|
+ :status => 200,
|
|
|
+ :headers => {"Content-Type" => "text/json"}
|
|
|
+ )
|
|
|
+ stub_request(:get, /projects.json$/).to_return(
|
|
|
+ :body => JSON.dump([{name: 'test', id: 1234},{name: 'test1', id: 1235}]),
|
|
|
+ :status => 200,
|
|
|
+ :headers => {"Content-Type" => "text/json"}
|
|
|
+ )
|
|
|
+ stub_request(:get, /02:00$/).to_return(
|
|
|
+ :body => File.read(Rails.root.join("spec/data_fixtures/basecamp.json")),
|
|
|
+ :status => 200,
|
|
|
+ :headers => {"Content-Type" => "text/json"}
|
|
|
+ )
|
|
|
@valid_params = { :project_id => 6789 }
|
|
|
|
|
|
@checker = Agents::BasecampAgent.new(:name => "somename", :options => @valid_params)
|
|
@@ -32,10 +45,13 @@ describe Agents::BasecampAgent do
|
|
|
expect(@checker.send(:request_options)).to eq({:headers => {"User-Agent" => "Huginn (https://github.com/cantino/huginn)", "Authorization" => 'Bearer "1234token"'}})
|
|
|
end
|
|
|
|
|
|
- it "should generate the currect request url" do
|
|
|
- expect(@checker.send(:request_url)).to eq("https://basecamp.com/12345/api/v1/projects/6789/events.json")
|
|
|
+ it "should generate the correct events url" do
|
|
|
+ expect(@checker.send(:events_url)).to eq("https://basecamp.com/12345/api/v1/projects/6789/events.json")
|
|
|
end
|
|
|
|
|
|
+ it "should generate the correct projects url" do
|
|
|
+ expect(@checker.send(:projects_url)).to eq("https://basecamp.com/12345/api/v1/projects.json")
|
|
|
+ end
|
|
|
|
|
|
it "should not provide the since attribute on first run" do
|
|
|
expect(@checker.send(:query_parameters)).to eq({})
|
|
@@ -48,6 +64,13 @@ describe Agents::BasecampAgent do
|
|
|
expect(@checker.reload.send(:query_parameters)).to eq({:query => {:since => time}})
|
|
|
end
|
|
|
end
|
|
|
+
|
|
|
+ describe "#complete_project_id" do
|
|
|
+ it "should return a array of hashes" do
|
|
|
+ expect(@checker.complete_project_id).to eq [{name: 'test (1234)', value: 1234}, {name: 'test1 (1235)', value: 1235}]
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
describe "#check" do
|
|
|
it "should not emit events on its first run" do
|
|
|
expect { @checker.check }.to change { Event.count }.by(0)
|
|
@@ -60,7 +83,7 @@ describe Agents::BasecampAgent do
|
|
|
end
|
|
|
|
|
|
describe "#working?" do
|
|
|
- it "it is working when at least one event was emited" do
|
|
|
+ it "it is working when at least one event was emitted" do
|
|
|
expect(@checker).not_to be_working
|
|
|
@checker.memory[:last_event] = '2014-04-17T10:25:31.000+02:00'
|
|
|
@checker.check
|