solidus_api_v2 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +2 -0
  4. data/CHANGELOG.md +38 -0
  5. data/Gemfile +13 -0
  6. data/LICENSE +26 -0
  7. data/README.md +98 -0
  8. data/Rakefile +37 -0
  9. data/app/controllers/concerns/spree/api/v2/renderable.rb +51 -0
  10. data/app/controllers/spree/api/v2/base_controller.rb +31 -0
  11. data/app/controllers/spree/api/v2/children_controller.rb +29 -0
  12. data/app/controllers/spree/api/v2/countries_controller.rb +21 -0
  13. data/app/controllers/spree/api/v2/images_controller.rb +29 -0
  14. data/app/controllers/spree/api/v2/line_items_controller.rb +36 -0
  15. data/app/controllers/spree/api/v2/option_types_controller.rb +31 -0
  16. data/app/controllers/spree/api/v2/option_values_controller.rb +29 -0
  17. data/app/controllers/spree/api/v2/orders_controller.rb +11 -0
  18. data/app/controllers/spree/api/v2/prices_controller.rb +27 -0
  19. data/app/controllers/spree/api/v2/products_controller.rb +37 -0
  20. data/app/controllers/spree/api/v2/states_controller.rb +29 -0
  21. data/app/controllers/spree/api/v2/taxonomies_controller.rb +21 -0
  22. data/app/controllers/spree/api/v2/taxons_controller.rb +40 -0
  23. data/app/controllers/spree/api/v2/variants_controller.rb +35 -0
  24. data/app/models/spree/base_decorator.rb +5 -0
  25. data/app/models/spree/image_decorator.rb +3 -0
  26. data/app/models/spree/price_decorator.rb +3 -0
  27. data/app/models/spree/state_decorator.rb +3 -0
  28. data/app/serializers/spree/address_serializer.rb +9 -0
  29. data/app/serializers/spree/base_serializer.rb +13 -0
  30. data/app/serializers/spree/country_serializer.rb +7 -0
  31. data/app/serializers/spree/error_serializer.rb +52 -0
  32. data/app/serializers/spree/image_serializer.rb +13 -0
  33. data/app/serializers/spree/line_item_serializer.rb +13 -0
  34. data/app/serializers/spree/option_type_serializer.rb +8 -0
  35. data/app/serializers/spree/option_value_serializer.rb +8 -0
  36. data/app/serializers/spree/order_serializer.rb +21 -0
  37. data/app/serializers/spree/price_serializer.rb +7 -0
  38. data/app/serializers/spree/product_serializer.rb +12 -0
  39. data/app/serializers/spree/role_serializer.rb +5 -0
  40. data/app/serializers/spree/state_serializer.rb +7 -0
  41. data/app/serializers/spree/store_serializer.rb +6 -0
  42. data/app/serializers/spree/taxon_serializer.rb +16 -0
  43. data/app/serializers/spree/taxonomy_serializer.rb +7 -0
  44. data/app/serializers/spree/user_serializer.rb +5 -0
  45. data/app/serializers/spree/variant_serializer.rb +12 -0
  46. data/bin/rails +7 -0
  47. data/circle.yml +13 -0
  48. data/config/locales/en.yml +25 -0
  49. data/config/routes.rb +53 -0
  50. data/docs/.nojekyll +0 -0
  51. data/docs/Dockerfile +12 -0
  52. data/docs/Gemfile +13 -0
  53. data/docs/README.md +12 -0
  54. data/docs/Rakefile +9 -0
  55. data/docs/config.rb +39 -0
  56. data/docs/font-selection.json +148 -0
  57. data/docs/source/fonts/slate.eot +0 -0
  58. data/docs/source/fonts/slate.svg +14 -0
  59. data/docs/source/fonts/slate.ttf +0 -0
  60. data/docs/source/fonts/slate.woff +0 -0
  61. data/docs/source/fonts/slate.woff2 +0 -0
  62. data/docs/source/images/logo.png +0 -0
  63. data/docs/source/images/navbar.png +0 -0
  64. data/docs/source/includes/_authentication.md +61 -0
  65. data/docs/source/includes/_countries.md +133 -0
  66. data/docs/source/includes/_errors.md +17 -0
  67. data/docs/source/includes/_filtering.md +11 -0
  68. data/docs/source/includes/_images.md +201 -0
  69. data/docs/source/includes/_line_items.md +137 -0
  70. data/docs/source/includes/_option_types.md +267 -0
  71. data/docs/source/includes/_option_values.md +227 -0
  72. data/docs/source/includes/_orders.md +75 -0
  73. data/docs/source/includes/_pagination.md +10 -0
  74. data/docs/source/includes/_prices.md +188 -0
  75. data/docs/source/includes/_products.md +403 -0
  76. data/docs/source/includes/_states.md +96 -0
  77. data/docs/source/includes/_taxonomies.md +325 -0
  78. data/docs/source/includes/_taxons.md +414 -0
  79. data/docs/source/includes/_variants.md +430 -0
  80. data/docs/source/index.md +53 -0
  81. data/docs/source/javascripts/all.js +4 -0
  82. data/docs/source/javascripts/all_nosearch.js +3 -0
  83. data/docs/source/javascripts/app/_lang.js +162 -0
  84. data/docs/source/javascripts/app/_search.js +74 -0
  85. data/docs/source/javascripts/app/_toc.js +55 -0
  86. data/docs/source/javascripts/lib/_energize.js +169 -0
  87. data/docs/source/javascripts/lib/_imagesloaded.min.js +7 -0
  88. data/docs/source/javascripts/lib/_jquery.highlight.js +108 -0
  89. data/docs/source/javascripts/lib/_jquery.tocify.js +1042 -0
  90. data/docs/source/javascripts/lib/_jquery_ui.js +566 -0
  91. data/docs/source/javascripts/lib/_lunr.js +1910 -0
  92. data/docs/source/layouts/layout.erb +102 -0
  93. data/docs/source/stylesheets/_icon-font.scss +38 -0
  94. data/docs/source/stylesheets/_normalize.css +427 -0
  95. data/docs/source/stylesheets/_syntax.scss.erb +27 -0
  96. data/docs/source/stylesheets/_variables.scss +109 -0
  97. data/docs/source/stylesheets/print.css.scss +142 -0
  98. data/docs/source/stylesheets/screen.css.scss +622 -0
  99. data/lib/solidus_api_v2.rb +5 -0
  100. data/lib/spree_api_v2/engine.rb +21 -0
  101. data/lib/spree_api_v2.rb +4 -0
  102. data/solidus_api_v2.gemspec +36 -0
  103. data/spec/controllers/spree/api/v2/children_controller_spec.rb +28 -0
  104. data/spec/controllers/spree/api/v2/countries_controller_spec.rb +25 -0
  105. data/spec/controllers/spree/api/v2/images_controller_spec.rb +93 -0
  106. data/spec/controllers/spree/api/v2/line_items_controller_spec.rb +86 -0
  107. data/spec/controllers/spree/api/v2/option_types_controller_spec.rb +73 -0
  108. data/spec/controllers/spree/api/v2/option_values_controller_spec.rb +88 -0
  109. data/spec/controllers/spree/api/v2/orders_controller_spec.rb +15 -0
  110. data/spec/controllers/spree/api/v2/prices_controller_spec.rb +55 -0
  111. data/spec/controllers/spree/api/v2/products_controller_spec.rb +95 -0
  112. data/spec/controllers/spree/api/v2/states_controller_spec.rb +42 -0
  113. data/spec/controllers/spree/api/v2/taxonomies_controller_spec.rb +31 -0
  114. data/spec/controllers/spree/api/v2/taxons_controller_spec.rb +54 -0
  115. data/spec/controllers/spree/api/v2/variants_controller_spec.rb +108 -0
  116. data/spec/models/spree/base_decorator_spec.rb +9 -0
  117. data/spec/models/spree/price_decorator_spec.rb +3 -0
  118. data/spec/serializers/spree/address_serializer_spec.rb +35 -0
  119. data/spec/serializers/spree/country_serializer_spec.rb +27 -0
  120. data/spec/serializers/spree/error_serializer_spec.rb +116 -0
  121. data/spec/serializers/spree/image_serializer_spec.rb +30 -0
  122. data/spec/serializers/spree/line_item_serializer_spec.rb +40 -0
  123. data/spec/serializers/spree/option_type_serializer_spec.rb +27 -0
  124. data/spec/serializers/spree/option_value_serializer_spec.rb +29 -0
  125. data/spec/serializers/spree/order_serializer_spec.rb +69 -0
  126. data/spec/serializers/spree/price_serializer_spec.rb +28 -0
  127. data/spec/serializers/spree/product_serializer_spec.rb +47 -0
  128. data/spec/serializers/spree/role_serializer_spec.rb +17 -0
  129. data/spec/serializers/spree/state_serializer_spec.rb +25 -0
  130. data/spec/serializers/spree/store_serializer_spec.rb +25 -0
  131. data/spec/serializers/spree/taxon_serializer_spec.rb +44 -0
  132. data/spec/serializers/spree/taxonomy_serializer_spec.rb +27 -0
  133. data/spec/serializers/spree/user_serializer_spec.rb +17 -0
  134. data/spec/serializers/spree/variant_serializer_spec.rb +55 -0
  135. data/spec/spec_helper.rb +51 -0
  136. data/spec/support/shoulda_matchers.rb +6 -0
  137. data/spree_api_v2.gemspec +36 -0
  138. metadata +437 -0
@@ -0,0 +1,28 @@
1
+ describe Spree::Api::V2::ChildrenController do
2
+ routes { Spree::Core::Engine.routes }
3
+
4
+ let(:taxon) { create :taxon }
5
+ let!(:child) { create :taxon, parent: taxon, taxonomy: taxon.taxonomy }
6
+
7
+ describe '#index' do
8
+ context 'by taxon' do
9
+ it 'can list all the children' do
10
+ get :index, taxon_id: taxon.id
11
+ taxon_ids = parse_json(response.body)['data'].map do |taxon|
12
+ taxon['id']
13
+ end
14
+ expect(taxon_ids).to include child.id.to_s
15
+ end
16
+ end
17
+ end
18
+
19
+ describe '#show' do
20
+ context 'by taxon' do
21
+ it 'will fetch the selected child' do
22
+ get :show, taxon_id: taxon.id, id: child.id
23
+ child_id = parse_json(response.body)['data']['id']
24
+ expect(child_id).to eql child.id.to_s
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ describe Spree::Api::V2::CountriesController do
2
+ routes { Spree::Core::Engine.routes }
3
+
4
+ let!(:country) { create :country }
5
+ let(:state) { create :state, country: country }
6
+
7
+ describe '#index' do
8
+ it 'will list all countries' do
9
+ get :index
10
+ expect(JSON.parse(response.body)['data'].length).to eql 1
11
+ end
12
+ end
13
+
14
+ describe '#show' do
15
+ it 'will list the selected country' do
16
+ get :show, id: country.id
17
+ expect(JSON.parse(response.body)['data']['id']).to eql country.id.to_s
18
+ end
19
+
20
+ it 'will the country via a state' do
21
+ get :show, state_id: state.id
22
+ expect(JSON.parse(response.body)['data']['id']).to eql country.id.to_s
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,93 @@
1
+ describe Spree::Api::V2::ImagesController do
2
+ routes { Spree::Core::Engine.routes }
3
+
4
+ let!(:image) { create :image }
5
+
6
+ let(:product) { create :product }
7
+ let(:new_product) { create :product }
8
+
9
+ let(:variant) { create :variant, images: [image] }
10
+ let(:new_variant) { create :variant, images: [create(:image)] }
11
+
12
+ describe '#index' do
13
+ it 'will list the images' do
14
+ get :index
15
+ image_ids = parse_json(response.body)['data'].map do |image|
16
+ image['id']
17
+ end
18
+ expect(image_ids).to include image.id.to_s
19
+ end
20
+
21
+ context 'by product id' do
22
+ it 'will list its images' do
23
+ product.images << image
24
+ get :index, product_id: product.id
25
+ image_ids = parse_json(response.body)['data'].map do |image|
26
+ image['id']
27
+ end
28
+ expect(image_ids).to include image.id.to_s
29
+ end
30
+
31
+ it 'will not list another products images' do
32
+ get :index, product_id: new_product.id
33
+ image_ids = parse_json(response.body)['data'].map do |image|
34
+ image['id']
35
+ end
36
+ expect(image_ids).to_not include image.id.to_s
37
+ end
38
+ end
39
+
40
+ context 'by variant id' do
41
+ it 'will list its images' do
42
+ get :index, variant_id: variant.id
43
+ image_ids = parse_json(response.body)['data'].map do |image|
44
+ image['id']
45
+ end
46
+ expect(image_ids).to include image.id.to_s
47
+ end
48
+
49
+ it 'will not list another variants images' do
50
+ get :index, variant_id: new_variant.id
51
+ image_ids = parse_json(response.body)['data'].map do |image|
52
+ image['id']
53
+ end
54
+ expect(image_ids).to_not include image.id.to_s
55
+ end
56
+ end
57
+ end
58
+
59
+ describe '#show' do
60
+ it 'will show the image' do
61
+ get :show, id: image.id
62
+ image_id = parse_json(response.body)['data']['id']
63
+ expect(image_id).to eql image.id.to_s
64
+ end
65
+
66
+ context 'by product id' do
67
+ it 'will show its image' do
68
+ product.images << image
69
+ get :show, id: image.id, product_id: product.id
70
+ image_id = parse_json(response.body)['data']['id']
71
+ expect(image_id).to eql image.id.to_s
72
+ end
73
+
74
+ it 'will not show another products image' do
75
+ get :show, id: image.id, product_id: new_product.id
76
+ expect(response).to have_http_status 404
77
+ end
78
+ end
79
+
80
+ context 'by variant id' do
81
+ it 'will show its image' do
82
+ get :show, id: image.id, variant_id: variant.id
83
+ image_id = parse_json(response.body)['data']['id']
84
+ expect(image_id).to eql image.id.to_s
85
+ end
86
+
87
+ it 'will not show another products image' do
88
+ get :show, id: image.id, variant_id: new_variant.id
89
+ expect(response).to have_http_status 404
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,86 @@
1
+ describe Spree::Api::V2::LineItemsController do
2
+ routes { Spree::Core::Engine.routes }
3
+
4
+ let(:order) { create :order }
5
+ let(:user) { order.user }
6
+ let(:variant) { create :variant }
7
+
8
+ before { user.generate_spree_api_key! }
9
+
10
+ describe '#create' do
11
+ let(:line_item_params) { { order_id: order.id, variant_id: variant.id, quantity: 1 } }
12
+
13
+ context 'on success' do
14
+ it 'will respond with line item' do
15
+ post :create, token: user.spree_api_key, line_item: line_item_params
16
+ expect(JSON.parse(response.body)['data']['type']).to eql 'spree_line_items'
17
+ end
18
+ end
19
+
20
+ context 'when out of range' do
21
+ before do
22
+ post :create, token: user.spree_api_key,
23
+ line_item: line_item_params.merge(quantity: 123_123_123_123)
24
+ end
25
+
26
+ it 'will respond with quantity too high error' do
27
+ expect(response.body).to be_json_eql <<-JSON
28
+ {
29
+ "errors" : [
30
+ {
31
+ "detail" : #{Spree.t('api.errors.quantity_too_high.detail').gsub("\n", '').to_json},
32
+ "meta" : {},
33
+ "title" : #{Spree.t('api.errors.quantity_too_high.title').titleize.to_json}
34
+ }
35
+ ]
36
+ }
37
+ JSON
38
+ end
39
+ end
40
+
41
+ context 'when record not found' do
42
+ before do
43
+ post :create, token: user.spree_api_key, line_item: line_item_params.merge(order_id: 0)
44
+ end
45
+
46
+ it 'will respond with record not found error' do
47
+ expect(response.body).to be_json_eql <<-JSON
48
+ {
49
+ "errors" : [
50
+ {
51
+ "detail" : #{Spree.t('api.errors.record_not_found.detail').gsub("\n", '').to_json},
52
+ "meta" : {},
53
+ "title" : #{Spree.t('api.errors.record_not_found.title').to_json}
54
+ }
55
+ ]
56
+ }
57
+ JSON
58
+ end
59
+ end
60
+
61
+ context 'when record is invalid' do
62
+ let(:stock_item) { variant.stock_items.first }
63
+
64
+ before do
65
+ quantity = stock_item.count_on_hand + 1
66
+ stock_item.update(backorderable: false)
67
+ post :create, token: user.spree_api_key,
68
+ line_item: line_item_params.merge(quantity: quantity)
69
+ end
70
+
71
+ it 'will respond with product out of stock' do
72
+ expect(response.body).to be_json_eql <<-JSON
73
+ {
74
+ "errors" : [
75
+ {
76
+ "detail" : "#{Spree.t('api.errors.product_out_of_stock.detail').gsub("\n", '')}",
77
+ "meta" : {},
78
+ "title" : #{Spree.t('api.errors.product_out_of_stock.title').titleize.to_json}
79
+ }
80
+ ]
81
+ }
82
+ JSON
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,73 @@
1
+ describe Spree::Api::V2::OptionTypesController do
2
+ routes { Spree::Core::Engine.routes }
3
+
4
+ let!(:option_type) { create :option_type }
5
+ let(:product) { create :product, option_types: [option_type] }
6
+ let(:new_product) { create :product }
7
+
8
+ describe '#index' do
9
+ it 'will list all option types' do
10
+ get :index
11
+ option_type_ids = parse_json(response.body)['data'].map do |option_type|
12
+ option_type['id']
13
+ end
14
+ expect(option_type_ids).to include option_type.id.to_s
15
+ end
16
+
17
+ context 'by product' do
18
+ it 'will list option types' do
19
+ get :index, product_id: product.id
20
+ option_type_ids = parse_json(response.body)['data'].map do |option_type|
21
+ option_type['id']
22
+ end
23
+ expect(option_type_ids).to include option_type.id.to_s
24
+ end
25
+
26
+ it 'will not list option types belonging to a different product' do
27
+ get :index, product_id: new_product.id
28
+ option_type_ids = parse_json(response.body)['data'].map do |option_type|
29
+ option_type['id']
30
+ end
31
+ expect(option_type_ids).to_not include option_type.id.to_s
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '#show' do
37
+ it 'will find selected option_type by id' do
38
+ get :show, id: option_type.id
39
+ option_type_id = parse_json(response.body)['data']['id']
40
+ expect(option_type_id).to eql option_type.id.to_s
41
+ end
42
+
43
+ context 'by product' do
44
+ it 'will list option types' do
45
+ get :show, id: option_type.id, product_id: product.id
46
+ option_type_id = parse_json(response.body)['data']['id']
47
+ expect(option_type_id).to eql option_type.id.to_s
48
+ end
49
+
50
+ it 'will not list option types belonging to a different product' do
51
+ get :show, id: option_type.id, product_id: new_product.id
52
+ expect(response).to have_http_status 404
53
+ end
54
+ end
55
+
56
+ context 'by option value' do
57
+ let(:option_value) { create :option_value, option_type: option_type }
58
+ let(:new_option_value) { create :option_value }
59
+
60
+ it 'will list option types' do
61
+ get :show, option_value_id: option_value.id
62
+ option_type_id = parse_json(response.body)['data']['id']
63
+ expect(option_type_id).to eql option_type.id.to_s
64
+ end
65
+
66
+ it 'will not list option types belonging to a different option value' do
67
+ get :show, option_value_id: new_option_value.id
68
+ option_type_id = parse_json(response.body)['data']['id']
69
+ expect(option_type_id).to_not eql option_type.id.to_s
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,88 @@
1
+ describe Spree::Api::V2::OptionValuesController do
2
+ routes { Spree::Core::Engine.routes }
3
+
4
+ let!(:option_value) { create :option_value }
5
+ let(:new_option_value) { create :option_value }
6
+ let(:variant) { create :variant, option_values: [option_value] }
7
+ let(:new_variant) { create :variant }
8
+
9
+ describe '#index' do
10
+ it 'will list all option values' do
11
+ get :index
12
+ option_value_ids = parse_json(response.body)['data'].map do |option_value|
13
+ option_value['id']
14
+ end
15
+ expect(option_value_ids).to include option_value.id.to_s
16
+ end
17
+
18
+ context 'by option type' do
19
+ it 'will list all option values' do
20
+ get :index, option_type_id: option_value.option_type.id
21
+ option_value_ids = parse_json(response.body)['data'].map do |option_value|
22
+ option_value['id']
23
+ end
24
+ expect(option_value_ids).to include option_value.id.to_s
25
+ end
26
+
27
+ it 'will not list option value belonging to a different option type' do
28
+ get :index, option_type_id: new_option_value.option_type.id
29
+ option_value_ids = parse_json(response.body)['data'].map do |option_value|
30
+ option_value['id']
31
+ end
32
+ expect(option_value_ids).to_not include option_value.id.to_s
33
+ end
34
+ end
35
+
36
+ context 'by variant' do
37
+ it 'will list all option values' do
38
+ get :index, variant_id: variant.id
39
+ option_value_ids = parse_json(response.body)['data'].map do |option_value|
40
+ option_value['id']
41
+ end
42
+ expect(option_value_ids).to include option_value.id.to_s
43
+ end
44
+
45
+ it 'will not list option value belonging to a different variant' do
46
+ get :index, variant_id: new_variant.id
47
+ option_value_ids = parse_json(response.body)['data'].map do |option_value|
48
+ option_value['id']
49
+ end
50
+ expect(option_value_ids).to_not include option_value.id.to_s
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '#show' do
56
+ it 'will find selected option value by id' do
57
+ get :show, id: option_value.id
58
+ option_value_id = parse_json(response.body)['data']['id']
59
+ expect(option_value_id).to eql option_value.id.to_s
60
+ end
61
+
62
+ context 'by option type' do
63
+ it 'will find option value by option type' do
64
+ get :show, option_type_id: option_value.option_type.id, id: option_value.id
65
+ option_value_id = parse_json(response.body)['data']['id']
66
+ expect(option_value_id).to eql option_value.id.to_s
67
+ end
68
+
69
+ it 'will not find option value belonging to a different option type' do
70
+ get :show, option_type_id: new_option_value.option_type.id, id: option_value.id
71
+ expect(response).to have_http_status 404
72
+ end
73
+ end
74
+
75
+ context 'by variant' do
76
+ it 'will find option value by option type' do
77
+ get :show, variant_id: variant.id, id: option_value.id
78
+ option_value_id = parse_json(response.body)['data']['id']
79
+ expect(option_value_id).to eql option_value.id.to_s
80
+ end
81
+
82
+ it 'will not find option value belonging to a different option type' do
83
+ get :show, variant_id: new_variant.id, id: option_value.id
84
+ expect(response).to have_http_status 404
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,15 @@
1
+ describe Spree::Api::V2::OrdersController do
2
+ routes { Spree::Core::Engine.routes }
3
+
4
+ let(:order) { create :order }
5
+ let(:user) { order.user }
6
+
7
+ before { user.generate_spree_api_key! }
8
+
9
+ describe '#show' do
10
+ it 'will respond with the order' do
11
+ get :show, token: user.spree_api_key, id: order.id
12
+ expect(JSON.parse(response.body)['data']['type']).to eql 'spree_orders'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,55 @@
1
+ describe Spree::Api::V2::PricesController do
2
+ routes { Spree::Core::Engine.routes }
3
+
4
+ let!(:price) { create :price }
5
+ let(:new_variant) { create :variant }
6
+
7
+ describe '#index' do
8
+ it 'will list all prices' do
9
+ get :index
10
+ price_ids = parse_json(response.body)['data'].map do |price|
11
+ price['id']
12
+ end
13
+ expect(price_ids).to include price.id.to_s
14
+ end
15
+
16
+ context 'by variant id' do
17
+ it 'will list its prices' do
18
+ get :index, variant_id: price.variant.id
19
+ price_ids = parse_json(response.body)['data'].map do |price|
20
+ price['id']
21
+ end
22
+ expect(price_ids).to include price.id.to_s
23
+ end
24
+
25
+ it 'will not list another variants prices' do
26
+ get :index, variant_id: new_variant.id
27
+ price_ids = parse_json(response.body)['data'].map do |price|
28
+ price['id']
29
+ end
30
+ expect(price_ids).to_not include price.id.to_s
31
+ end
32
+ end
33
+ end
34
+
35
+ describe '#show' do
36
+ it 'will show the price' do
37
+ get :show, id: price.id
38
+ price_id = parse_json(response.body)['data']['id']
39
+ expect(price_id).to eql price.id.to_s
40
+ end
41
+
42
+ context 'by variant id' do
43
+ it 'will show its prices' do
44
+ get :show, id: price.id, variant_id: price.variant.id
45
+ price_id = parse_json(response.body)['data']['id']
46
+ expect(price_id).to eql price.id.to_s
47
+ end
48
+
49
+ it 'will not show another variants price' do
50
+ get :show, id: price.id, variant_id: new_variant.id
51
+ expect(response).to have_http_status 404
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,95 @@
1
+ describe Spree::Api::V2::ProductsController do
2
+ routes { Spree::Core::Engine.routes }
3
+
4
+ let!(:product) { create :product }
5
+ let(:taxon) { create :taxon, products: [product] }
6
+ let(:new_taxon) { create :taxon }
7
+
8
+ describe '#index' do
9
+ it 'will respond with products' do
10
+ get :index
11
+ expect(JSON.parse(response.body)['data'].size).to eql 1
12
+ end
13
+
14
+ context 'by taxon id' do
15
+ it 'will respond with the taxons products' do
16
+ get :index, taxon_id: taxon.id
17
+ product_ids = parse_json(response.body)['data'].map do |products|
18
+ products['id']
19
+ end
20
+ expect(product_ids).to include product.id.to_s
21
+ end
22
+
23
+ it 'will not respond with a product that is not associated to the taxon' do
24
+ get :index, taxon_id: new_taxon.id
25
+ product_ids = parse_json(response.body)['data'].map do |products|
26
+ products['id']
27
+ end
28
+ expect(product_ids).to_not include product.id.to_s
29
+ end
30
+ end
31
+ end
32
+
33
+ describe '#show' do
34
+ it 'will render the selected product' do
35
+ get :show, id: product.id
36
+ expect(parse_json(response.body)['data']['id']).to eql product.id.to_s
37
+ end
38
+
39
+ context 'by taxon id' do
40
+ it 'will respond with the taxons products' do
41
+ get :show, taxon_id: taxon.id, id: product.id
42
+ product_id = parse_json(response.body)['data']['id']
43
+ expect(product_id).to eql product.id.to_s
44
+ end
45
+
46
+ it 'will not respond with a product that is not associated to the taxon' do
47
+ get :show, taxon_id: new_taxon.id, id: product.id
48
+ expect(response).to have_http_status 404
49
+ end
50
+ end
51
+
52
+ context 'by option type' do
53
+ let(:option_type) { create :option_type, products: [product] }
54
+ let(:new_option_type) { create :option_type }
55
+
56
+ it 'will find product' do
57
+ get :show, option_type_id: option_type.id, id: product.id
58
+ product_id = parse_json(response.body)['data']['id']
59
+ expect(product_id).to eql product.id.to_s
60
+ end
61
+
62
+ it 'will not find a product belong to a different option type' do
63
+ get :show, option_type_id: new_option_type.id, id: product.id
64
+ expect(response).to have_http_status 404
65
+ end
66
+ end
67
+
68
+ context 'by variant id' do
69
+ it 'will show its product' do
70
+ get :show, variant_id: product.master.id
71
+ product_id = parse_json(response.body)['data']['id']
72
+ expect(product_id).to eql product.id.to_s
73
+ end
74
+ end
75
+
76
+ context 'by price id' do
77
+ it 'will show its product' do
78
+ get :show, price_id: product.master.prices.first.id
79
+ product_id = parse_json(response.body)['data']['id']
80
+ expect(product_id).to eql product.id.to_s
81
+ end
82
+ end
83
+
84
+ context 'by image id' do
85
+ let(:image) { create :image }
86
+
87
+ it 'will show its product' do
88
+ product.images << image
89
+ get :show, image_id: image.id
90
+ product_id = parse_json(response.body)['data']['id']
91
+ expect(product_id).to eql product.id.to_s
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,42 @@
1
+ describe Spree::Api::V2::StatesController do
2
+ routes { Spree::Core::Engine.routes }
3
+
4
+ let!(:state) { create :state }
5
+
6
+ describe '#index' do
7
+ it 'can list all states' do
8
+ get :index
9
+ expect(JSON.parse(response.body)['data'].length).to eql 1
10
+ end
11
+
12
+ context 'by country id' do
13
+ it 'will list selected states by country' do
14
+ get :index, country_id: state.country.id
15
+ expect(JSON.parse(response.body)['data'].length).to eql 1
16
+ end
17
+
18
+ it 'will not include states belonging to other countries' do
19
+ new_state = create :state
20
+ get :index, country_id: state.country.id
21
+ state_ids = JSON.parse(response.body)['data'].map do |states|
22
+ states['id']
23
+ end
24
+ expect(state_ids).to_not include new_state
25
+ end
26
+ end
27
+ end
28
+
29
+ describe '#show' do
30
+ it 'will find selected state by id' do
31
+ get :show, id: state.id
32
+ state_id = parse_json(response.body)['data']['id']
33
+ expect(state_id).to eql state.id.to_s
34
+ end
35
+
36
+ it 'can find a state by a country' do
37
+ get :show, country_id: state.country.id, id: state.id
38
+ state_id = parse_json(response.body)['data']['id']
39
+ expect(state_id).to eql state.id.to_s
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,31 @@
1
+ describe Spree::Api::V2::TaxonomiesController do
2
+ routes { Spree::Core::Engine.routes }
3
+
4
+ let!(:taxonomy) { create :taxonomy }
5
+
6
+ describe '#index' do
7
+ it 'will list taxonomies' do
8
+ get :index
9
+ taxonomy_ids = parse_json(response.body)['data'].map do |taxonomy|
10
+ taxonomy['id']
11
+ end
12
+ expect(taxonomy_ids).to include taxonomy.id.to_s
13
+ end
14
+ end
15
+
16
+ describe '#show' do
17
+ let(:taxon) { taxonomy.root }
18
+
19
+ it 'will show taxonomy' do
20
+ get :show, id: taxonomy.id
21
+ taxonomy_id = parse_json(response.body)['data']['id']
22
+ expect(taxonomy_id).to eql taxonomy.id.to_s
23
+ end
24
+
25
+ it 'can show taxonomy by taxon_id' do
26
+ get :show, taxon_id: taxon.id
27
+ taxonomy_id = parse_json(response.body)['data']['id']
28
+ expect(taxonomy_id).to eql taxonomy.id.to_s
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,54 @@
1
+ describe Spree::Api::V2::TaxonsController do
2
+ routes { Spree::Core::Engine.routes }
3
+
4
+ let!(:taxon) { create :taxon }
5
+
6
+ describe '#index' do
7
+ it 'will list the taxons' do
8
+ get :index
9
+ taxon_ids = parse_json(response.body)['data'].map do |taxon|
10
+ taxon['id']
11
+ end
12
+ expect(taxon_ids).to include taxon.id.to_s
13
+ end
14
+
15
+ it 'can list the taxons filtered by taxonomy_id' do
16
+ get :index, taxonomy_id: taxon.taxonomy.id
17
+ taxon_ids = parse_json(response.body)['data'].map do |taxon|
18
+ taxon['id']
19
+ end
20
+ expect(taxon_ids).to include taxon.id.to_s
21
+ end
22
+ end
23
+
24
+ describe '#show' do
25
+ it 'will show the selected taxon' do
26
+ get :show, id: taxon.id
27
+ taxon_id = parse_json(response.body)['data']['id']
28
+ expect(taxon_id).to eql taxon.id.to_s
29
+ end
30
+
31
+ context 'by parent' do
32
+ it 'can show a taxons parent' do
33
+ child = create :taxon, parent: taxon
34
+ get :show, taxon_id: child.id
35
+ taxon_id = parse_json(response.body)['data']['id']
36
+ expect(taxon_id).to eql taxon.id.to_s
37
+ end
38
+ end
39
+
40
+ context 'by taxonomy_id' do
41
+ it 'will fetch the selected taxon' do
42
+ get :show, taxonomy_id: taxon.taxonomy.id, id: taxon.id
43
+ taxon_id = parse_json(response.body)['data']['id']
44
+ expect(taxon_id).to eql taxon.id.to_s
45
+ end
46
+
47
+ it 'when taxon does not belong to taxonomy' do
48
+ new_taxonomy = create :taxonomy
49
+ get :show, taxonomy_id: new_taxonomy.id, id: taxon.id
50
+ expect(response).to have_http_status 404
51
+ end
52
+ end
53
+ end
54
+ end