diff options
| author | Zack Hobson | 2013-12-22 23:28:00 -0800 | 
|---|---|---|
| committer | Zack Hobson | 2013-12-22 23:28:00 -0800 | 
| commit | 11310cefb8206487337b8040f9ceb70e570a06f7 (patch) | |
| tree | f9b3624e4210616e48108ff650fa229c125d894d /test | |
| parent | d315a241dbd6c959085b26a413fc5e40683d63f0 (diff) | |
| parent | b8d0ef7022541999c2267fc7937f2a60e0da602c (diff) | |
| download | hcl-11310cefb8206487337b8040f9ceb70e570a06f7.tar.bz2 | |
Merge pull request #46 from zenhob/faraday
Switch to a Faraday-based JSON API client for Harvest.
Diffstat (limited to 'test')
| -rw-r--r-- | test/app_test.rb | 6 | ||||
| -rw-r--r-- | test/day_entry_test.rb | 38 | ||||
| -rw-r--r-- | test/net_test.rb (renamed from test/timesheet_resource_test.rb) | 27 | ||||
| -rw-r--r-- | test/task_test.rb | 63 | 
4 files changed, 32 insertions, 102 deletions
| diff --git a/test/app_test.rb b/test/app_test.rb index 68e3782..1fc1073 100644 --- a/test/app_test.rb +++ b/test/app_test.rb @@ -23,7 +23,7 @@ class AppTest < HCl::TestCase      app = HCl::App.new      throttled = states('throttled').starts_as(false)      app.expects(:show). -      raises(HCl::TimesheetResource::ThrottleFailure, stub(headers:{'Retry-After' => 42})). +      raises(HCl::HarvestMiddleware::ThrottleFailure, {response_headers:{'retry-after' => 42}}).        then(throttled.is(true))      app.expects(:sleep).with(47).when(throttled.is(true))      app.expects(:show).when(throttled.is(true)) @@ -48,7 +48,7 @@ class AppTest < HCl::TestCase    def test_configure_on_auth_failure      app = HCl::App.new      configured = states('configured').starts_as(false) -    app.expects(:show).raises(HCl::TimesheetResource::AuthFailure).when(configured.is(false)) +    app.expects(:show).raises(HCl::HarvestMiddleware::AuthFailure).when(configured.is(false))      app.expects(:ask).returns('xxx').times(4).when(configured.is(false))      app.expects(:write_config).then(configured.is(true))      app.expects(:show).when(configured.is(true)) @@ -58,7 +58,7 @@ class AppTest < HCl::TestCase    def test_api_failure      app = HCl::App.new -    app.expects(:show).raises(HCl::TimesheetResource::Failure) +    app.expects(:show).raises(HCl::HarvestMiddleware::Failure)      app.expects(:exit).with(1)      app.process_args('show').run      assert_match /API failure/i, error_output diff --git a/test/day_entry_test.rb b/test/day_entry_test.rb index 581b22b..3e8be24 100644 --- a/test/day_entry_test.rb +++ b/test/day_entry_test.rb @@ -9,7 +9,7 @@ class DayEntryTest < HCl::TestCase    def test_cancel_failure      entry = HCl::DayEntry.new(id:123) -    HCl::DayEntry.expects(:delete).raises(HCl::TimesheetResource::Failure) +    HCl::DayEntry.expects(:delete).raises(HCl::HarvestMiddleware::Failure)      assert !entry.cancel    end @@ -19,48 +19,16 @@ class DayEntryTest < HCl::TestCase      assert_equal "Taco Town - Pizza Taco - Preparation (1:12)", entry.to_s    end -  def test_from_xml -    entries = HCl::DayEntry.from_xml(<<-EOD) -<daily> -  <for_day type="date">Wed, 18 Oct 2006</for_day> -  <day_entries> -    <day_entry> -      <id type="integer">195168</id> -      <client>Iridesco</client> -      <project>Harvest</project> -      <task>Backend Programming</task> -      <hours type="float">2.06</hours> -      <notes>Test api support</notes> -      <timer_started_at type="datetime"> -        Wed, 18 Oct 2006 09:53:06 -0000 -      </timer_started_at> -      <created_at type="datetime">Wed, 18 Oct 2006 09:53:06 -0000</created_at> -    </day_entry> -  </day_entries> -</daily> -    EOD -    assert_equal 1, entries.size -    { -      :project => 'Harvest', -      :client => 'Iridesco', -      :task => 'Backend Programming', -      :notes => 'Test api support', -      :hours => '2.06', -    }.each do |method, value| -      assert_equal value, entries.first.send(method) -    end -  end -    def test_append_note      entry = HCl::DayEntry.new(:id => '1', :notes => 'yourmom.', :hours => '1.0') -    HCl::DayEntry.stubs(:post) +    HCl::Net.stubs(:post)      entry.append_note('hi world')      assert_equal "yourmom.\nhi world", entry.notes    end    def test_append_note_to_empty      entry = HCl::DayEntry.new(:id => '1', :notes => nil, :hours => '1.0') -    HCl::DayEntry.stubs(:post) +    HCl::Net.stubs(:post)      entry.append_note('hi world')      assert_equal 'hi world', entry.notes    end diff --git a/test/timesheet_resource_test.rb b/test/net_test.rb index 4153429..c4e39e1 100644 --- a/test/timesheet_resource_test.rb +++ b/test/net_test.rb @@ -1,10 +1,10 @@  require 'test_helper' -class TimesheetResourceTest < HCl::TestCase +class NetTest < HCl::TestCase    def setup      FakeWeb.allow_net_connect = false -    HCl::TimesheetResource.configure \ +    HCl::Net.configure \        'login' => 'bob',        'password' => 'secret',        'subdomain' => 'bobclock', @@ -12,27 +12,30 @@ class TimesheetResourceTest < HCl::TestCase    end    def test_configure -    assert_equal 'bob', HCl::TimesheetResource.login -    assert_equal 'secret', HCl::TimesheetResource.password -    assert_equal 'bobclock', HCl::TimesheetResource.subdomain -    assert_equal true, HCl::TimesheetResource.ssl +    assert_equal 'bob', HCl::Net.login +    assert_equal 'secret', HCl::Net.password +    assert_equal 'bobclock', HCl::Net.subdomain +    assert_equal true, HCl::Net.ssl    end    def test_http_get -    FakeWeb.register_uri(:get, "https://bob:secret@bobclock.harvestapp.com/foo", :body => 'gotten!') -    body = HCl::TimesheetResource.get 'foo' +    FakeWeb.register_uri(:get, "https://bob:secret@bobclock.harvestapp.com/foo", +                         :body => 'gotten!'.inspect) +    body = HCl::Net.get 'foo'      assert_equal 'gotten!', body    end    def test_http_post -    FakeWeb.register_uri(:post, "https://bob:secret@bobclock.harvestapp.com/foo", :body => 'posted!') -    body = HCl::TimesheetResource.post 'foo', {pizza:'taco'} +    FakeWeb.register_uri(:post, "https://bob:secret@bobclock.harvestapp.com/foo", +                         :body => 'posted!'.inspect) +    body = HCl::Net.post 'foo', {pizza:'taco'}      assert_equal 'posted!', body    end    def test_http_delete -    FakeWeb.register_uri(:delete, "https://bob:secret@bobclock.harvestapp.com/foo", :body => 'wiped!') -    body = HCl::TimesheetResource.delete 'foo' +    FakeWeb.register_uri(:delete, "https://bob:secret@bobclock.harvestapp.com/foo", +                         :body => 'wiped!'.inspect) +    body = HCl::Net.delete 'foo'      assert_equal 'wiped!', body    end  end diff --git a/test/task_test.rb b/test/task_test.rb index f5c30b8..bbdce89 100644 --- a/test/task_test.rb +++ b/test/task_test.rb @@ -1,61 +1,20 @@  class TaskTest < HCl::TestCase -  DAILY_ENTRY = %{<daily> -    <for_day type="date">Wed, 18 Oct 2006</for_day> -    <day_entries> -      <day_entry> -        <id type="integer">195168</id> -        <client>Iridesco</client> -        <project>Harvest</project> -        <task>Backend Programming</task> -        <hours type="float">2.06</hours> -        <notes>Test api support</notes> -        <timer_started_at type="datetime"> -          Wed, 18 Oct 2006 09:53:06 -0000 -        </timer_started_at> -        <created_at type="datetime">Wed, 18 Oct 2006 09:53:06 -0000</created_at> -      </day_entry> -    </day_entries> -  </daily>} - -  def test_add_task -    task = HCl::Task.new(id:456, project:HCl::Project.new(id:123)) -    Date.expects(:today).returns('now') -    HCl::Task.expects(:post).with('daily/add', <<-EOT).returns(DAILY_ENTRY) -      <request> -        <notes>hi world</notes> -        <hours>0.5</hours> -        <project_id type="integer">123</project_id> -        <task_id type="integer">456</task_id> -        <spent_at type="date">now</spent_at> -      </request> -      EOT -    task.add note:'hi world', starting_time:0.5 -  end    def test_cache_file      assert_equal "#{HCl::App::HCL_DIR}/cache/tasks.yml", HCl::Task.cache_file    end -  def test_cache_tasks -    HCl::Task.cache_tasks(REXML::Document.new(<<-EOD)) -<daily> -  <projects> -    <project> -      <name>Click and Type</name> -      <code></code> -      <id type="integer">3</id> -      <client>AFS</client> -      <tasks> -        <task> -          <name>Security support</name> -          <id type="integer">14</id> -          <billable type="boolean">true</billable> -        </task> -      </tasks> -    </project> -  </projects> -</daily> -    EOD +  def test_cache_tasks_hash +    HCl::Task.cache_tasks_hash({ projects: [{ +      name: "Click and Type", +      id: 3, +      client: "AFS", +      tasks: [{ +        name: "Security support", +        id: 14, +        billable: true +      }] +    }]})      assert_equal 1, HCl::Task.all.size      assert_equal 'Security support', HCl::Task.all.first.name    end | 
