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,108 @@
1
+ describe Spree::Api::V2::VariantsController do
2
+ routes { Spree::Core::Engine.routes }
3
+
4
+ let!(:variant) { create :variant }
5
+ let(:new_option_value) { create :option_value }
6
+
7
+ describe '#index' do
8
+ it 'will list all variants' do
9
+ get :index
10
+ variant_ids = parse_json(response.body)['data'].map do |variant|
11
+ variant['id']
12
+ end
13
+ expect(variant_ids).to include variant.id.to_s
14
+ end
15
+
16
+ context 'by product id' do
17
+ let(:new_product) { create :product }
18
+
19
+ it 'will list its variants' do
20
+ get :index, product_id: variant.product.id
21
+ variant_ids = parse_json(response.body)['data'].map do |variant|
22
+ variant['id']
23
+ end
24
+ expect(variant_ids).to include variant.id.to_s
25
+ end
26
+
27
+ it 'will not list another products variants' do
28
+ get :index, product_id: new_product.id
29
+ variant_ids = parse_json(response.body)['data'].map do |variant|
30
+ variant['id']
31
+ end
32
+ expect(variant_ids).to_not include variant.id.to_s
33
+ end
34
+ end
35
+
36
+ context 'by option value' do
37
+ it 'will list its variants' do
38
+ get :index, option_value_id: variant.option_values.first.id
39
+ variant_ids = parse_json(response.body)['data'].map do |variant|
40
+ variant['id']
41
+ end
42
+ expect(variant_ids).to include variant.id.to_s
43
+ end
44
+
45
+ it 'will not list another products variants' do
46
+ get :index, option_value_id: new_option_value.id
47
+ variant_ids = parse_json(response.body)['data'].map do |variant|
48
+ variant['id']
49
+ end
50
+ expect(variant_ids).to_not include variant.id.to_s
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '#show' do
56
+ it 'will show the variant' do
57
+ get :show, id: variant.id
58
+ variant_id = parse_json(response.body)['data']['id']
59
+ expect(variant_id).to eql variant.id.to_s
60
+ end
61
+
62
+ context 'by product id' do
63
+ let(:new_product) { create :product }
64
+
65
+ it 'will show its variant' do
66
+ get :show, id: variant.id, product_id: variant.product.id
67
+ variant_id = parse_json(response.body)['data']['id']
68
+ expect(variant_id).to eql variant.id.to_s
69
+ end
70
+
71
+ it 'will not show another products variant' do
72
+ get :show, id: variant.id, product_id: new_product.id
73
+ expect(response).to have_http_status 404
74
+ end
75
+ end
76
+
77
+ context 'by option_value id' do
78
+ it 'will show its variant' do
79
+ get :show, id: variant.id, option_value_id: variant.option_values.first.id
80
+ variant_id = parse_json(response.body)['data']['id']
81
+ expect(variant_id).to eql variant.id.to_s
82
+ end
83
+
84
+ it 'will not show another option_values variant' do
85
+ get :show, id: variant.id, option_value_id: new_option_value.id
86
+ expect(response).to have_http_status 404
87
+ end
88
+ end
89
+
90
+ context 'by price id' do
91
+ it 'will show its variant' do
92
+ get :show, price_id: variant.prices.first.id
93
+ variant_id = parse_json(response.body)['data']['id']
94
+ expect(variant_id).to eql variant.id.to_s
95
+ end
96
+ end
97
+
98
+ context 'by image id' do
99
+ let(:image) { create :image, viewable: variant }
100
+
101
+ it 'will show its variant' do
102
+ get :show, image_id: image.id
103
+ variant_id = parse_json(response.body)['data']['id']
104
+ expect(variant_id).to eql variant.id.to_s
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,9 @@
1
+ describe Spree::Base do
2
+ it '.paginate' do
3
+ # The pagination is concerned onto abstract models. There's not really a way
4
+ # to be able to ensure that the model is paginated, so instead of ensuring
5
+ # that the result is paginated (tested in the Spree::Api::BaseController),
6
+ # this just makes sure it can respond to the +.paginate+ method.
7
+ expect(described_class).to respond_to(:paginate).with(1).argument
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ describe Spree::Price do
2
+ it { is_expected.to delegate_method(:product).to :variant }
3
+ end
@@ -0,0 +1,35 @@
1
+ describe Spree::AddressSerializer do
2
+ let(:address) { create :address }
3
+ subject { ActiveModel::Serializer::Adapter::JsonApi.new(described_class.new address) }
4
+
5
+ its(:to_json) do
6
+ is_expected.to be_json_eql <<-JSON
7
+ {
8
+ "data" : {
9
+ "attributes" : {
10
+ "address1" : "#{address.address1}",
11
+ "address2" : "#{address.address2}",
12
+ "city" : "#{address.city}",
13
+ "first_name" : "#{address.first_name}",
14
+ "last_name" : "#{address.last_name}",
15
+ "phone" : "#{address.phone}",
16
+ "zipcode" : "#{address.zipcode}"
17
+ },
18
+ "relationships" : {
19
+ "country" : {
20
+ "data" : {
21
+ "type" : "spree_countries"
22
+ }
23
+ },
24
+ "state" : {
25
+ "data" : {
26
+ "type" : "spree_states"
27
+ }
28
+ }
29
+ },
30
+ "type" : "spree_addresses"
31
+ }
32
+ }
33
+ JSON
34
+ end
35
+ end
@@ -0,0 +1,27 @@
1
+ describe Spree::CountrySerializer do
2
+ let(:country) { create :country }
3
+ subject { ActiveModel::Serializer::Adapter::JsonApi.new(described_class.new country) }
4
+
5
+ its(:to_json) do
6
+ is_expected.to be_json_eql <<-JSON
7
+ {
8
+ "data" : {
9
+ "attributes" : {
10
+ "iso" : "#{country.iso}",
11
+ "iso3" : "#{country.iso3}",
12
+ "iso_name" : "#{country.iso_name}",
13
+ "name" : "#{country.name}",
14
+ "numcode" : #{country.numcode},
15
+ "states_required" : #{country.states_required}
16
+ },
17
+ "relationships" : {
18
+ "states" : {
19
+ "data" : []
20
+ }
21
+ },
22
+ "type" : "spree_countries"
23
+ }
24
+ }
25
+ JSON
26
+ end
27
+ end
@@ -0,0 +1,116 @@
1
+ describe Spree::ErrorSerializer do
2
+ let(:address_errors) do
3
+ [
4
+ {
5
+ "ship_address.firstname": ["can't be blank"],
6
+ "ship_address.lastname": ["can't be blank"]
7
+ },
8
+ {
9
+ "bill_address.firstname": ["can't be blank"],
10
+ "bill_address.lastname": ["can't be blank"]
11
+ }
12
+ ]
13
+ end
14
+
15
+ subject { described_class }
16
+
17
+ describe '#as_json' do
18
+ before do
19
+ @store = build(:store, code: nil, mail_from_address: nil)
20
+ @store.save
21
+ end
22
+
23
+ it 'will format json to json api spec' do
24
+ expect(described_class.new(@store).as_json).to be_json_eql <<-JSON
25
+ {
26
+ "errors": [
27
+ {
28
+ "title": "Code",
29
+ "meta": {},
30
+ "pointer": "data/attributes/code",
31
+ "detail": "can't be blank"
32
+ },
33
+ {
34
+ "title": "Mail From Address",
35
+ "meta": {},
36
+ "pointer": "data/attributes/mail_from_address",
37
+ "detail": "can't be blank"
38
+ }
39
+ ]
40
+ }
41
+ JSON
42
+ end
43
+
44
+ it 'will format options as meta' do
45
+ expect(described_class.new(@store, example: :content).as_json).to be_json_eql <<-JSON
46
+ {
47
+ "errors": [
48
+ {
49
+ "detail": "can't be blank",
50
+ "meta": {
51
+ "example": "content"
52
+ },
53
+ "pointer": "data/attributes/code",
54
+ "title": "Code"
55
+ },
56
+ {
57
+ "detail": "can't be blank",
58
+ "meta": {
59
+ "example": "content"
60
+ },
61
+ "pointer": "data/attributes/mail_from_address",
62
+ "title": "Mail From Address"
63
+ }
64
+ ]
65
+ }
66
+ JSON
67
+ end
68
+
69
+ it 'will format a symbol' do
70
+ expect(described_class.new(:invalid_token).as_json).to be_json_eql <<-JSON
71
+ {
72
+ "errors": [
73
+ {
74
+ "detail": "#{Spree.t('api.errors.invalid_token.detail')}",
75
+ "meta": {},
76
+ "title": "#{Spree.t('api.errors.invalid_token.title')}"
77
+ }
78
+ ]
79
+ }
80
+ JSON
81
+ end
82
+
83
+ it 'will format an array of errors' do
84
+ expect(described_class.new(address_errors).as_json).to be_json_eql <<-JSON
85
+ {
86
+ "errors" : [
87
+ {
88
+ "detail" : "can't be blank",
89
+ "meta" : {},
90
+ "pointer" : "data/attributes/ship_address/firstname",
91
+ "title" : "Ship Address Firstname"
92
+ },
93
+ {
94
+ "detail" : "can't be blank",
95
+ "meta" : {},
96
+ "pointer" : "data/attributes/ship_address/lastname",
97
+ "title" : "Ship Address Lastname"
98
+ },
99
+ {
100
+ "detail" : "can't be blank",
101
+ "meta" : {},
102
+ "pointer" : "data/attributes/bill_address/firstname",
103
+ "title" : "Bill Address Firstname"
104
+ },
105
+ {
106
+ "detail" : "can't be blank",
107
+ "meta" : {},
108
+ "pointer" : "data/attributes/bill_address/lastname",
109
+ "title" : "Bill Address Lastname"
110
+ }
111
+ ]
112
+ }
113
+ JSON
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,30 @@
1
+ describe Spree::ImageSerializer do
2
+ let(:image) { create :image }
3
+ subject { ActiveModel::Serializer::Adapter::JsonApi.new(described_class.new image) }
4
+
5
+ its(:to_json) do
6
+ is_expected.to be_json_eql <<-JSON
7
+ {
8
+ "data" : {
9
+ "attributes" : {
10
+ "alt" : null,
11
+ "links" : {
12
+ "large" : "#{image.attachment.url(:large)}",
13
+ "mini" : "#{image.attachment.url(:mini)}",
14
+ "original" : "#{image.attachment.url(:original)}",
15
+ "product" : "#{image.attachment.url(:product)}",
16
+ "small" : "#{image.attachment.url(:small)}"
17
+ },
18
+ "position" : 1
19
+ },
20
+ "relationships" : {
21
+ "viewable" : {
22
+ "data" : null
23
+ }
24
+ },
25
+ "type" : "spree_images"
26
+ }
27
+ }
28
+ JSON
29
+ end
30
+ end
@@ -0,0 +1,40 @@
1
+ describe Spree::LineItemSerializer do
2
+ let(:line_item) { create :line_item }
3
+ subject { ActiveModel::Serializer::Adapter::JsonApi.new(described_class.new line_item) }
4
+
5
+ its(:to_json) do
6
+ is_expected.to be_json_eql <<-JSON
7
+ {
8
+ "data" : {
9
+ "attributes" : {
10
+ "additional_tax_total" : 0,
11
+ "adjustment_total" : 0.0,
12
+ "amount" : "10.0",
13
+ "cost_price" : "17.0",
14
+ "currency" : "USD",
15
+ "display_amount" : "$10.00",
16
+ "display_total" : "$10.00",
17
+ "order_id" : #{line_item.order_id},
18
+ "price" : "10.0",
19
+ "quantity" : 1,
20
+ "total" : "10.0",
21
+ "variant_id" : #{line_item.variant_id}
22
+ },
23
+ "relationships" : {
24
+ "order" : {
25
+ "data" : {
26
+ "type" : "spree_orders"
27
+ }
28
+ },
29
+ "variant" : {
30
+ "data" : {
31
+ "type" : "spree_variants"
32
+ }
33
+ }
34
+ },
35
+ "type" : "spree_line_items"
36
+ }
37
+ }
38
+ JSON
39
+ end
40
+ end
@@ -0,0 +1,27 @@
1
+ describe Spree::OptionTypeSerializer do
2
+ let(:option_type) { create :option_type }
3
+ subject { ActiveModel::Serializer::Adapter::JsonApi.new(described_class.new option_type) }
4
+
5
+ its(:to_json) do
6
+ is_expected.to be_json_eql <<-JSON
7
+ {
8
+ "data" : {
9
+ "attributes" : {
10
+ "name" : "#{option_type.name}",
11
+ "position" : #{option_type.position},
12
+ "presentation" : "#{option_type.presentation}"
13
+ },
14
+ "relationships" : {
15
+ "option_values" : {
16
+ "data" : []
17
+ },
18
+ "products" : {
19
+ "data" : []
20
+ }
21
+ },
22
+ "type" : "spree_option_types"
23
+ }
24
+ }
25
+ JSON
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ describe Spree::OptionValueSerializer do
2
+ let(:option_value) { create :option_value }
3
+ subject { ActiveModel::Serializer::Adapter::JsonApi.new(described_class.new option_value) }
4
+
5
+ its(:to_json) do
6
+ is_expected.to be_json_eql <<-JSON
7
+ {
8
+ "data" : {
9
+ "attributes" : {
10
+ "name" : "#{option_value.name}",
11
+ "position" : #{option_value.position},
12
+ "presentation" : "#{option_value.presentation}"
13
+ },
14
+ "relationships" : {
15
+ "option_type" : {
16
+ "data" : {
17
+ "type" : "spree_option_types"
18
+ }
19
+ },
20
+ "variants" : {
21
+ "data" : []
22
+ }
23
+ },
24
+ "type" : "spree_option_values"
25
+ }
26
+ }
27
+ JSON
28
+ end
29
+ end
@@ -0,0 +1,69 @@
1
+ describe Spree::OrderSerializer do
2
+ let(:order) { create :completed_order_with_totals }
3
+ subject { ActiveModel::Serializer::Adapter::JsonApi.new(described_class.new order) }
4
+
5
+ its(:to_json) do
6
+ is_expected.to be_json_eql <<-JSON
7
+ {
8
+ "data" : {
9
+ "attributes" : {
10
+ "additional_tax_total" : "0.0",
11
+ "adjustment_total" : "0.0",
12
+ "approved_at" : null,
13
+ "canceled_at" : null,
14
+ "channel" : "spree",
15
+ "completed_at" : "#{order.completed_at.iso8601(3)}",
16
+ "confirmation_delivered" : false,
17
+ "considered_risky" : false,
18
+ "currency" : "USD",
19
+ "display_additional_tax_total" : "$0.00",
20
+ "display_adjustment_total" : "$0.00",
21
+ "display_included_tax_total" : "$0.00",
22
+ "display_item_total" : "$10.00",
23
+ "display_promo_total" : "$0.00",
24
+ "display_shipment_total" : "$100.00",
25
+ "display_total" : "$110.00",
26
+ "email" : "#{order.email}",
27
+ "included_tax_total" : "0.0",
28
+ "item_count" : 0,
29
+ "item_total" : "10.0",
30
+ "number" : "#{order.number}",
31
+ "payment_state" : null,
32
+ "payment_total" : "0.0",
33
+ "promo_total" : "0.0",
34
+ "shipment_state" : null,
35
+ "shipment_total" : "100.0",
36
+ "special_instructions" : null,
37
+ "state" : "complete",
38
+ "total" : "110.0"
39
+ },
40
+ "relationships" : {
41
+ "bill_address" : {
42
+ "data" : {
43
+ "type" : "spree_addresses"
44
+ }
45
+ },
46
+ "line_items" : {
47
+ "data" : [
48
+ {
49
+ "type" : "spree_line_items"
50
+ }
51
+ ]
52
+ },
53
+ "ship_address" : {
54
+ "data" : {
55
+ "type" : "spree_addresses"
56
+ }
57
+ },
58
+ "user" : {
59
+ "data" : {
60
+ "type" : "spree_users"
61
+ }
62
+ }
63
+ },
64
+ "type" : "spree_orders"
65
+ }
66
+ }
67
+ JSON
68
+ end
69
+ end
@@ -0,0 +1,28 @@
1
+ describe Spree::PriceSerializer do
2
+ let(:price) { create :price }
3
+ subject { ActiveModel::Serializer::Adapter::JsonApi.new(described_class.new price) }
4
+
5
+ its(:to_json) do
6
+ is_expected.to be_json_eql <<-JSON
7
+ {
8
+ "data" : {
9
+ "attributes" : {
10
+ "amount" : "19.99",
11
+ "currency" : "USD",
12
+ "display_amount" : "$19.99",
13
+ "display_price" : "$19.99",
14
+ "price" : "19.99"
15
+ },
16
+ "relationships" : {
17
+ "variant" : {
18
+ "data" : {
19
+ "type" : "spree_variants"
20
+ }
21
+ }
22
+ },
23
+ "type" : "spree_prices"
24
+ }
25
+ }
26
+ JSON
27
+ end
28
+ end
@@ -0,0 +1,47 @@
1
+ describe Spree::ProductSerializer do
2
+ let(:image) { create :image }
3
+ let(:product) { create :product }
4
+ subject { ActiveModel::Serializer::Adapter::JsonApi.new(described_class.new product) }
5
+
6
+ before { product.images << image }
7
+
8
+ its(:to_json) do
9
+ is_expected.to be_json_eql <<-JSON
10
+ {
11
+ "data" : {
12
+ "attributes" : {
13
+ "description" : #{product.description.to_json},
14
+ "meta_description" : null,
15
+ "meta_keywords" : null,
16
+ "name" : "#{product.name}",
17
+ "slug" : "#{product.slug}"
18
+ },
19
+ "relationships" : {
20
+ "images" : {
21
+ "data" : [
22
+ {
23
+ "type" : "spree_images"
24
+ }
25
+ ]
26
+ },
27
+ "master" : {
28
+ "data" : {
29
+ "type" : "spree_variants"
30
+ }
31
+ },
32
+ "option_types" : {
33
+ "data" : []
34
+ },
35
+ "taxons" : {
36
+ "data" : []
37
+ },
38
+ "variants" : {
39
+ "data" : []
40
+ }
41
+ },
42
+ "type" : "spree_products"
43
+ }
44
+ }
45
+ JSON
46
+ end
47
+ end
@@ -0,0 +1,17 @@
1
+ describe Spree::RoleSerializer do
2
+ let(:role) { create :role }
3
+ subject { ActiveModel::Serializer::Adapter::JsonApi.new(described_class.new role) }
4
+
5
+ its(:to_json) do
6
+ is_expected.to be_json_eql <<-JSON
7
+ {
8
+ "data" : {
9
+ "attributes" : {
10
+ "name" : "#{role.name}"
11
+ },
12
+ "type" : "spree_roles"
13
+ }
14
+ }
15
+ JSON
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ describe Spree::StateSerializer do
2
+ let(:state) { create :state }
3
+ subject { ActiveModel::Serializer::Adapter::JsonApi.new(described_class.new state) }
4
+
5
+ its(:to_json) do
6
+ is_expected.to be_json_eql <<-JSON
7
+ {
8
+ "data" : {
9
+ "attributes" : {
10
+ "abbr" : "#{state.abbr}",
11
+ "name" : "#{state.name}"
12
+ },
13
+ "relationships" : {
14
+ "country" : {
15
+ "data" : {
16
+ "type" : "spree_countries"
17
+ }
18
+ }
19
+ },
20
+ "type" : "spree_states"
21
+ }
22
+ }
23
+ JSON
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ describe Spree::StoreSerializer do
2
+ let(:store) { create :store }
3
+ subject { ActiveModel::Serializer::Adapter::JsonApi.new(described_class.new store) }
4
+
5
+ its(:to_json) do
6
+ is_expected.to be_json_eql <<-JSON
7
+ {
8
+ "data" : {
9
+ "attributes" : {
10
+ "code" : "#{store.code}",
11
+ "default" : #{store.default},
12
+ "default_currency" : #{store.default_currency || 'null'},
13
+ "mail_from_address" : "#{store.mail_from_address}",
14
+ "meta_description" : null,
15
+ "meta_keywords" : null,
16
+ "name" : "#{store.name}",
17
+ "seo_title" : null,
18
+ "url" : "#{store.url}"
19
+ },
20
+ "type" : "spree_stores"
21
+ }
22
+ }
23
+ JSON
24
+ end
25
+ end