summaryrefslogtreecommitdiffstats
path: root/test/command_test.rb
blob: 0b3b5c1532c12b75b065c63ef273461ff77e99eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require 'test_helper'
class CommandTest < Test::Unit::TestCase
  include HCl::Commands
  include HCl::Utility

  def setup
    @settings = {}
  end

  # the current_time utility method needs to be deterministic
  def current_time
    'high noon'
  end

  # stub settings helpers
  def write_settings; end
  def read_settings
    @settings
  end

  def test_tasks
    HCl::Task.expects(:all).returns([HCl::Task.new(
      id:123,
      name: 'Dev',
      project: HCl::Project.new(id:456, name:'App', client:'Bob', code:'b')
    )])
    result = tasks
    assert_equal "456 123\tBob - [b] App - Dev", result
  end

  def test_show
    HCl::DayEntry.expects(:all).returns([HCl::DayEntry.new({
      hours:'2.06',
      notes: 'hi world',
      project: 'App'
    })])
    result = show
    assert_equal \
      "\t2:03\tApp: hi world\n\t-------------\n\t2:03\ttotal (as of high noon)\n",
      result
  end

  def test_aliases
    HCl::Task.expects(:all).returns([HCl::Task.new(
      id:123,
      name: 'Dev',
      project: HCl::Project.new(id:456, name:'App', client:'Bob', code:'b')
    )])
    result = send :alias, *%w[ hcl 456 123 ]
    assert_equal '456 123', @settings['task.hcl']

    result = aliases
    assert_equal ["@hcl"], result

    result = unalias 'hcl'
    assert !@settings.key?('task.hcl'), 'hcl alias is no longer defined'
  end

  def test_start
    task = HCl::Task.new(
      id:123,
      name: 'Dev',
      project: HCl::Project.new(id:456, name:'App', client:'Bob', code:'b')
    )
    HCl::Task.expects(:find).with('456','123').returns(task)
    task.expects(:start).with(starting_time:nil, note:'do stuff')
    start *%w[ 456 123 do stuff ]
  end

end