spree_api 3.1.14 → 3.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -1
  3. data/app/controllers/spree/api/base_controller.rb +2 -2
  4. data/app/controllers/spree/api/v1/addresses_controller.rb +1 -1
  5. data/app/controllers/spree/api/v1/classifications_controller.rb +1 -1
  6. data/app/controllers/spree/api/v1/images_controller.rb +3 -0
  7. data/app/controllers/spree/api/v1/inventory_units_controller.rb +3 -3
  8. data/app/controllers/spree/api/v1/line_items_controller.rb +3 -0
  9. data/app/controllers/spree/api/v1/option_types_controller.rb +16 -7
  10. data/app/controllers/spree/api/v1/option_values_controller.rb +6 -3
  11. data/app/controllers/spree/api/v1/orders_controller.rb +13 -24
  12. data/app/controllers/spree/api/v1/payments_controller.rb +0 -1
  13. data/app/controllers/spree/api/v1/products_controller.rb +8 -5
  14. data/app/controllers/spree/api/v1/stock_items_controller.rb +1 -1
  15. data/app/controllers/spree/api/v1/stock_locations_controller.rb +1 -1
  16. data/app/controllers/spree/api/v1/tags_controller.rb +28 -0
  17. data/app/controllers/spree/api/v1/taxonomies_controller.rb +7 -4
  18. data/app/controllers/spree/api/v1/taxons_controller.rb +4 -1
  19. data/app/controllers/spree/api/v1/users_controller.rb +5 -3
  20. data/app/controllers/spree/api/v1/zones_controller.rb +3 -3
  21. data/app/helpers/spree/api/api_helpers.rb +4 -1
  22. data/app/models/spree/api_configuration.rb +1 -1
  23. data/app/views/spree/api/errors/invalid_api_key.v1.rabl +1 -1
  24. data/app/views/spree/api/errors/invalid_resource.v1.rabl +1 -1
  25. data/app/views/spree/api/errors/must_specify_api_key.v1.rabl +1 -1
  26. data/app/views/spree/api/errors/not_found.v1.rabl +1 -1
  27. data/app/views/spree/api/errors/unauthorized.v1.rabl +1 -1
  28. data/app/views/spree/api/v1/countries/show.v1.rabl +1 -1
  29. data/app/views/spree/api/v1/line_items/show.v1.rabl +2 -2
  30. data/app/views/spree/api/v1/option_types/show.v1.rabl +1 -1
  31. data/app/views/spree/api/v1/orders/invalid_shipping_method.v1.rabl +1 -1
  32. data/app/views/spree/api/v1/orders/payment.v1.rabl +1 -1
  33. data/app/views/spree/api/v1/orders/show.v1.rabl +9 -9
  34. data/app/views/spree/api/v1/payments/credit_over_limit.v1.rabl +1 -1
  35. data/app/views/spree/api/v1/payments/update_forbidden.v1.rabl +1 -1
  36. data/app/views/spree/api/v1/products/show.v1.rabl +5 -5
  37. data/app/views/spree/api/v1/shipments/cannot_ready_shipment.v1.rabl +1 -1
  38. data/app/views/spree/api/v1/shipments/show.v1.rabl +7 -7
  39. data/app/views/spree/api/v1/shipments/small.v1.rabl +8 -8
  40. data/app/views/spree/api/v1/tags/index.v1.rabl +9 -0
  41. data/app/views/spree/api/v1/taxonomies/jstree.rabl +2 -2
  42. data/app/views/spree/api/v1/taxonomies/nested.v1.rabl +2 -2
  43. data/app/views/spree/api/v1/taxons/jstree.rabl +3 -3
  44. data/app/views/spree/api/v1/taxons/show.v1.rabl +1 -1
  45. data/app/views/spree/api/v1/taxons/taxons.v1.rabl +1 -1
  46. data/app/views/spree/api/v1/users/show.v1.rabl +3 -2
  47. data/app/views/spree/api/v1/variants/big.v1.rabl +3 -3
  48. data/app/views/spree/api/v1/variants/small.v1.rabl +3 -2
  49. data/app/views/spree/api/v1/zones/show.v1.rabl +1 -1
  50. data/config/routes.rb +4 -6
  51. data/db/migrate/20100107141738_add_api_key_to_spree_users.rb +2 -2
  52. data/db/migrate/20120411123334_resize_api_key_field.rb +2 -2
  53. data/db/migrate/20120530054546_rename_api_key_to_spree_api_key.rb +1 -1
  54. data/db/migrate/20131017162334_add_index_to_user_spree_api_key.rb +1 -1
  55. data/lib/spree/api/engine.rb +11 -3
  56. data/lib/spree/api/responders/rabl_template.rb +1 -1
  57. data/lib/spree/api/testing_support/caching.rb +2 -2
  58. data/spec/controllers/spree/api/base_controller_spec.rb +96 -0
  59. data/spec/controllers/spree/api/v1/addresses_controller_spec.rb +56 -0
  60. data/spec/controllers/spree/api/v1/checkouts_controller_spec.rb +363 -0
  61. data/spec/controllers/spree/api/v1/classifications_controller_spec.rb +48 -0
  62. data/spec/controllers/spree/api/v1/countries_controller_spec.rb +48 -0
  63. data/spec/controllers/spree/api/v1/credit_cards_controller_spec.rb +80 -0
  64. data/spec/controllers/spree/api/v1/images_controller_spec.rb +114 -0
  65. data/spec/controllers/spree/api/v1/inventory_units_controller_spec.rb +48 -0
  66. data/spec/controllers/spree/api/v1/line_items_controller_spec.rb +203 -0
  67. data/spec/controllers/spree/api/v1/option_types_controller_spec.rb +122 -0
  68. data/spec/controllers/spree/api/v1/option_values_controller_spec.rb +141 -0
  69. data/spec/controllers/spree/api/v1/orders_controller_spec.rb +735 -0
  70. data/spec/controllers/spree/api/v1/payments_controller_spec.rb +234 -0
  71. data/spec/controllers/spree/api/v1/product_properties_controller_spec.rb +147 -0
  72. data/spec/controllers/spree/api/v1/products_controller_spec.rb +409 -0
  73. data/spec/controllers/spree/api/v1/promotion_application_spec.rb +50 -0
  74. data/spec/controllers/spree/api/v1/promotions_controller_spec.rb +64 -0
  75. data/spec/controllers/spree/api/v1/properties_controller_spec.rb +102 -0
  76. data/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb +161 -0
  77. data/spec/controllers/spree/api/v1/shipments_controller_spec.rb +187 -0
  78. data/spec/controllers/spree/api/v1/states_controller_spec.rb +86 -0
  79. data/spec/controllers/spree/api/v1/stock_items_controller_spec.rb +143 -0
  80. data/spec/controllers/spree/api/v1/stock_locations_controller_spec.rb +113 -0
  81. data/spec/controllers/spree/api/v1/stock_movements_controller_spec.rb +84 -0
  82. data/spec/controllers/spree/api/v1/stores_controller_spec.rb +133 -0
  83. data/spec/controllers/spree/api/v1/tags_controller_spec.rb +102 -0
  84. data/spec/controllers/spree/api/v1/taxonomies_controller_spec.rb +114 -0
  85. data/spec/controllers/spree/api/v1/taxons_controller_spec.rb +177 -0
  86. data/spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb +26 -0
  87. data/spec/controllers/spree/api/v1/users_controller_spec.rb +153 -0
  88. data/spec/controllers/spree/api/v1/variants_controller_spec.rb +205 -0
  89. data/spec/controllers/spree/api/v1/zones_controller_spec.rb +91 -0
  90. data/spec/models/spree/legacy_user_spec.rb +19 -0
  91. data/spec/requests/rabl_cache_spec.rb +32 -0
  92. data/spec/requests/ransackable_attributes_spec.rb +79 -0
  93. data/spec/requests/version_spec.rb +19 -0
  94. data/spec/shared_examples/protect_product_actions.rb +17 -0
  95. data/spec/spec_helper.rb +60 -0
  96. data/spec/support/controller_hacks.rb +40 -0
  97. data/spec/support/database_cleaner.rb +14 -0
  98. data/spec/support/have_attributes_matcher.rb +13 -0
  99. data/spree_api.gemspec +7 -4
  100. metadata +99 -14
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ describe Api::V1::StatesController, type: :controller do
5
+ render_views
6
+
7
+ let!(:state) { create(:state, name: "Victoria") }
8
+ let(:attributes) { [:id, :name, :abbr, :country_id] }
9
+
10
+ before do
11
+ stub_authentication!
12
+ end
13
+
14
+ it "gets all states" do
15
+ api_get :index
16
+ expect(json_response["states"].first).to have_attributes(attributes)
17
+ expect(json_response['states'].first['name']).to eq(state.name)
18
+ end
19
+
20
+ it "gets all the states for a particular country" do
21
+ api_get :index, country_id: state.country.id
22
+ expect(json_response["states"].first).to have_attributes(attributes)
23
+ expect(json_response['states'].first['name']).to eq(state.name)
24
+ end
25
+
26
+ context "pagination" do
27
+ let(:scope) { double('scope') }
28
+
29
+ before do
30
+ expect(scope).to receive_messages(last: state)
31
+ expect(State).to receive_messages(accessible_by: scope)
32
+ expect(scope).to receive_messages(order: scope)
33
+ allow(scope).to receive_message_chain(:ransack, :result, :includes).and_return(scope)
34
+ end
35
+
36
+ it "does not paginate states results when asked not to do so" do
37
+ expect(scope).not_to receive(:page)
38
+ expect(scope).not_to receive(:per)
39
+ api_get :index
40
+ end
41
+
42
+ it "paginates when page parameter is passed through" do
43
+ expect(scope).to receive(:page).with("1").and_return(scope)
44
+ expect(scope).to receive(:per).with(nil).and_return(scope)
45
+ api_get :index, page: 1
46
+ end
47
+
48
+ it "paginates when per_page parameter is passed through" do
49
+ expect(scope).to receive(:page).with(nil).and_return(scope)
50
+ expect(scope).to receive(:per).with("25").and_return(scope)
51
+ api_get :index, per_page: 25
52
+ end
53
+ end
54
+
55
+
56
+ context "with two states" do
57
+ before { create(:state, name: "New South Wales") }
58
+
59
+ it "gets all states for a country" do
60
+ country = create(:country, states_required: true)
61
+ state.country = country
62
+ state.save
63
+
64
+ api_get :index, country_id: country.id
65
+ expect(json_response["states"].first).to have_attributes(attributes)
66
+ expect(json_response["states"].count).to eq(1)
67
+ json_response["states_required"] = true
68
+ end
69
+
70
+ it "can view all states" do
71
+ api_get :index
72
+ expect(json_response["states"].first).to have_attributes(attributes)
73
+ end
74
+
75
+ it 'can query the results through a paramter' do
76
+ api_get :index, q: { name_cont: 'Vic' }
77
+ expect(json_response['states'].first['name']).to eq("Victoria")
78
+ end
79
+ end
80
+
81
+ it "can view a state" do
82
+ api_get :show, id: state.id
83
+ expect(json_response).to have_attributes(attributes)
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,143 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ describe Api::V1::StockItemsController, type: :controller do
5
+ render_views
6
+
7
+ let!(:stock_location) { create(:stock_location_with_items) }
8
+ let!(:stock_item) { stock_location.stock_items.order(:id).first }
9
+ let!(:attributes) { [:id, :count_on_hand, :backorderable,
10
+ :stock_location_id, :variant_id] }
11
+
12
+ before do
13
+ stub_authentication!
14
+ end
15
+
16
+ context "as a normal user" do
17
+ it "cannot list stock items for a stock location" do
18
+ api_get :index, stock_location_id: stock_location.to_param
19
+ expect(response.status).to eq(404)
20
+ end
21
+
22
+ it "cannot see a stock item" do
23
+ api_get :show, stock_location_id: stock_location.to_param, id: stock_item.to_param
24
+ expect(response.status).to eq(404)
25
+ end
26
+
27
+ it "cannot create a stock item" do
28
+ variant = create(:variant)
29
+ params = {
30
+ stock_location_id: stock_location.to_param,
31
+ stock_item: {
32
+ variant_id: variant.id,
33
+ count_on_hand: '20'
34
+ }
35
+ }
36
+
37
+ api_post :create, params
38
+ expect(response.status).to eq(404)
39
+ end
40
+
41
+ it "cannot update a stock item" do
42
+ api_put :update, stock_location_id: stock_location.to_param,
43
+ id: stock_item.to_param
44
+ expect(response.status).to eq(404)
45
+ end
46
+
47
+ it "cannot destroy a stock item" do
48
+ api_delete :destroy, stock_location_id: stock_location.to_param,
49
+ id: stock_item.to_param
50
+ expect(response.status).to eq(404)
51
+ end
52
+ end
53
+
54
+ context "as an admin" do
55
+ sign_in_as_admin!
56
+
57
+ it 'cannot list of stock items' do
58
+ api_get :index, stock_location_id: stock_location.to_param
59
+ expect(json_response['stock_items'].first).to have_attributes(attributes)
60
+ expect(json_response['stock_items'].first['variant']['sku']).to include 'SKU'
61
+ end
62
+
63
+ it 'requires a stock_location_id to be passed as a parameter' do
64
+ api_get :index
65
+ expect(json_response['error']).to match(/stock_location_id parameter must be provided/)
66
+ expect(response.status).to eq(422)
67
+ end
68
+
69
+ it 'can control the page size through a parameter' do
70
+ api_get :index, stock_location_id: stock_location.to_param, per_page: 1
71
+ expect(json_response['count']).to eq(1)
72
+ expect(json_response['current_page']).to eq(1)
73
+ end
74
+
75
+ it 'can query the results through a paramter' do
76
+ stock_item.update_column(:count_on_hand, 30)
77
+ api_get :index, stock_location_id: stock_location.to_param, q: { count_on_hand_eq: '30' }
78
+ expect(json_response['count']).to eq(1)
79
+ expect(json_response['stock_items'].first['count_on_hand']).to eq 30
80
+ end
81
+
82
+ it 'gets a stock item' do
83
+ api_get :show, stock_location_id: stock_location.to_param, id: stock_item.to_param
84
+ expect(json_response).to have_attributes(attributes)
85
+ expect(json_response['count_on_hand']).to eq stock_item.count_on_hand
86
+ end
87
+
88
+ it 'can create a new stock item' do
89
+ variant = create(:variant)
90
+ # Creating a variant also creates stock items.
91
+ # We don't want any to exist (as they would conflict with what we're about to create)
92
+ StockItem.delete_all
93
+ params = {
94
+ stock_location_id: stock_location.to_param,
95
+ stock_item: {
96
+ variant_id: variant.id,
97
+ count_on_hand: '20'
98
+ }
99
+ }
100
+
101
+ api_post :create, params
102
+ expect(response.status).to eq(201)
103
+ expect(json_response).to have_attributes(attributes)
104
+ end
105
+
106
+ it 'can update a stock item to add new inventory' do
107
+ expect(stock_item.count_on_hand).to eq(10)
108
+ params = {
109
+ id: stock_item.to_param,
110
+ stock_item: {
111
+ count_on_hand: 40,
112
+ }
113
+ }
114
+
115
+ api_put :update, params
116
+ expect(response.status).to eq(200)
117
+ expect(json_response['count_on_hand']).to eq 50
118
+ end
119
+
120
+ it 'can set a stock item to modify the current inventory' do
121
+ expect(stock_item.count_on_hand).to eq(10)
122
+
123
+ params = {
124
+ id: stock_item.to_param,
125
+ stock_item: {
126
+ count_on_hand: 40,
127
+ force: true,
128
+ }
129
+ }
130
+
131
+ api_put :update, params
132
+ expect(response.status).to eq(200)
133
+ expect(json_response['count_on_hand']).to eq 40
134
+ end
135
+
136
+ it 'can delete a stock item' do
137
+ api_delete :destroy, id: stock_item.to_param
138
+ expect(response.status).to eq(204)
139
+ expect { Spree::StockItem.find(stock_item.id) }.to raise_error(ActiveRecord::RecordNotFound)
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,113 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ describe Api::V1::StockLocationsController, type: :controller do
5
+ render_views
6
+
7
+ let!(:stock_location) { create(:stock_location) }
8
+ let!(:attributes) { [:id, :name, :address1, :address2, :city, :state_id, :state_name, :country_id, :zipcode, :phone, :active] }
9
+
10
+ before do
11
+ stub_authentication!
12
+ end
13
+
14
+ context "as a user" do
15
+ it "cannot see stock locations" do
16
+ api_get :index
17
+ expect(response.status).to eq(401)
18
+ end
19
+
20
+ it "cannot see a single stock location" do
21
+ api_get :show, id: stock_location.id
22
+ expect(response.status).to eq(404)
23
+ end
24
+
25
+ it "cannot create a new stock location" do
26
+ params = {
27
+ stock_location: {
28
+ name: "North Pole",
29
+ active: true
30
+ }
31
+ }
32
+
33
+ api_post :create, params
34
+ expect(response.status).to eq(401)
35
+ end
36
+
37
+ it "cannot update a stock location" do
38
+ api_put :update, stock_location: { name: "South Pole" }, id: stock_location.to_param
39
+ expect(response.status).to eq(404)
40
+ end
41
+
42
+ it "cannot delete a stock location" do
43
+ api_put :destroy, id: stock_location.to_param
44
+ expect(response.status).to eq(404)
45
+ end
46
+ end
47
+
48
+
49
+ context "as an admin" do
50
+ sign_in_as_admin!
51
+
52
+ it "gets list of stock locations" do
53
+ api_get :index
54
+ expect(json_response['stock_locations'].first).to have_attributes(attributes)
55
+ expect(json_response['stock_locations'].first['country']).not_to be_nil
56
+ expect(json_response['stock_locations'].first['state']).not_to be_nil
57
+ end
58
+
59
+ it 'can control the page size through a parameter' do
60
+ create(:stock_location)
61
+ api_get :index, per_page: 1
62
+ expect(json_response['count']).to eq(1)
63
+ expect(json_response['current_page']).to eq(1)
64
+ expect(json_response['pages']).to eq(2)
65
+ end
66
+
67
+ it 'can query the results through a paramter' do
68
+ expected_result = create(:stock_location, name: 'South America')
69
+ api_get :index, q: { name_cont: 'south' }
70
+ expect(json_response['count']).to eq(1)
71
+ expect(json_response['stock_locations'].first['name']).to eq expected_result.name
72
+ end
73
+
74
+ it "gets a stock location" do
75
+ api_get :show, id: stock_location.to_param
76
+ expect(json_response).to have_attributes(attributes)
77
+ expect(json_response['name']).to eq stock_location.name
78
+ end
79
+
80
+ it "can create a new stock location" do
81
+ params = {
82
+ stock_location: {
83
+ name: "North Pole",
84
+ active: true
85
+ }
86
+ }
87
+
88
+ api_post :create, params
89
+ expect(response.status).to eq(201)
90
+ expect(json_response).to have_attributes(attributes)
91
+ end
92
+
93
+ it "can update a stock location" do
94
+ params = {
95
+ id: stock_location.to_param,
96
+ stock_location: {
97
+ name: "South Pole"
98
+ }
99
+ }
100
+
101
+ api_put :update, params
102
+ expect(response.status).to eq(200)
103
+ expect(json_response['name']).to eq 'South Pole'
104
+ end
105
+
106
+ it "can delete a stock location" do
107
+ api_delete :destroy, id: stock_location.to_param
108
+ expect(response.status).to eq(204)
109
+ expect { stock_location.reload }.to raise_error(ActiveRecord::RecordNotFound)
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ describe Api::V1::StockMovementsController, type: :controller do
5
+ render_views
6
+
7
+ let!(:stock_location) { create(:stock_location_with_items) }
8
+ let!(:stock_item) { stock_location.stock_items.order(:id).first }
9
+ let!(:stock_movement) { create(:stock_movement, stock_item: stock_item) }
10
+ let!(:attributes) { [:id, :quantity, :stock_item_id] }
11
+
12
+ before do
13
+ stub_authentication!
14
+ end
15
+
16
+ context 'as a user' do
17
+ it 'cannot see a list of stock movements' do
18
+ api_get :index, stock_location_id: stock_location.to_param
19
+ expect(response.status).to eq(404)
20
+ end
21
+
22
+ it 'cannot see a stock movement' do
23
+ api_get :show, stock_location_id: stock_location.to_param, id: stock_movement.id
24
+ expect(response.status).to eq(404)
25
+ end
26
+
27
+ it 'cannot create a stock movement' do
28
+ params = {
29
+ stock_location_id: stock_location.to_param,
30
+ stock_movement: {
31
+ stock_item_id: stock_item.to_param
32
+ }
33
+ }
34
+
35
+ api_post :create, params
36
+ expect(response.status).to eq(404)
37
+ end
38
+ end
39
+
40
+ context 'as an admin' do
41
+ sign_in_as_admin!
42
+
43
+ it 'gets list of stock movements' do
44
+ api_get :index, stock_location_id: stock_location.to_param
45
+ expect(json_response['stock_movements'].first).to have_attributes(attributes)
46
+ expect(json_response['stock_movements'].first['stock_item']['count_on_hand']).to eq 11
47
+ end
48
+
49
+ it 'can control the page size through a parameter' do
50
+ create(:stock_movement, stock_item: stock_item)
51
+ api_get :index, stock_location_id: stock_location.to_param, per_page: 1
52
+ expect(json_response['count']).to eq(1)
53
+ expect(json_response['current_page']).to eq(1)
54
+ expect(json_response['pages']).to eq(2)
55
+ end
56
+
57
+ it 'can query the results through a paramter' do
58
+ expected_result = create(:stock_movement, :received, quantity: 10, stock_item: stock_item)
59
+ api_get :index, stock_location_id: stock_location.to_param, q: { quantity_eq: '10' }
60
+ expect(json_response['count']).to eq(1)
61
+ end
62
+
63
+ it 'gets a stock movement' do
64
+ api_get :show, stock_location_id: stock_location.to_param, id: stock_movement.to_param
65
+ expect(json_response).to have_attributes(attributes)
66
+ expect(json_response['stock_item_id']).to eq stock_movement.stock_item_id
67
+ end
68
+
69
+ it 'can create a new stock movement' do
70
+ params = {
71
+ stock_location_id: stock_location.to_param,
72
+ stock_movement: {
73
+ stock_item_id: stock_item.to_param
74
+ }
75
+ }
76
+
77
+ api_post :create, params
78
+ expect(response.status).to eq(201)
79
+ expect(json_response).to have_attributes(attributes)
80
+ end
81
+ end
82
+ end
83
+ end
84
+
@@ -0,0 +1,133 @@
1
+ require "spec_helper"
2
+
3
+ module Spree
4
+ describe Api::V1::StoresController, type: :controller do
5
+ render_views
6
+
7
+ let!(:store) do
8
+ create(:store, name: "My Spree Store", url: "spreestore.example.com")
9
+ end
10
+
11
+ before do
12
+ stub_authentication!
13
+ end
14
+
15
+ context "as an admin" do
16
+ sign_in_as_admin!
17
+
18
+ let!(:non_default_store) do
19
+ create(:store,
20
+ name: "Extra Store",
21
+ url: "spreestore-5.example.com",
22
+ default: false
23
+ )
24
+ end
25
+
26
+ it "I can list the available stores" do
27
+ api_get :index
28
+ expect(json_response["stores"]).to eq([
29
+ {
30
+ "id" => store.id,
31
+ "name" => "My Spree Store",
32
+ "url" => "spreestore.example.com",
33
+ "meta_description" => nil,
34
+ "meta_keywords" => nil,
35
+ "seo_title" => nil,
36
+ "mail_from_address" => "spree@example.org",
37
+ "default_currency" => nil,
38
+ "code" => store.code,
39
+ "default" => true
40
+ },
41
+ {
42
+ "id" => non_default_store.id,
43
+ "name" => "Extra Store",
44
+ "url" => "spreestore-5.example.com",
45
+ "meta_description" => nil,
46
+ "meta_keywords" => nil,
47
+ "seo_title" => nil,
48
+ "mail_from_address" => "spree@example.org",
49
+ "default_currency" => nil,
50
+ "code" => non_default_store.code,
51
+ "default" => false
52
+ }
53
+ ])
54
+ end
55
+
56
+ it "I can get the store details" do
57
+ api_get :show, id: store.id
58
+ expect(json_response).to eq(
59
+ "id" => store.id,
60
+ "name" => "My Spree Store",
61
+ "url" => "spreestore.example.com",
62
+ "meta_description" => nil,
63
+ "meta_keywords" => nil,
64
+ "seo_title" => nil,
65
+ "mail_from_address" => "spree@example.org",
66
+ "default_currency" => nil,
67
+ "code" => store.code,
68
+ "default" => true
69
+ )
70
+ end
71
+
72
+ it "I can create a new store" do
73
+ store_hash = {
74
+ code: "spree123",
75
+ name: "Hack0rz",
76
+ url: "spree123.example.com",
77
+ mail_from_address: "me@example.com"
78
+ }
79
+ api_post :create, store: store_hash
80
+ expect(response.status).to eq(201)
81
+ end
82
+
83
+ it "I can update an existing store" do
84
+ store_hash = {
85
+ url: "spree123.example.com",
86
+ mail_from_address: "me@example.com"
87
+ }
88
+ api_put :update, id: store.id, store: store_hash
89
+ expect(response.status).to eq(200)
90
+ expect(store.reload.url).to eql "spree123.example.com"
91
+ expect(store.reload.mail_from_address).to eql "me@example.com"
92
+ end
93
+
94
+ context "deleting a store" do
95
+ it "will fail if it's the default Store" do
96
+ api_delete :destroy, id: store.id
97
+ expect(response.status).to eq(422)
98
+ expect(json_response["errors"]["base"]).to eql(
99
+ ["Cannot destroy the default Store."]
100
+ )
101
+ end
102
+
103
+ it "will destroy the store" do
104
+ api_delete :destroy, id: non_default_store.id
105
+ expect(response.status).to eq(204)
106
+ end
107
+ end
108
+ end
109
+
110
+ context "as an user" do
111
+
112
+ it "I cannot list all the stores" do
113
+ api_get :index
114
+ expect(response.status).to eq(401)
115
+ end
116
+
117
+ it "I cannot get the store details" do
118
+ api_get :show, id: store.id
119
+ expect(response.status).to eq(401)
120
+ end
121
+
122
+ it "I cannot create a new store" do
123
+ api_post :create, store: {}
124
+ expect(response.status).to eq(401)
125
+ end
126
+
127
+ it "I cannot update an existing store" do
128
+ api_put :update, id: store.id, store: {}
129
+ expect(response.status).to eq(401)
130
+ end
131
+ end
132
+ end
133
+ end