tacokit 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +86 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +16 -25
  5. data/Guardfile +1 -1
  6. data/README.md +61 -17
  7. data/Rakefile +10 -5
  8. data/lib/tacokit/authorization.rb +14 -13
  9. data/lib/tacokit/client/actions.rb +68 -28
  10. data/lib/tacokit/client/boards.rb +92 -85
  11. data/lib/tacokit/client/cards.rb +285 -92
  12. data/lib/tacokit/client/checklists.rb +48 -28
  13. data/lib/tacokit/client/labels.rb +14 -16
  14. data/lib/tacokit/client/lists.rb +52 -28
  15. data/lib/tacokit/client/members.rb +56 -46
  16. data/lib/tacokit/client/notifications.rb +13 -27
  17. data/lib/tacokit/client/organizations.rb +0 -6
  18. data/lib/tacokit/client/searches.rb +0 -1
  19. data/lib/tacokit/client/tokens.rb +0 -6
  20. data/lib/tacokit/client/types.rb +0 -1
  21. data/lib/tacokit/client/webhooks.rb +3 -8
  22. data/lib/tacokit/client.rb +48 -75
  23. data/lib/tacokit/collection.rb +49 -0
  24. data/lib/tacokit/configuration.rb +4 -6
  25. data/lib/tacokit/error.rb +0 -2
  26. data/lib/tacokit/middleware/boom.rb +6 -7
  27. data/lib/tacokit/middleware.rb +2 -10
  28. data/lib/tacokit/resource.rb +84 -57
  29. data/lib/tacokit/response.rb +3 -3
  30. data/lib/tacokit/transform.rb +35 -13
  31. data/lib/tacokit/utils.rb +40 -8
  32. data/lib/tacokit/version.rb +1 -1
  33. data/lib/tacokit.rb +0 -2
  34. data/spec/cassettes/Tacokit_Client_Actions/_action_board/returns_action_board.json +1 -0
  35. data/spec/cassettes/Tacokit_Client_Actions/_action_card/returns_action_card.json +1 -0
  36. data/spec/cassettes/Tacokit_Client_Actions/_action_entities/returns_action_entities.json +1 -0
  37. data/spec/cassettes/Tacokit_Client_Actions/_action_list/returns_action_list.json +1 -0
  38. data/spec/cassettes/Tacokit_Client_Boards/_add_board_member/adds_invites_member_to_board.json +1 -1
  39. data/spec/cassettes/Tacokit_Client_Boards/_board_actions/returns_board_actions.json +1 -0
  40. data/spec/cassettes/Tacokit_Client_Boards/_board_cards/returns_board_cards.json +1 -0
  41. data/spec/cassettes/Tacokit_Client_Boards/_board_checklists/returns_board_checklists.json +1 -0
  42. data/spec/cassettes/Tacokit_Client_Boards/_board_labels/returns_board_labels.json +1 -0
  43. data/spec/cassettes/Tacokit_Client_Boards/_board_lists/returns_board_lists.json +1 -0
  44. data/spec/cassettes/Tacokit_Client_Boards/_board_members/returns_board_members.json +1 -0
  45. data/spec/cassettes/Tacokit_Client_Boards/_board_organization/returns_board_organization.json +1 -0
  46. data/spec/cassettes/Tacokit_Client_Boards/_board_preferences/returns_preferences_for_a_board.json +1 -0
  47. data/spec/cassettes/Tacokit_Client_Boards/_board_stars/returns_board_stars.json +1 -0
  48. data/spec/cassettes/Tacokit_Client_Boards/_member_board_stars/returns_board_stars.json +1 -0
  49. data/spec/cassettes/Tacokit_Client_Boards/_update_board_member/updates_member.json +1 -0
  50. data/spec/cassettes/Tacokit_Client_Cards/_add_comment/creates_a_comment.json +1 -0
  51. data/spec/cassettes/Tacokit_Client_Cards/_add_label/adds_label_to_card.json +1 -0
  52. data/spec/cassettes/Tacokit_Client_Cards/_add_member_to_card/adds_member_to_card.json +1 -0
  53. data/spec/cassettes/Tacokit_Client_Cards/_archive_card/archives_card.json +1 -0
  54. data/spec/cassettes/Tacokit_Client_Cards/_archive_card/restore_card.json +1 -0
  55. data/spec/cassettes/Tacokit_Client_Cards/_attachments/returns_an_attachment.json +1 -0
  56. data/spec/cassettes/Tacokit_Client_Cards/_attachments/returns_attachment.json +1 -0
  57. data/spec/cassettes/Tacokit_Client_Cards/_attachments/returns_attachments.json +1 -0
  58. data/spec/cassettes/Tacokit_Client_Cards/_card/returns_a_card_by_card_resource.json +1 -0
  59. data/spec/cassettes/Tacokit_Client_Cards/_card/returns_a_card_by_id.json +1 -1
  60. data/spec/cassettes/Tacokit_Client_Cards/_card/returns_a_card_by_short_link.json +1 -1
  61. data/spec/cassettes/Tacokit_Client_Cards/_card_actions/returns_card_actions.json +1 -0
  62. data/spec/cassettes/Tacokit_Client_Cards/_card_board/returns_card_board.json +1 -0
  63. data/spec/cassettes/Tacokit_Client_Cards/_card_field/returns_a_hash.json +1 -1
  64. data/spec/cassettes/Tacokit_Client_Cards/_card_field/returns_a_value.json +1 -1
  65. data/spec/cassettes/Tacokit_Client_Cards/_card_field/returns_an_array.json +1 -1
  66. data/spec/cassettes/Tacokit_Client_Cards/_card_list/returns_a_list.json +1 -0
  67. data/spec/cassettes/Tacokit_Client_Cards/_card_members/returns_members.json +1 -0
  68. data/spec/cassettes/Tacokit_Client_Cards/_card_members/returns_members_voted.json +1 -0
  69. data/spec/cassettes/Tacokit_Client_Cards/_card_resource/returns_card_actions.json +1 -1
  70. data/spec/cassettes/Tacokit_Client_Cards/_card_resource/returns_card_board.json +1 -1
  71. data/spec/cassettes/Tacokit_Client_Cards/_card_resource/returns_card_check_item_states.json +1 -1
  72. data/spec/cassettes/Tacokit_Client_Cards/_card_stickers/returns_.json +1 -0
  73. data/spec/cassettes/Tacokit_Client_Cards/_checklists/returns_check_item_states.json +1 -0
  74. data/spec/cassettes/Tacokit_Client_Cards/_checklists/returns_checklists.json +1 -0
  75. data/spec/cassettes/Tacokit_Client_Cards/_create_card/creates_a_card.json +1 -1
  76. data/spec/cassettes/Tacokit_Client_Cards/_create_card_attachment/attaches_external_url.json +1 -1
  77. data/spec/cassettes/Tacokit_Client_Cards/_create_card_attachment/uploads_local_file.json +1 -1
  78. data/spec/cassettes/Tacokit_Client_Cards/_delete_card/deletes_a_card.json +1 -1
  79. data/spec/cassettes/Tacokit_Client_Cards/_delete_card_resource/deletes_resource.json +1 -1
  80. data/spec/cassettes/Tacokit_Client_Cards/_delete_comment/deletes_comment.json +1 -0
  81. data/spec/cassettes/Tacokit_Client_Cards/_list/returns_list.json +1 -0
  82. data/spec/cassettes/Tacokit_Client_Cards/_move_card/moves_card_to_a_new_position.json +1 -0
  83. data/spec/cassettes/Tacokit_Client_Cards/_move_card/moves_card_to_another_board_list.json +1 -0
  84. data/spec/cassettes/Tacokit_Client_Cards/_move_card/moves_card_to_board.json +1 -0
  85. data/spec/cassettes/Tacokit_Client_Cards/_move_card/moves_card_to_list.json +1 -0
  86. data/spec/cassettes/Tacokit_Client_Cards/_move_card/raises_error_if_missing_options.json +1 -0
  87. data/spec/cassettes/Tacokit_Client_Cards/_start_checklist/adds_a_checklist_item.json +1 -0
  88. data/spec/cassettes/Tacokit_Client_Cards/_start_checklist/adds_new_checklist_by_name.json +1 -0
  89. data/spec/cassettes/Tacokit_Client_Cards/_start_checklist/copies_a_checklist_by_id.json +1 -0
  90. data/spec/cassettes/Tacokit_Client_Cards/_stickers/returns_stickers.json +1 -0
  91. data/spec/cassettes/Tacokit_Client_Cards/_update_card/updates_a_card.json +1 -1
  92. data/spec/cassettes/Tacokit_Client_Cards/_update_checklist_item/updates_checklist_item.json +1 -0
  93. data/spec/cassettes/Tacokit_Client_Cards/_update_comment/updates_a_comment.json +1 -0
  94. data/spec/cassettes/Tacokit_Client_Cards/_vote/adds_a_member_s_vote_to_card.json +1 -0
  95. data/spec/cassettes/Tacokit_Client_Checklists/_check_items/adds_a_checklist_check_item.json +1 -0
  96. data/spec/cassettes/Tacokit_Client_Checklists/_check_items/retrieves_checklist_check_items.json +1 -0
  97. data/spec/cassettes/Tacokit_Client_Lists/_archive_list_cards/should_archive_cards_in_list.json +1 -0
  98. data/spec/cassettes/Tacokit_Client_Lists/_list_actions/returns_list_actions.json +1 -0
  99. data/spec/cassettes/Tacokit_Client_Lists/_list_board/returns_list_board.json +1 -0
  100. data/spec/cassettes/Tacokit_Client_Lists/_list_cards/returns_list_cards.json +1 -0
  101. data/spec/cassettes/Tacokit_Client_Lists/_move_list_cards/should_move_cards_in_list.json +1 -0
  102. data/spec/cassettes/Tacokit_Client_Members/_actions/returns_member_actions.json +1 -0
  103. data/spec/cassettes/Tacokit_Client_Members/_board_stars/returns_member_board_stars.json +1 -0
  104. data/spec/cassettes/Tacokit_Client_Members/_boards/returns_member_boards.json +1 -0
  105. data/spec/cassettes/Tacokit_Client_Members/_cards/returns_member_cards.json +1 -0
  106. data/spec/cassettes/Tacokit_Client_Members/_notifications/returns_member_notifications.json +1 -0
  107. data/spec/cassettes/Tacokit_Client_Members/_organizations/returns_member_organizations.json +1 -0
  108. data/spec/cassettes/Tacokit_Client_Members/_tokens/returns_member_organizations.json +1 -0
  109. data/spec/cassettes/Tacokit_Client_Members/_tokens/returns_member_tokens.json +1 -0
  110. data/spec/spec_helper.rb +39 -29
  111. data/spec/tacokit/authorization_spec.rb +11 -11
  112. data/spec/tacokit/client/actions_spec.rb +56 -19
  113. data/spec/tacokit/client/boards_spec.rb +81 -78
  114. data/spec/tacokit/client/cards_spec.rb +322 -68
  115. data/spec/tacokit/client/checklists_spec.rb +29 -27
  116. data/spec/tacokit/client/labels_spec.rb +8 -16
  117. data/spec/tacokit/client/lists_spec.rb +74 -27
  118. data/spec/tacokit/client/members_spec.rb +55 -41
  119. data/spec/tacokit/client/notifications_spec.rb +3 -31
  120. data/spec/tacokit/client/organizations_spec.rb +6 -27
  121. data/spec/tacokit/client/searches_spec.rb +1 -3
  122. data/spec/tacokit/client/tokens_spec.rb +2 -18
  123. data/spec/tacokit/client/types_spec.rb +2 -3
  124. data/spec/tacokit/client/webhooks_spec.rb +6 -14
  125. data/spec/tacokit/client_spec.rb +3 -3
  126. data/spec/tacokit/configuration_spec.rb +30 -31
  127. data/spec/tacokit/middleware/boom_spec.rb +6 -7
  128. data/spec/tacokit/resource_spec.rb +142 -17
  129. data/spec/tacokit/transform_spec.rb +37 -35
  130. data/spec/tacokit_spec.rb +3 -5
  131. data/tacokit.gemspec +6 -6
  132. metadata +132 -15
  133. data/config.ru +0 -7
  134. data/lib/tacokit/middleware/debug.rb +0 -22
  135. data/spec/cassettes/Tacokit_Client_Boards/_update_board_resource/updates_member.json +0 -1
  136. data/spec/cassettes/Tacokit_Client_Members/_member/raises_error_for_missing_token.json +0 -1
@@ -1,104 +1,215 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Tacokit::Client::Cards do
4
4
  def test_card_link
5
- 'k7GHJj7Q'
5
+ "k7GHJj7Q"
6
6
  end
7
7
 
8
8
  def test_card_id
9
- '548dd95c8ca25ac9d0d9ce71'
10
- end
11
-
12
- def test_list_id
13
- '548dd948ffd374221926b4c8'
9
+ "548dd95c8ca25ac9d0d9ce71"
14
10
  end
15
11
 
16
12
  describe "#card", :vcr do
17
13
  it "returns a card by short link" do
18
14
  card = app_client.card(test_card_link)
19
15
 
20
- expect(card.name).to eq 'Card 1'
16
+ expect(card.name).to eq "Card 1"
21
17
  end
22
18
 
23
19
  it "returns a card by id" do
24
20
  card = app_client.card(test_card_id)
25
21
 
26
- expect(card.name).to eq 'Card 1'
22
+ expect(card.name).to eq "Card 1"
23
+ end
24
+
25
+ it "returns a card by card resource" do
26
+ card = app_client.card(test_card_link)
27
+
28
+ card = app_client.card(card)
29
+
30
+ expect(card.name).to eq "Card 1"
31
+ end
32
+ end
33
+
34
+ describe "#card_actions", :vcr do
35
+ it "returns card actions" do
36
+ actions = app_client.card_actions(test_card_link)
37
+
38
+ expect(actions).to be_any
27
39
  end
28
40
  end
29
41
 
30
- describe "#card_field", :vcr do
31
- it "returns a value" do
32
- field = app_client.card_field(test_card_link, :email)
42
+ describe "#card_board", :vcr do
43
+ it "returns card board" do
44
+ board = app_client.card_board(test_card_link)
33
45
 
34
- expect(field['_value']).to be_present
46
+ expect(board.name).to eq("Test Board")
35
47
  end
48
+ end
36
49
 
37
- it "returns an array" do
38
- field = app_client.card_field(test_card_link, :labels)
50
+ describe "#attachments", :vcr do
51
+ before do
52
+ url = "http://cl.ly/image/2p1x3K1X160b/taco.png"
53
+ @attachment = app_client.create_card_attachment(test_card_link, url, "image/png", name: "taco")
54
+ end
39
55
 
40
- expect(field).to be_any
56
+ it "returns attachments" do
57
+ attachments = app_client.attachments(test_card_link)
41
58
 
42
- label = field.first
43
- expect(label.to_attrs).to include(color: "green")
59
+ expect(attachments.first.name).to eq("taco")
44
60
  end
45
61
 
46
- it "returns a hash" do
47
- field = app_client.card_field(test_card_link, :labels)
62
+ it "returns an attachment" do
63
+ attachment = app_client.attachment(test_card_link, @attachment.id)
48
64
 
49
- expect(field.first.to_attrs).to include(color: "green")
65
+ expect(attachment.name).to eq("taco")
66
+ end
67
+
68
+ after do
69
+ app_client.remove_attachment(test_card_link, @attachment.id)
50
70
  end
51
71
  end
52
72
 
53
- describe "#card_resource", :vcr do
54
- it "returns card actions" do
55
- actions = app_client.card_resource(test_card_link, :actions)
73
+ describe "#checklists", :vcr do
74
+ it "returns check_item_states" do
75
+ check_item_state, _ = app_client.check_item_states(test_card_link)
76
+ expect(check_item_state.state).to eq("complete")
77
+ end
56
78
 
57
- expect(actions).to be_any
79
+ it "returns checklists" do
80
+ checklist, _ = app_client.checklists(test_card_link)
81
+
82
+ expect(checklist.name).to eq("Test Checklist 1")
58
83
  end
84
+ end
59
85
 
60
- it "returns card board" do
61
- board = app_client.card_resource(test_card_link, :board)
86
+ describe "#card_list", :vcr do
87
+ it "returns a list" do
88
+ list = app_client.card_list(test_card_link)
89
+
90
+ expect(list.name).to eq("Test List 1")
91
+ end
92
+ end
93
+
94
+ describe "#card_members", :vcr do
95
+ before do
96
+ @member_1 = app_client.member
97
+ @member_2 = app_client.member("rossta")
98
+
99
+ app_client.update_card test_card_link, member_ids: [@member_1.id, @member_2.id]
100
+ end
62
101
 
63
- expect(board.name).to be_present
102
+ it "returns members" do
103
+ members = app_client.card_members(test_card_link)
104
+
105
+ expect(members.size).to eq(2)
106
+ expect(members.first.id).to eq(@member_1.id)
107
+ expect(members.last.id).to eq(@member_2.id)
64
108
  end
65
109
 
66
- it "returns card check item states" do
67
- states = app_client.card_resource(test_card_link, :check_item_states)
110
+ it "returns members voted" do
111
+ members = app_client.card_members_voted(test_card_link)
68
112
 
69
- expect(states).to be_any
113
+ expect(members).to be_empty
114
+ end
70
115
 
71
- state = states.first
72
- expect(state.state).to be_present
116
+ after do
117
+ app_client.update_card test_card_link, member_ids: []
118
+ end
119
+ end
120
+
121
+ describe "#stickers", :vcr do
122
+ before do
123
+ @sticker = app_client.add_sticker(test_card_link, "star")
124
+ end
125
+
126
+ it "returns stickers" do
127
+ stickers = app_client.stickers(test_card_link)
128
+
129
+ expect(stickers.size).to eq(1)
130
+ expect(stickers.first.image).to eq("star")
131
+ end
132
+
133
+ after do
134
+ app_client.remove_sticker(test_card_link, @sticker.id)
73
135
  end
74
136
  end
75
137
 
76
138
  describe "#update_card", :vcr do
139
+ before do
140
+ @member_1 = app_client.member
141
+ @member_2 = app_client.member("rossta")
142
+ end
143
+
77
144
  it "updates a card" do
78
145
  card = app_client.update_card test_card_link,
79
- desc: 'This card is for Tacokit testing',
80
- labels: ['blue', 'green']
146
+ desc: "This card is for Tacokit testing",
147
+ labels: %w[blue green],
148
+ member_ids: [@member_1.id, @member_2.id]
81
149
 
82
- expect(card.desc).to eq 'This card is for Tacokit testing'
150
+ expect(card.desc).to eq "This card is for Tacokit testing"
83
151
  expect(card.labels.size).to eq(2)
152
+ expect(card.member_ids.size).to eq(2)
84
153
  assert_requested :put, trello_url_template("cards/#{test_card_link}{?key,token}")
85
154
  end
155
+
156
+ after do
157
+ app_client.update_card test_card_link, member_ids: []
158
+ end
86
159
  end
87
160
 
88
- describe "#create_card", :vcr do
161
+ describe "#update_comment", :vcr do
162
+ before do
163
+ @comment = app_client.add_comment(test_card_link, "I'm singing, I'm singing, I'm singing!")
164
+ end
165
+
166
+ it "updates a comment" do
167
+ app_client.update_comment(test_card_link, @comment.id, "I'm not singing")
168
+ actions = app_client.card_actions(test_card_link)
169
+
170
+ comment = actions.first.data
171
+ expect(comment.text).to eq("I'm not singing")
172
+ end
173
+
174
+ after do
175
+ app_client.remove_comment test_card_link, @comment.id
176
+ end
177
+ end
178
+
179
+ describe "#update_checklist_item", :vcr do
180
+ before do
181
+ @checklist = app_client.post("cards/#{test_card_link}/checklists", name: "Test Checklist Actions")
182
+ @checkitem = app_client.post("cards/#{test_card_link}/checklist/#{@checklist.id}/checkItem", name: "Working for a living")
183
+ end
184
+
185
+ it "updates checklist item" do
186
+ checkitem = app_client.update_check_item(test_card_link, @checklist.id, @checkitem.id, name: "Going on vacation instead")
187
+
188
+ expect(checkitem.id).to eq(@checkitem.id)
189
+ expect(checkitem.name).to eq("Going on vacation instead")
190
+ end
191
+
192
+ after do
193
+ app_client.delete("cards/#{test_card_link}/checklists/#{@checklist.id}")
194
+ end
195
+ end
196
+
197
+ describe "#archive_card", :vcr do
89
198
  before do
90
199
  @card = app_client.create_card test_list_id, "Autocard", desc: "This is an autogenerated card"
91
200
  end
92
201
 
93
- it "creates a card" do
94
- expect(@card.name).to eq "Autocard"
95
- expect(@card.desc).to eq "This is an autogenerated card"
96
- assert_requested :post, trello_url_template("cards{?key,token}"),
97
- body: {
98
- 'idList' => test_list_id,
99
- 'name' => 'Autocard',
100
- 'desc' => 'This is an autogenerated card'
101
- }
202
+ it "archives card" do
203
+ card = app_client.archive_card(@card.id)
204
+
205
+ expect(card.closed).to be_truthy
206
+ end
207
+
208
+ it "restore card" do
209
+ app_client.archive_card(@card.id)
210
+ card = app_client.restore_card(@card.id)
211
+
212
+ expect(card.closed).to be_falsey
102
213
  end
103
214
 
104
215
  after do
@@ -106,16 +217,89 @@ describe Tacokit::Client::Cards do
106
217
  end
107
218
  end
108
219
 
109
- describe "#delete_card", :vcr do
220
+ describe "#move_card", :vcr do
110
221
  before do
111
- @card = app_client.create_card test_list_id, "Autocard"
222
+ @card = app_client.create_card test_list_id, "Autocard", desc: "This is an autogenerated card"
223
+ @other_board_id = "5496c2a593901c2eb3af5bc6"
224
+ @other_board_list_id = "54b280a866e198c7596baca1"
112
225
  end
113
226
 
114
- it "deletes a card" do
227
+ it "moves card to board" do
228
+ expect(@card.board_id).to eq(test_board_id)
229
+
230
+ card = app_client.move_card(@card.id, board_id: @other_board_id)
231
+ expect(card.board_id).to eq(@other_board_id)
232
+ end
233
+
234
+ it "moves card to list" do
235
+ expect(@card.list_id).to eq(test_list_id)
236
+
237
+ card = app_client.move_card(@card.id, board_id: @other_board_id)
238
+ expect(card.board_id).to eq(@other_board_id)
239
+ end
240
+
241
+ it "moves card to another board list" do
242
+ card = app_client.move_card(@card.id, board_id: @other_board_id, list_id: @other_board_list_id)
243
+
244
+ expect(card.board_id).to eq(@other_board_id)
245
+ expect(card.list_id).to eq(@other_board_list_id)
246
+ end
247
+
248
+ it "moves card to a new position" do
249
+ bottom_pos = app_client.move_card(@card.id, pos: "bottom").pos
250
+
251
+ top_pos = app_client.move_card(@card.id, pos: "top").pos
252
+
253
+ expect(bottom_pos).to be > top_pos
254
+ end
255
+
256
+ it "raises error if missing options" do
257
+ expect { app_client.move_card(@card.id) }.to raise_error(ArgumentError)
258
+ expect { app_client.move_card @card.id, :foo }.to raise_error(ArgumentError)
259
+ expect { app_client.move_card @card.id, foo: :bar }.to raise_error(ArgumentError)
260
+ end
261
+
262
+ after do
115
263
  app_client.delete_card(@card.id)
264
+ end
265
+ end
116
266
 
117
- assert_requested :delete, trello_url_template("cards/#{@card.id}{?key,token}")
118
- expect { app_client.card(@card.id) }.to raise_error(Tacokit::Error::ResourceNotFound)
267
+ describe "#add_member_to_card", :vcr do
268
+ before do
269
+ @member = app_client.member("rossta")
270
+ @card = app_client.card(test_card_link)
271
+ end
272
+
273
+ it "adds member to card" do
274
+ members = app_client.add_member_to_card(test_card_link, @member.id)
275
+
276
+ expect(members.size).to eq(@card.member_ids.size + 1)
277
+ expect(members.map(&:id)).to include(@member.id)
278
+ end
279
+
280
+ after do
281
+ app_client.update_card test_card_link, member_ids: []
282
+ end
283
+ end
284
+
285
+ describe "#create_card", :vcr do
286
+ before do
287
+ @card = app_client.create_card test_list_id, "Autocard", desc: "This is an autogenerated card"
288
+ end
289
+
290
+ it "creates a card" do
291
+ expect(@card.name).to eq "Autocard"
292
+ expect(@card.desc).to eq "This is an autogenerated card"
293
+ assert_requested :post, trello_url_template("cards{?key,token}"),
294
+ body: {
295
+ "idList" => test_list_id,
296
+ "name" => "Autocard",
297
+ "desc" => "This is an autogenerated card"
298
+ }
299
+ end
300
+
301
+ after do
302
+ app_client.delete_card(@card.id)
119
303
  end
120
304
  end
121
305
 
@@ -125,25 +309,25 @@ describe Tacokit::Client::Cards do
125
309
  end
126
310
 
127
311
  it "uploads local file" do
128
- file_path = File.expand_path('../../../fixtures/taco.png', __FILE__)
312
+ file_path = File.expand_path("../../../fixtures/taco.png", __FILE__)
129
313
  expect(File.exist?(file_path)).to be_truthy
130
314
 
131
- attachment = app_client.create_card_attachment(@card.id, file_path, 'image/png', name: 'taco')
315
+ attachment = app_client.create_card_attachment(@card.id, file_path, "image/png", name: "taco")
132
316
 
133
- expect(attachment.name).to eq('taco')
317
+ expect(attachment.name).to eq("taco")
134
318
 
135
319
  # TODO: mime_type for upload is not persisted on Trello
136
- # expect(attachment.mime_type).to eq('image/png')
320
+ # expect(attachment.mime_type).to eq("image/png")
137
321
  end
138
322
 
139
323
  it "attaches external url" do
140
- url = 'http://cl.ly/image/2p1x3K1X160b/taco.png'
141
- attachment = app_client.create_card_attachment(@card.id, url, 'image/png', name: 'taco')
324
+ url = "http://cl.ly/image/2p1x3K1X160b/taco.png"
325
+ attachment = app_client.create_card_attachment(@card.id, url, "image/png", name: "taco")
142
326
 
143
- expect(attachment.name).to eq('taco')
327
+ expect(attachment.name).to eq("taco")
144
328
 
145
329
  # TODO: mime_type for upload is not persisted on Trello
146
- # expect(attachment.mime_type).to eq('image/png')
330
+ # expect(attachment.mime_type).to eq("image/png")
147
331
  end
148
332
 
149
333
  after do
@@ -151,18 +335,18 @@ describe Tacokit::Client::Cards do
151
335
  end
152
336
  end
153
337
 
154
- describe "#create_card_comment", :vcr do
338
+ describe "#add_comment", :vcr do
155
339
  before do
156
340
  @card = app_client.create_card test_list_id, "Autocard", desc: "This is an autogenerated card"
157
341
  end
158
342
 
159
343
  it "creates a comment" do
160
- comment = app_client.create_card_comment(@card.id, "I'm singing, I'm singing, I'm singing!")
344
+ comment = app_client.add_comment(@card.id, "I'm singing, I'm singing, I'm singing!")
161
345
 
162
346
  expect(comment.data.text).to eq "I'm singing, I'm singing, I'm singing!"
163
347
  expect(comment.data.card.id).to eq @card.id
164
348
 
165
- actions = app_client.card_resource(@card.id, "actions")
349
+ actions = app_client.card_actions(@card.id)
166
350
  expect(actions.map(&:id)).to include(comment.id)
167
351
  end
168
352
 
@@ -171,22 +355,92 @@ describe Tacokit::Client::Cards do
171
355
  end
172
356
  end
173
357
 
174
- describe "#delete_card_resource", :vcr do
358
+ describe "#start_checklist", :vcr do
175
359
  before do
176
360
  @card = app_client.create_card test_list_id, "Autocard", desc: "This is an autogenerated card"
177
- @comment = app_client.create_card_comment(@card.id, "I'm singing, I'm singing, I'm singing!")
178
361
  end
179
362
 
180
- it "deletes resource" do
181
- app_client.delete_card_resource @card.id, "actions", @comment.id, "comments"
363
+ it "adds new checklist by name" do
364
+ checklist = app_client.start_checklist(@card.id, "Making a list")
365
+
366
+ expect(checklist.name).to eq("Making a list")
367
+ expect(checklist.card_id).to eq(@card.id)
368
+ end
369
+
370
+ it "copies a checklist by id" do
371
+ source_checklist = app_client.start_checklist(@card.id, "Making a list")
372
+ app_client.add_checklist_item(source_checklist.id, "Test Checklist Item")
373
+
374
+ new_checklist = app_client.copy_checklist(@card.id, source_checklist.id)
182
375
 
183
- actions = app_client.card_resource(@card.id, "actions")
376
+ expect(new_checklist.id).to_not eq(source_checklist.id)
377
+ expect(new_checklist.check_items.size).to eq(1)
378
+ expect(new_checklist.check_items.first.name).to eq("Test Checklist Item")
184
379
 
185
- expect(actions).to be_empty
380
+ assert_requested :post, trello_url_template("cards/#{@card.id}/checklists{?key,token}"),
381
+ body: { "idChecklistSource" => source_checklist.id }
186
382
  end
187
383
 
188
384
  after do
189
385
  app_client.delete_card(@card.id)
190
386
  end
191
387
  end
388
+
389
+ describe "#add_label", :vcr do
390
+ it "adds label to card" do
391
+ label = app_client.add_label(test_card_link, "red")
392
+
393
+ expect(label.color).to eq("red")
394
+ end
395
+
396
+ after do
397
+ app_client.delete("card/#{test_card_link}/labels/red")
398
+ end
399
+ end
400
+
401
+ describe "#vote", :vcr do
402
+ before do
403
+ @card = app_client.create_card test_list_id, "Autocard", desc: "This is an autogenerated card"
404
+ @member_1 = app_client.member
405
+ @member_2 = app_client.member("rossta")
406
+ end
407
+
408
+ it "adds a member's vote to card" do
409
+ app_client.vote(@card.id, @member_1.id)
410
+
411
+ voted = app_client.card_members_voted(@card.id)
412
+ expect(voted.size).to eq(1)
413
+ expect(voted.first.username).to eq("tacokit")
414
+ end
415
+
416
+ after do
417
+ app_client.delete_card(@card.id)
418
+ end
419
+ end
420
+
421
+ describe "#delete_card", :vcr do
422
+ before do
423
+ @card = app_client.create_card test_list_id, "Autocard"
424
+ end
425
+
426
+ it "deletes a card" do
427
+ app_client.delete_card(@card.id)
428
+
429
+ assert_requested :delete, trello_url_template("cards/#{@card.id}{?key,token}")
430
+ expect { app_client.card(@card.id) }.to raise_error(Tacokit::Error::ResourceNotFound)
431
+ end
432
+ end
433
+
434
+ describe "#delete_comment", :vcr do
435
+ before do
436
+ @comment = app_client.add_comment(test_card_link, "This is a comment")
437
+ end
438
+
439
+ it "deletes comment" do
440
+ # rubocop:disable Style/DotPosition
441
+ expect { app_client.delete_comment(test_card_link, @comment.id) }.
442
+ to change { app_client.card_actions(test_card_link, filter: "comment_card").size }.by(-1)
443
+ # rubocop:enable Style/DotPosition
444
+ end
445
+ end
192
446
  end
@@ -1,53 +1,55 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Tacokit::Client::Checklists do
4
4
  def test_checklist_id
5
- '548ddd3f5402eb674035334f'
5
+ "548ddd3f5402eb674035334f"
6
6
  end
7
7
 
8
8
  def test_card_id
9
- '548dd95c8ca25ac9d0d9ce71'
9
+ "548dd95c8ca25ac9d0d9ce71"
10
10
  end
11
11
 
12
12
  describe "#checklist", :vcr do
13
13
  it "returns a checklist by id" do
14
14
  checklist = app_client.checklist(test_checklist_id)
15
15
 
16
- expect(checklist.name).to eq 'Checklist 1'
16
+ expect(checklist.name).to eq "Checklist 1"
17
17
  end
18
18
  end
19
19
 
20
- describe "#checklist_field", :vcr do
21
- it "returns a value" do
22
- field = app_client.checklist_field(test_checklist_id, :pos)
20
+ describe "#update_checklist", :vcr do
21
+ it "updates a checklist" do
22
+ checklist = app_client.update_checklist test_checklist_id,
23
+ name: "Test Checklist 1"
23
24
 
24
- expect(field['_value']).to be_present
25
+ expect(checklist.name).to eq "Test Checklist 1"
26
+ assert_requested :put, trello_url_template("checklists/#{test_checklist_id}{?key,token}")
25
27
  end
26
28
  end
27
29
 
28
- describe "#checklist_resource", :vcr do
29
- it "returns checklist actions" do
30
- items = app_client.checklist_resource(test_checklist_id, :check_items)
31
-
32
- expect(items).to be_any
33
- expect(items.first.state).to be_present
30
+ describe "#check_items", :vcr do
31
+ before do
32
+ @card = app_client.create_card test_list_id, "Autocard", desc: "This is an autogenerated card"
33
+ @checklist = app_client.start_checklist(@card.id, "Making a list")
34
34
  end
35
35
 
36
- it "returns checklist board" do
37
- board = app_client.checklist_resource(test_checklist_id, :board)
36
+ it "retrieves checklist check items" do
37
+ app_client.add_checklist_item(@checklist.id, "Test Checklist Item")
38
+
39
+ check_items = app_client.check_items(@checklist.id)
38
40
 
39
- expect(board.name).to be_present
41
+ expect(check_items.size).to eq(1)
42
+ expect(check_items.first.name).to eq("Test Checklist Item")
40
43
  end
41
44
 
42
- end
45
+ it "adds a checklist check item" do
46
+ item = app_client.add_checklist_item(@checklist.id, "Test Checklist Item")
43
47
 
44
- describe "#update_checklist", :vcr do
45
- it "updates a checklist" do
46
- checklist = app_client.update_checklist test_checklist_id,
47
- name: 'Test Checklist 1'
48
+ expect(item.name).to eq("Test Checklist Item")
49
+ end
48
50
 
49
- expect(checklist.name).to eq 'Test Checklist 1'
50
- assert_requested :put, trello_url_template("checklists/#{test_checklist_id}{?key,token}")
51
+ after do
52
+ app_client.delete_card(@card.id)
51
53
  end
52
54
  end
53
55
 
@@ -61,9 +63,9 @@ describe Tacokit::Client::Checklists do
61
63
  expect(@checklist.pos).to be >= 1
62
64
  assert_requested :post, trello_url_template("checklists{?key,token}"),
63
65
  body: {
64
- 'name' => 'Autochecklist',
65
- 'pos' => 'top',
66
- 'idCard' => test_card_id
66
+ "name" => "Autochecklist",
67
+ "pos" => "top",
68
+ "idCard" => test_card_id
67
69
  }
68
70
  end
69
71
 
@@ -1,12 +1,12 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Tacokit::Client::Labels do
4
4
  def test_label_id
5
- '548a675574d650d567d52ad0'
5
+ "548a675574d650d567d52ad0"
6
6
  end
7
7
 
8
8
  def test_board_id
9
- '548a675581d1d669c9e8184e'
9
+ "548a675581d1d669c9e8184e"
10
10
  end
11
11
 
12
12
  describe "#label", :vcr do
@@ -16,19 +16,11 @@ describe Tacokit::Client::Labels do
16
16
  end
17
17
  end
18
18
 
19
- describe "#label_resource", :vcr do
20
- it "returns a board" do
21
- board = app_client.label_resource(test_label_id, :board)
22
-
23
- expect(board.name).to be_present
24
- end
25
- end
26
-
27
19
  describe "#update_label", :vcr do
28
20
  it "updates a label" do
29
- label = app_client.update_label test_label_id, name: 'Test Label 1'
21
+ label = app_client.update_label test_label_id, name: "Test Label 1"
30
22
 
31
- expect(label.name).to eq 'Test Label 1'
23
+ expect(label.name).to eq "Test Label 1"
32
24
  assert_requested :put, trello_url_template("labels/#{test_label_id}{?key,token}")
33
25
  end
34
26
  end
@@ -44,9 +36,9 @@ describe Tacokit::Client::Labels do
44
36
 
45
37
  assert_requested :post, trello_url_template("labels{?key,token}"),
46
38
  body: {
47
- 'idBoard' => test_board_id,
48
- 'name' => 'Test Label X',
49
- 'color' => 'sky'
39
+ "idBoard" => test_board_id,
40
+ "name" => "Test Label X",
41
+ "color" => "sky"
50
42
  }
51
43
  end
52
44