backpack_tf 0.8.4 → 1.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -3
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +5 -3
  6. data/Gemfile.lock +49 -0
  7. data/README.md +144 -0
  8. data/Rakefile +7 -0
  9. data/backpack_tf.gemspec +2 -2
  10. data/lib/backpack_tf/assets/{attribute_controlled_attached_particles.json → particle_effects.json} +0 -0
  11. data/lib/backpack_tf/client.rb +72 -95
  12. data/lib/backpack_tf/currency/interface.rb +9 -0
  13. data/lib/backpack_tf/currency/response.rb +24 -0
  14. data/lib/backpack_tf/currency.rb +24 -47
  15. data/lib/backpack_tf/helpers.rb +29 -0
  16. data/lib/backpack_tf/interface.rb +29 -0
  17. data/lib/backpack_tf/market_price/interface.rb +9 -0
  18. data/lib/backpack_tf/market_price/response.rb +15 -0
  19. data/lib/backpack_tf/market_price.rb +25 -0
  20. data/lib/backpack_tf/price/interface.rb +19 -0
  21. data/lib/backpack_tf/price/item.rb +85 -0
  22. data/lib/backpack_tf/price/item_price.rb +113 -0
  23. data/lib/backpack_tf/price/particle_effect.rb +27 -0
  24. data/lib/backpack_tf/price/response.rb +38 -0
  25. data/lib/backpack_tf/price.rb +9 -81
  26. data/lib/backpack_tf/price_history/interface.rb +22 -0
  27. data/lib/backpack_tf/price_history/response.rb +15 -0
  28. data/lib/backpack_tf/price_history.rb +25 -0
  29. data/lib/backpack_tf/response.rb +9 -56
  30. data/lib/backpack_tf/special_item/interface.rb +9 -0
  31. data/lib/backpack_tf/special_item/response.rb +16 -0
  32. data/lib/backpack_tf/special_item.rb +11 -21
  33. data/lib/backpack_tf/user/interface.rb +18 -0
  34. data/lib/backpack_tf/user/response.rb +16 -0
  35. data/lib/backpack_tf/user.rb +10 -19
  36. data/lib/backpack_tf/user_listing/interface.rb +18 -0
  37. data/lib/backpack_tf/user_listing/response.rb +15 -0
  38. data/lib/backpack_tf/user_listing.rb +31 -43
  39. data/lib/backpack_tf/version.rb +1 -1
  40. data/lib/backpack_tf.rb +8 -8
  41. data/spec/backpack_tf/client_spec.rb +151 -101
  42. data/spec/backpack_tf/currency/interface_spec.rb +8 -0
  43. data/spec/backpack_tf/currency/response_spec.rb +41 -0
  44. data/spec/backpack_tf/currency_spec.rb +34 -118
  45. data/spec/backpack_tf/helpers_spec.rb +85 -0
  46. data/spec/backpack_tf/interface_spec.rb +56 -0
  47. data/spec/backpack_tf/market_price/interface_spec.rb +8 -0
  48. data/spec/backpack_tf/market_price/response_spec.rb +22 -0
  49. data/spec/backpack_tf/market_price_spec.rb +22 -0
  50. data/spec/backpack_tf/price/interface_spec.rb +27 -0
  51. data/spec/backpack_tf/price/item_price_spec.rb +101 -0
  52. data/spec/backpack_tf/price/item_spec.rb +291 -0
  53. data/spec/backpack_tf/price/particle_effect_spec.rb +23 -0
  54. data/spec/backpack_tf/price/response_spec.rb +87 -0
  55. data/spec/backpack_tf/price_history/interface_spec.rb +38 -0
  56. data/spec/backpack_tf/price_history/response_spec.rb +22 -0
  57. data/spec/backpack_tf/price_history_spec.rb +24 -0
  58. data/spec/backpack_tf/response_spec.rb +22 -108
  59. data/spec/backpack_tf/special_item/interface_spec.rb +8 -0
  60. data/spec/backpack_tf/special_item/response_spec.rb +26 -0
  61. data/spec/backpack_tf/special_item_spec.rb +23 -100
  62. data/spec/backpack_tf/user/interface_spec.rb +20 -0
  63. data/spec/backpack_tf/user/response_spec.rb +27 -0
  64. data/spec/backpack_tf/user_listing/interface_spec.rb +20 -0
  65. data/spec/backpack_tf/user_listing/response_spec.rb +21 -0
  66. data/spec/backpack_tf/user_listing_spec.rb +53 -81
  67. data/spec/backpack_tf/user_spec.rb +16 -83
  68. data/spec/fixtures/item_price_typical.json +6 -0
  69. data/spec/fixtures/item_price_unusual.json +7 -0
  70. data/spec/fixtures/item_typical.json +1 -1
  71. data/spec/fixtures/item_unusual.json +311 -1
  72. data/spec/fixtures/item_with_dual_craftability_tradability.json +59 -0
  73. data/spec/fixtures/market_prices.json +1 -0
  74. data/spec/fixtures/price_history.json +1 -0
  75. data/spec/fixtures/prices.json +80 -1
  76. data/spec/fixtures/user_listing.json +1 -1
  77. data/spec/fixtures/user_listing_individual.json +51 -0
  78. data/spec/spec_helper.rb +12 -52
  79. metadata +61 -16
  80. data/TODO.md +0 -15
  81. data/lib/backpack_tf/item.rb +0 -84
  82. data/lib/backpack_tf/item_price.rb +0 -172
  83. data/readme.md +0 -96
  84. data/spec/backpack_tf/inherited_class_methods_spec.rb +0 -100
  85. data/spec/backpack_tf/item_price_spec.rb +0 -119
  86. data/spec/backpack_tf/item_spec.rb +0 -126
  87. data/spec/backpack_tf/price_spec.rb +0 -184
  88. data/spec/fixtures/item_without_defindex.json +0 -1
@@ -0,0 +1,291 @@
1
+ require 'spec_helper'
2
+
3
+ describe BackpackTF::Price::Item do
4
+ let(:attr) do
5
+ { 'prices' => {}, 'defindex' => ['1'] }
6
+ end
7
+ let(:item) do
8
+ described_class.new('item', attr)
9
+ end
10
+ let(:item_price) do
11
+ BackpackTF::Price::ItemPrice.new('q_t_c', {})
12
+ end
13
+
14
+ describe '#process_defindex' do
15
+ after(:each) do
16
+ attr['defindex'] = nil
17
+ end
18
+
19
+ it 'returns nil when arr length is 0' do
20
+ attr['defindex'] = []
21
+ actual = item.send(:process_defindex, attr['defindex'])
22
+ expect(actual).to be_nil
23
+ end
24
+
25
+ it 'returns value when arr length is 1' do
26
+ attr['defindex'] = ['bar']
27
+ actual = item.send(:process_defindex, attr['defindex'])
28
+ expect(actual).to eq 'bar'
29
+ end
30
+
31
+ it 'otherwise returns array' do
32
+ attr['defindex'] = %w(bar quux)
33
+ actual = item.send(:process_defindex, attr['defindex'])
34
+ expect(actual).to eq %w(bar quux)
35
+ end
36
+ end
37
+
38
+ describe '#generate_prices_hash' do
39
+ context 'a typical item' do
40
+ it 'calls build_item_price' do
41
+ mock_input_hash = {
42
+ 'prices' => {
43
+ '6' => {
44
+ 'Tradable' => {
45
+ 'Craftable' => {
46
+ '0' => {}
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ expect(item).to receive(:build_item_price)
53
+ item.send(:generate_prices_hash, mock_input_hash)
54
+ end
55
+ end
56
+
57
+ context 'an item with "Unusual" quality' do
58
+ it 'calls build_unusual_item_price' do
59
+ mock_input_hash = {
60
+ 'prices' => {
61
+ '5' => {
62
+ 'Tradable' => {
63
+ 'Craftable' => {
64
+ '1' => {}
65
+ }
66
+ }
67
+ }
68
+ }
69
+ }
70
+ expect(item).to receive(:build_unusual_item_price)
71
+ item.send(:generate_prices_hash, mock_input_hash)
72
+ end
73
+ end
74
+
75
+ context 'a crate' do
76
+ it 'calls build_crate_price' do
77
+ mock_input_hash = {
78
+ 'prices' => {
79
+ '6' => {
80
+ 'Tradable' => {
81
+ 'Craftable' => {
82
+ '2' => {}
83
+ }
84
+ }
85
+ }
86
+ }
87
+ }
88
+ expect(item).to receive(:build_crate_price)
89
+ item.send(:generate_prices_hash, mock_input_hash)
90
+ end
91
+ end
92
+ end
93
+
94
+ describe '#quality_index_to_name' do
95
+ it 'calls ItemPrice.quality_index_to_name' do
96
+ expect(BackpackTF::Price::ItemPrice)
97
+ .to receive(:qualities)
98
+ .and_return([:foo, :bar])
99
+ item.send(:quality_index_to_name, '1')
100
+ end
101
+ end
102
+
103
+ describe '#keyname' do
104
+ before(:each) do
105
+ expect(item).to receive(:quality_index_to_name).and_return('Quality')
106
+ end
107
+ it 'returns a string delimited by underscore' do
108
+ actual = item.send(:keyname, 1, 'Tradability', 'Craftability')
109
+ expected = 'Quality_Tradability_Craftability'
110
+ expect(actual).to eq expected
111
+ end
112
+
113
+ it 'returns a string plus priceindex, delimited by underscore' do
114
+ actual = item.send(:keyname, 1, 'Tradability', 'Craftability', '5')
115
+ expected = 'Quality_Tradability_Craftability_#5'
116
+ expect(actual).to eq expected
117
+ end
118
+ end
119
+
120
+ describe '#build_item_price' do
121
+ before(:each) do
122
+ allow(BackpackTF::Price::ItemPrice)
123
+ .to receive(:new)
124
+ .and_return(item_price)
125
+ end
126
+
127
+ it 'calls for a new ItemPrice object' do
128
+ expect(BackpackTF::Price::ItemPrice).to receive(:new)
129
+ item.send(:build_item_price, {}, 'key_str', :attr)
130
+ end
131
+ it 'the new item is an ItemPrice object' do
132
+ actual = item.send(:build_item_price, {}, 'key_str', :attr)
133
+ expect(actual['key_str']).to be_a BackpackTF::Price::ItemPrice
134
+ end
135
+ end
136
+
137
+ describe '#build_unusual_item_price' do
138
+ before(:each) do
139
+ expect(BackpackTF::Price::ItemPrice)
140
+ .to receive(:new)
141
+ .and_return(item_price)
142
+ allow_any_instance_of(BackpackTF::Price::ItemPrice)
143
+ .to receive(:effect)
144
+ .and_return('effect')
145
+ end
146
+
147
+ it 'calls for a new ItemPrice object' do
148
+ item.send(:build_unusual_item_price, {}, 'q_t_c', :attr, :price_idx)
149
+ end
150
+ it 'the name of the new key is the effect name of item price object' do
151
+ actual = item.send(:build_unusual_item_price, {}, 'q_t_c', :attr, '5')
152
+ expect(actual['effect']).to be_a BackpackTF::Price::ItemPrice
153
+ end
154
+ end
155
+
156
+ describe '#build_crate_price' do
157
+ before(:each) do
158
+ allow(BackpackTF::Price::ItemPrice)
159
+ .to receive(:new)
160
+ .and_return(item_price)
161
+ end
162
+
163
+ it 'calls for a new ItemPrice object' do
164
+ expect(BackpackTF::Price::ItemPrice).to receive(:new)
165
+ item.send(:build_crate_price, {}, 'key_str', :attr, '85')
166
+ end
167
+ it 'the new item is an ItemPrice object' do
168
+ actual = item.send(:build_crate_price, {}, 'key_str', :attr, '85')
169
+ expect(actual['key_str']).to be_a BackpackTF::Price::ItemPrice
170
+ end
171
+ end
172
+
173
+ shared_examples 'a common item' do |passed_item_attr|
174
+ describe '#generate_prices_hash' do
175
+ let(:prices_hash) do
176
+ subject.send(:generate_prices_hash, passed_item_attr)
177
+ end
178
+
179
+ it 'each key is a String' do
180
+ expect(prices_hash.keys).to all be_a String
181
+ end
182
+ it 'value of each key is a BackpackTF::ItemPrice object' do
183
+ expect(prices_hash.values).to all be_an BackpackTF::Price::ItemPrice
184
+ end
185
+ end
186
+
187
+ describe 'the @prices instance variable' do
188
+ it 'is a Hash' do
189
+ expect(subject.prices).to be_a Hash
190
+ end
191
+ it 'each value is a BackpackTF::ItemPrice object' do
192
+ expect(subject.prices.values).to all be_an BackpackTF::Price::ItemPrice
193
+ end
194
+ end
195
+ end
196
+
197
+ describe 'A typical item' do
198
+ item_attr = JSON.parse(file_fixture('item_typical.json'))['Kritzkrieg']
199
+ item = described_class.new('Kritzkrieg', item_attr)
200
+ subject { item }
201
+ it_behaves_like('a common item', item_attr)
202
+
203
+ context 'item-specific tests' do
204
+ it 'should have these values' do
205
+ expect(subject.item_name).to eq 'Kritzkrieg'
206
+ expect(subject.defindex).to eq 35
207
+ end
208
+ it '@prices should have these keys' do
209
+ expected = ['Strange_Tradable_Craftable',
210
+ "Collector's_Tradable_Craftable",
211
+ 'Vintage_Tradable_Craftable',
212
+ 'Unique_Tradable_Craftable',
213
+ 'Unique_Tradable_Non-Craftable']
214
+ expect(subject.prices.keys).to match_array expected
215
+ end
216
+ end
217
+ end
218
+
219
+ describe "An item with the quality of 'Unusual'" do
220
+ item_attr = JSON.parse(file_fixture('item_unusual.json'))['Barnstormer']
221
+ item = described_class.new('Barnstormer', item_attr)
222
+ subject { item }
223
+ it_behaves_like('a common item', item_attr)
224
+
225
+ context 'item-specific tests' do
226
+ it 'should have these values' do
227
+ expect(item.item_name).to eq 'Barnstormer'
228
+ expect(item.defindex).to eq 988
229
+ end
230
+ it '@prices should have these keys' do
231
+ priceindex_vals = ['Aces High', 'Amaranthine', 'Anti-Freeze', 'Blizzardy Storm', 'Bubbling', 'Burning Flames', 'Circling Heart', 'Circling TF Logo', 'Cloud 9', 'Dead Presidents', 'Death at Dusk', 'Disco Beat Down', 'Electrostatic', 'Green Black Hole', 'Green Confetti', 'Green Energy', 'Haunted Ghosts', 'Kill-a-Watt', 'Memory Leak', 'Miami Nights', 'Molten Mallard', 'Morning Glory', "Nuts n' Bolts", 'Orbiting Fire', 'Orbiting Planets', 'Overclocked', 'Phosphorous', 'Power Surge', 'Purple Confetti', 'Purple Energy', 'Roboactive', 'Scorching Flames', 'Smoking', 'Something Burning This Way Comes', 'Steaming', 'Stormy Storm', 'Sulphurous', 'Terror-Watt', 'The Ooze', 'Time Warp', 'Unique_Tradable_Craftable']
232
+ expect(subject.prices.keys).to match_array priceindex_vals
233
+ end
234
+ end
235
+ end
236
+
237
+ describe 'An item with many priceindex values (Crate or Unusual)' do
238
+ item_attr = JSON.parse(file_fixture('item_crate.json'))['Mann Co. Supply Munition']
239
+ item = described_class.new('Mann Co. Supply Munition', item_attr)
240
+ subject { item }
241
+ it_behaves_like('a common item', item_attr)
242
+
243
+ context 'item-specific tests' do
244
+ it 'should have these values' do
245
+ expect(subject.item_name).to eq 'Mann Co. Supply Munition'
246
+ expected_defindexes = [5734, 5735, 5742, 5752, 5781, 5802, 5803]
247
+ expect(subject.defindex).to match_array expected_defindexes
248
+ end
249
+ it 'prices array should have these keys' do
250
+ expected_keys = ['Unique_Tradable_Craftable_#82',
251
+ 'Unique_Tradable_Craftable_#83',
252
+ 'Unique_Tradable_Craftable_#84',
253
+ 'Unique_Tradable_Craftable_#85',
254
+ 'Unique_Tradable_Craftable_#90',
255
+ 'Unique_Tradable_Craftable_#91',
256
+ 'Unique_Tradable_Craftable_#92']
257
+ expect(subject.prices.keys).to match_array expected_keys
258
+ end
259
+ end
260
+ end
261
+
262
+ describe 'An item with an unconventional structure' do
263
+ item_attr = JSON.parse(file_fixture('item_with_unconventional_structure.json'))['Aqua Summer 2013 Cooler']
264
+ item = described_class.new('Aqua Summer 2013 Cooler', item_attr)
265
+ subject { item }
266
+ it_behaves_like('a common item', item_attr)
267
+
268
+ context 'item-specific tests' do
269
+ it 'should have these values' do
270
+ expect(item.item_name).to eq 'Aqua Summer 2013 Cooler'
271
+ expect(item.defindex).to eq 5650
272
+ end
273
+ end
274
+ end
275
+
276
+ describe 'An item with Tradable, Non-Tradable & Craftable, Non-Craftable' do
277
+ item_attr = JSON.parse(file_fixture('item_with_dual_craftability_tradability.json'))['All-Father']
278
+ subject { described_class.new('All-Father', item_attr) }
279
+
280
+ context 'item-specific tests' do
281
+ it '@prices hash has these keys' do
282
+ expected = ['Strange_Tradable_Craftable',
283
+ 'Strange_Tradable_Non-Craftable',
284
+ 'Strange_Non-Tradable_Craftable',
285
+ 'Unique_Tradable_Craftable',
286
+ 'Unique_Tradable_Non-Craftable']
287
+ expect(subject.prices.keys).to match_array expected
288
+ end
289
+ end
290
+ end
291
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe BackpackTF::Price::ParticleEffect do
4
+ describe '::read_stored_effects_info' do
5
+ it 'creates a key value pair for each id & name' do
6
+ expect(described_class.read_stored_effects_info[17]).to eq 'Sunbeams'
7
+ expect(described_class.read_stored_effects_info[5]).to eq 'Holy Glow'
8
+ end
9
+ it 'is nil if it cannot find that key' do
10
+ expect(described_class.read_stored_effects_info[nil]).to be_nil
11
+ end
12
+
13
+ context '@list' do
14
+ it 'same thing can be accessed through class variable' do
15
+ expect(described_class.list[17]).to eq 'Sunbeams'
16
+ expect(described_class.list[5]).to eq 'Holy Glow'
17
+ end
18
+ it 'is nil if it cannot find that key' do
19
+ expect(described_class.list[nil]).to be_nil
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ describe BackpackTF::Price::Response do
4
+ let(:response) do
5
+ {
6
+ 'raw_usd_value' => 'raw_usd_value',
7
+ 'usd_currency' => 'usd_currency',
8
+ 'usd_currency_index' => 'usd_currency_index'
9
+ }
10
+ end
11
+
12
+ context 'reader methods' do
13
+ before(:each) do
14
+ described_class.response = response
15
+ end
16
+ after(:each) do
17
+ described_class.response = nil
18
+ end
19
+
20
+ describe '::raw_usd_value' do
21
+ it 'returns the value' do
22
+ expect(described_class.raw_usd_value).to eq 'raw_usd_value'
23
+ end
24
+ end
25
+
26
+ describe '::usd_currency' do
27
+ it 'returns the value' do
28
+ expect(described_class.usd_currency).to eq 'usd_currency'
29
+ end
30
+ end
31
+
32
+ describe '::usd_currency_index' do
33
+ it 'returns the value' do
34
+ expect(described_class.usd_currency_index).to eq 'usd_currency_index'
35
+ end
36
+ end
37
+
38
+ describe '::items' do
39
+ after :each do
40
+ described_class.class_eval { @items = nil }
41
+ end
42
+ context 'when @items is not nil' do
43
+ before :each do
44
+ described_class.class_eval { @items = { foo: 'bar' } }
45
+ end
46
+ it 'returns @items' do
47
+ expected = described_class.class_eval { @items }
48
+ expect(described_class.items).to eq expected
49
+ end
50
+ end
51
+
52
+ context 'when @items is nil' do
53
+ before :each do
54
+ described_class.class_eval { @items = nil }
55
+ end
56
+ it 'calls .generate_items' do
57
+ expect(described_class).to receive(:generate_items)
58
+ described_class.items
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ describe '::generate_items' do
65
+ let(:json_response) do
66
+ fixture = file_fixture('prices.json')
67
+ JSON.parse(fixture)['response']
68
+ end
69
+
70
+ context 'using keys to generate BackpackTF::Item objects' do
71
+ before(:each) do
72
+ described_class.response = json_response
73
+ end
74
+ after(:each) do
75
+ described_class.response = nil
76
+ end
77
+ it 'each value of hash is a BackpackTF::Price::Item object' do
78
+ actual = described_class.generate_items.values
79
+ expect(actual).to all be_a BackpackTF::Price::Item
80
+ end
81
+ it 'if an item does not have a valid `defindex`, then it is ignored' do
82
+ generated_items = described_class.generate_items
83
+ expect(generated_items['Random Craft Hat']).to be_nil
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe BackpackTF::PriceHistory::Interface do
4
+ it 'has these default attributes' do
5
+ expect(described_class.name).to eq :IGetPriceHistory
6
+ expect(described_class.version).to eq 1
7
+ expect(described_class.item).to eq nil
8
+ expect(described_class.quality).to eq nil
9
+ expect(described_class.tradable).to eq nil
10
+ expect(described_class.craftable).to eq nil
11
+ expect(described_class.priceindex).to eq nil
12
+ end
13
+ describe '::defaults' do
14
+ after(:each) do
15
+ described_class.class_eval do
16
+ @item = nil
17
+ @quality = nil
18
+ @tradable = nil
19
+ @craftable = nil
20
+ @priceindex = nil
21
+ end
22
+ end
23
+ it 'can modify its values' do
24
+ options = {
25
+ item: 'item name or defindex',
26
+ quality: 'quality name or defindex',
27
+ tradable: 1,
28
+ craftable: 1,
29
+ priceindex: 0
30
+ }
31
+ described_class.defaults(options)
32
+ ivars = [:@item, :@quality, :@tradable, :@craftable, :@priceindex]
33
+ ivars.each do |ivar|
34
+ expect(described_class.instance_variable_get(ivar)).not_to be_nil
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe BackpackTF::PriceHistory::Response do
4
+ let(:json_response) do
5
+ fixture = file_fixture('price_history.json')
6
+ JSON.parse(fixture)['response']
7
+ end
8
+
9
+ describe '::history' do
10
+ before(:each) do
11
+ described_class.response = json_response
12
+ end
13
+ after :each do
14
+ described_class.response = nil
15
+ end
16
+
17
+ it 'each entry is a BackpackTF::PriceHistory object' do
18
+ actual = BackpackTF::PriceHistory::Response.history
19
+ expect(actual).to all be_a BackpackTF::PriceHistory
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe BackpackTF::PriceHistory do
4
+ let(:response_attr) do
5
+ {
6
+ 'value' => 2.5,
7
+ 'value_high' => 2.5,
8
+ 'currency' => 'keys',
9
+ 'timestamp' => 1346988149
10
+ }
11
+ end
12
+
13
+ describe '#initialize' do
14
+ it 'has these these attributes' do
15
+ price_history = described_class.new(response_attr)
16
+ expect(price_history).to have_attributes(
17
+ value: 2.5,
18
+ value_high: 2.5,
19
+ currency: 'keys',
20
+ timestamp: 1346988149
21
+ )
22
+ end
23
+ end
24
+ end
@@ -1,124 +1,38 @@
1
1
  require 'spec_helper'
2
2
 
3
- module BackpackTF
4
-
5
- describe Response do
6
- let (:bp) { Client.new }
7
-
8
- let(:json_obj) {
9
- fixture = file_fixture('currencies.json')
10
- fixture = JSON.parse(fixture)['response']
11
- described_class.hash_keys_to_sym(fixture)
12
- }
13
-
14
- let(:more_json) {
15
- fixture = file_fixture('currencies_updated.json')
16
- fixture = JSON.parse(fixture)['response']
17
- described_class.hash_keys_to_sym(fixture)
3
+ describe BackpackTF::Response do
4
+ let(:response) do
5
+ {
6
+ 'success' => 'success',
7
+ 'message' => 'message',
8
+ 'current_time' => 'current_time'
18
9
  }
10
+ end
19
11
 
20
- describe '::interface' do
21
- it 'should be nil' do
22
- expect(Response.interface).to be_nil
23
- end
12
+ context 'reader methods' do
13
+ before(:each) do
14
+ described_class.response = response
24
15
  end
25
-
26
- describe '::to_sym' do
27
- it 'should return the name of the class, as a Symbol object' do
28
- expect(Response.to_sym).to eq :'BackpackTF::Response'
29
- end
16
+ after(:each) do
17
+ described_class.response = nil
30
18
  end
31
19
 
32
- describe '::responses' do
33
- let (:faked_class_sym) { :'BackpackTF::FakedClass' }
34
-
35
- after :all do
36
- Response.responses(:reset => :confirm)
37
- expect(Response.responses).to be_empty
38
- expect(described_class.response).to be_nil
39
- end
40
-
41
- it 'returns a Hash object' do
42
- expect(Response.responses).to be_instance_of Hash
20
+ describe '::success' do
21
+ it 'returns success' do
22
+ expect(described_class.success).to eq 'success'
43
23
  end
44
-
45
- context 'expected input' do
46
- it 'has these keys' do
47
- stub_http_response_with('currencies.json')
48
- expect(bp.fetch(:currencies).keys).to eq ['success', 'currencies', 'name', 'url', 'current_time']
49
- end
50
- end
51
-
52
- context 'resetting' do
53
- before :each do
54
- Response.responses(faked_class_sym => json_obj)
55
- expect(Response.responses[faked_class_sym]).to eq json_obj
56
- end
57
- it 'can be emptied by passing in `:reset => :confirm`' do
58
- Response.responses(:reset => :confirm)
59
- expect(Response.responses).to be_empty
60
- end
61
- end
62
-
63
- context 'reading' do
64
-
65
- before :each do
66
- Response.responses(:reset => :confirm)
67
- expect(Response.responses).to be_empty
68
- end
69
-
70
- it 'returns the value of the key' do
71
- res = { faked_class_sym => json_obj }
72
- Response.responses(res)
73
- expect(Response.responses[faked_class_sym]).to eq json_obj
74
- end
75
- it 'returns nil when key has no value' do
76
- Response.responses(:foo)
77
- expect(Response.responses[:foo]).to be_nil
78
- end
79
- end
80
-
81
- context 'updating' do
82
-
83
- before :each do
84
- Response.responses(:reset => :confirm)
85
- expect(Response.responses).to be_empty
86
- end
87
-
88
- it "updates a key's value when the key already exists" do
89
- entry1 = { faked_class_sym => json_obj }
90
- Response.responses(entry1)
91
- expect(Response.responses[faked_class_sym]).to eq json_obj
92
- entry2 = { faked_class_sym => more_json }
93
- Response.responses(entry2)
94
- expect(Response.responses[faked_class_sym]).to eq more_json
95
- end
96
- it 'creates a new key & value if key does not exist' do
97
- res = { faked_class_sym => json_obj }
98
- expect(Response.responses(res)[faked_class_sym]).to eq json_obj
99
- end
100
- it 'is not nil when you reference entire hash object' do
101
- Response.responses( { faked_class_sym => json_obj } )
102
- expect(Response.responses).not_to be_nil
103
- end
104
- end
105
-
106
24
  end
107
25
 
108
- describe '::response' do
109
- it "returns nil when called by #{described_class}" do
110
- expect(described_class.response).to be_nil
26
+ describe '::message' do
27
+ it 'returns message' do
28
+ expect(described_class.message).to eq 'message'
111
29
  end
112
30
  end
113
31
 
114
- describe '::hash_keys_to_sym' do
115
- it 'changes the type of each key from String to Symbol' do
116
- metal = {'quality'=>6, 'priceindex'=>0, 'single'=>'ref', 'plural'=>'ref', 'round'=>2, 'blanket'=>0, 'craftable'=>'Craftable', 'tradable'=>'Tradable', 'defindex'=>5002}
117
- hashed_metal = {:quality=>6, :priceindex=>0, :single=>'ref', :plural=>'ref', :round=>2, :blanket=>0, :craftable=>'Craftable', :tradable=>'Tradable', :defindex=>5002}
118
- expect(Response.hash_keys_to_sym(metal)).to eq hashed_metal
119
- end
32
+ describe '::current_time' do
33
+ it 'returns current_time' do
34
+ expect(described_class.current_time).to eq 'current_time'
35
+ end
120
36
  end
121
-
122
37
  end
123
-
124
38
  end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe BackpackTF::SpecialItem::Interface do
4
+ it 'has these default attributes' do
5
+ expect(described_class.name).to eq :IGetSpecialItems
6
+ expect(described_class.version).to eq 1
7
+ end
8
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe BackpackTF::SpecialItem::Response do
4
+ let(:json_response) do
5
+ fixture = file_fixture('special_items.json')
6
+ JSON.parse(fixture)['response']
7
+ end
8
+
9
+ describe '::items' do
10
+ before(:each) do
11
+ described_class.response = json_response
12
+ end
13
+ after(:each) do
14
+ described_class.response = nil
15
+ end
16
+
17
+ it 'has these 2 keys' do
18
+ actual_keys = described_class.items.keys
19
+ expected_keys = [':weed:', 'Random Craft Hat']
20
+ expect(actual_keys).to match_array expected_keys
21
+ end
22
+ it 'each key points to an instance of BackpackTF::SpecialItem' do
23
+ expect(described_class.items.values).to all be_a BackpackTF::SpecialItem
24
+ end
25
+ end
26
+ end