spree_backend 3.0.5 → 3.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -0
- data/Gemfile +6 -0
- data/Rakefile +29 -0
- data/app/assets/javascripts/spree/backend/admin.js +26 -0
- data/app/controllers/spree/admin/resource_controller.rb +4 -2
- data/app/helpers/spree/admin/navigation_helper.rb +10 -1
- data/app/views/spree/admin/images/new.html.erb +1 -1
- data/app/views/spree/admin/payments/_list.html.erb +1 -1
- data/app/views/spree/admin/products/_form.html.erb +1 -1
- data/app/views/spree/admin/shared/_index_table_options.html.erb +1 -11
- data/app/views/spree/admin/shared/sub_menu/_product.html.erb +1 -1
- data/script/rails +9 -0
- data/spec/controllers/spree/admin/base_controller_spec.rb +46 -0
- data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +185 -0
- data/spec/controllers/spree/admin/general_settings_controller_spec.rb +41 -0
- data/spec/controllers/spree/admin/missing_products_controller_spec.rb +18 -0
- data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +42 -0
- data/spec/controllers/spree/admin/orders_controller_spec.rb +247 -0
- data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +49 -0
- data/spec/controllers/spree/admin/payments_controller_spec.rb +97 -0
- data/spec/controllers/spree/admin/products_controller_spec.rb +53 -0
- data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +21 -0
- data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +21 -0
- data/spec/controllers/spree/admin/promotions_controller_spec.rb +44 -0
- data/spec/controllers/spree/admin/refunds_controller_spec.rb +32 -0
- data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +74 -0
- data/spec/controllers/spree/admin/reports_controller_spec.rb +42 -0
- data/spec/controllers/spree/admin/resource_controller_spec.rb +276 -0
- data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +225 -0
- data/spec/controllers/spree/admin/return_items_controller_spec.rb +27 -0
- data/spec/controllers/spree/admin/root_controller_spec.rb +35 -0
- data/spec/controllers/spree/admin/search_controller_spec.rb +56 -0
- data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +14 -0
- data/spec/controllers/spree/admin/stock_items_controller_spec.rb +19 -0
- data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +41 -0
- data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +41 -0
- data/spec/controllers/spree/admin/tax_categories_controller_spec.rb +34 -0
- data/spec/controllers/spree/admin/users_controller_spec.rb +161 -0
- data/spec/controllers/spree/admin/variants_controller_spec.rb +32 -0
- data/spec/features/admin/configuration/analytics_tracker_spec.rb +46 -0
- data/spec/features/admin/configuration/countries_spec.rb +24 -0
- data/spec/features/admin/configuration/general_settings_spec.rb +43 -0
- data/spec/features/admin/configuration/payment_methods_spec.rb +63 -0
- data/spec/features/admin/configuration/roles_spec.rb +47 -0
- data/spec/features/admin/configuration/shipping_methods_spec.rb +62 -0
- data/spec/features/admin/configuration/states_spec.rb +68 -0
- data/spec/features/admin/configuration/stock_locations_spec.rb +48 -0
- data/spec/features/admin/configuration/tax_categories_spec.rb +56 -0
- data/spec/features/admin/configuration/tax_rates_spec.rb +18 -0
- data/spec/features/admin/configuration/zones_spec.rb +39 -0
- data/spec/features/admin/homepage_spec.rb +81 -0
- data/spec/features/admin/locale_spec.rb +31 -0
- data/spec/features/admin/orders/adjustments_promotions_spec.rb +53 -0
- data/spec/features/admin/orders/adjustments_spec.rb +129 -0
- data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +47 -0
- data/spec/features/admin/orders/customer_details_spec.rb +182 -0
- data/spec/features/admin/orders/line_items_spec.rb +51 -0
- data/spec/features/admin/orders/listing_spec.rb +225 -0
- data/spec/features/admin/orders/log_entries_spec.rb +55 -0
- data/spec/features/admin/orders/new_order_spec.rb +161 -0
- data/spec/features/admin/orders/order_details_spec.rb +620 -0
- data/spec/features/admin/orders/payments_spec.rb +229 -0
- data/spec/features/admin/orders/risk_analysis_spec.rb +48 -0
- data/spec/features/admin/orders/shipments_spec.rb +64 -0
- data/spec/features/admin/orders/state_changes_spec.rb +21 -0
- data/spec/features/admin/products/edit/images_spec.rb +86 -0
- data/spec/features/admin/products/edit/products_spec.rb +64 -0
- data/spec/features/admin/products/edit/taxons_spec.rb +41 -0
- data/spec/features/admin/products/edit/variants_spec.rb +56 -0
- data/spec/features/admin/products/option_types_spec.rb +113 -0
- data/spec/features/admin/products/products_spec.rb +394 -0
- data/spec/features/admin/products/properties_spec.rb +140 -0
- data/spec/features/admin/products/prototypes_spec.rb +112 -0
- data/spec/features/admin/products/stock_management_spec.rb +123 -0
- data/spec/features/admin/products/taxonomies_spec.rb +52 -0
- data/spec/features/admin/products/variant_spec.rb +50 -0
- data/spec/features/admin/promotions/adjustments_spec.rb +255 -0
- data/spec/features/admin/promotions/option_value_rule_spec.rb +70 -0
- data/spec/features/admin/promotions/tiered_calculator_spec.rb +70 -0
- data/spec/features/admin/reports_spec.rb +61 -0
- data/spec/features/admin/stock_transfer_spec.rb +75 -0
- data/spec/features/admin/taxons_spec.rb +47 -0
- data/spec/features/admin/users_spec.rb +284 -0
- data/spec/helpers/admin/base_helper_spec.rb +24 -0
- data/spec/helpers/admin/navigation_helper_spec.rb +106 -0
- data/spec/helpers/admin/stock_movements_helper_spec.rb +30 -0
- data/spec/helpers/promotion_rules_helper_spec.rb +12 -0
- data/spec/models/spree/resource_spec.rb +48 -0
- data/spec/spec_helper.rb +133 -0
- data/spec/support/appear_before_matcher.rb +8 -0
- data/spec/support/ror_ringer.jpeg +0 -0
- data/spec/test_views/spree/admin/submodule/posts/edit.html.erb +1 -0
- data/spec/test_views/spree/admin/submodule/posts/new.html.erb +1 -0
- data/spec/test_views/spree/admin/widgets/edit.html.erb +1 -0
- data/spec/test_views/spree/admin/widgets/new.html.erb +1 -0
- data/spree_backend.gemspec +29 -0
- metadata +101 -14
@@ -0,0 +1,255 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Promotion Adjustments", type: :feature, js: true do
|
4
|
+
stub_authorization!
|
5
|
+
|
6
|
+
context "coupon promotions" do
|
7
|
+
before(:each) do
|
8
|
+
visit spree.admin_promotions_path
|
9
|
+
click_on "New Promotion"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should allow an admin to create a flat rate discount coupon promo" do
|
13
|
+
fill_in "Name", with: "Promotion"
|
14
|
+
fill_in "Code", with: "order"
|
15
|
+
click_button "Create"
|
16
|
+
expect(page).to have_content("Editing Promotion")
|
17
|
+
|
18
|
+
select2 "Item total", from: "Add rule of type"
|
19
|
+
within('#rule_fields') { click_button "Add" }
|
20
|
+
|
21
|
+
eventually_fill_in "promotion_promotion_rules_attributes_#{Spree::Promotion.count}_preferred_amount_min", :with => 30
|
22
|
+
eventually_fill_in "promotion_promotion_rules_attributes_#{Spree::Promotion.count}_preferred_amount_max", :with => 60
|
23
|
+
within('#rule_fields') { click_button "Update" }
|
24
|
+
|
25
|
+
select2 "Create whole-order adjustment", from: "Add action of type"
|
26
|
+
within('#action_fields') { click_button "Add" }
|
27
|
+
select2 "Flat Rate", from: "Calculator"
|
28
|
+
within('#actions_container') { click_button "Update" }
|
29
|
+
|
30
|
+
within('.calculator-fields') { fill_in "Amount", with: 5 }
|
31
|
+
within('#actions_container') { click_button "Update" }
|
32
|
+
|
33
|
+
promotion = Spree::Promotion.find_by_name("Promotion")
|
34
|
+
expect(promotion.code).to eq("order")
|
35
|
+
|
36
|
+
first_rule = promotion.rules.first
|
37
|
+
expect(first_rule.class).to eq(Spree::Promotion::Rules::ItemTotal)
|
38
|
+
expect(first_rule.preferred_amount_min).to eq(30)
|
39
|
+
expect(first_rule.preferred_amount_max).to eq(60)
|
40
|
+
|
41
|
+
first_action = promotion.actions.first
|
42
|
+
expect(first_action.class).to eq(Spree::Promotion::Actions::CreateAdjustment)
|
43
|
+
first_action_calculator = first_action.calculator
|
44
|
+
expect(first_action_calculator.class).to eq(Spree::Calculator::FlatRate)
|
45
|
+
expect(first_action_calculator.preferred_amount).to eq(5)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should allow an admin to create a single user coupon promo with flat rate discount" do
|
49
|
+
fill_in "Name", with: "Promotion"
|
50
|
+
fill_in "Usage Limit", with: "1"
|
51
|
+
fill_in "Code", with: "single_use"
|
52
|
+
click_button "Create"
|
53
|
+
expect(page).to have_content("Editing Promotion")
|
54
|
+
|
55
|
+
select2 "Create whole-order adjustment", from: "Add action of type"
|
56
|
+
within('#action_fields') { click_button "Add" }
|
57
|
+
select2 "Flat Rate", from: "Calculator"
|
58
|
+
within('#actions_container') { click_button "Update" }
|
59
|
+
within('#action_fields') { fill_in "Amount", with: "5" }
|
60
|
+
within('#actions_container') { click_button "Update" }
|
61
|
+
|
62
|
+
promotion = Spree::Promotion.find_by_name("Promotion")
|
63
|
+
expect(promotion.usage_limit).to eq(1)
|
64
|
+
expect(promotion.code).to eq("single_use")
|
65
|
+
|
66
|
+
first_action = promotion.actions.first
|
67
|
+
expect(first_action.class).to eq(Spree::Promotion::Actions::CreateAdjustment)
|
68
|
+
first_action_calculator = first_action.calculator
|
69
|
+
expect(first_action_calculator.class).to eq(Spree::Calculator::FlatRate)
|
70
|
+
expect(first_action_calculator.preferred_amount).to eq(5)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should allow an admin to create an automatic promo with flat percent discount" do
|
74
|
+
fill_in "Name", with: "Promotion"
|
75
|
+
click_button "Create"
|
76
|
+
expect(page).to have_content("Editing Promotion")
|
77
|
+
|
78
|
+
select2 "Item total", from: "Add rule of type"
|
79
|
+
within('#rule_fields') { click_button "Add" }
|
80
|
+
|
81
|
+
eventually_fill_in "promotion_promotion_rules_attributes_1_preferred_amount_min", with: 30
|
82
|
+
eventually_fill_in "promotion_promotion_rules_attributes_1_preferred_amount_max", with: 60
|
83
|
+
within('#rule_fields') { click_button "Update" }
|
84
|
+
|
85
|
+
select2 "Create whole-order adjustment", from: "Add action of type"
|
86
|
+
within('#action_fields') { click_button "Add" }
|
87
|
+
select2 "Flat Percent", from: "Calculator"
|
88
|
+
within('#actions_container') { click_button "Update" }
|
89
|
+
within('.calculator-fields') { fill_in "Flat Percent", with: "10" }
|
90
|
+
within('#actions_container') { click_button "Update" }
|
91
|
+
|
92
|
+
promotion = Spree::Promotion.find_by_name("Promotion")
|
93
|
+
expect(promotion.code).to be_blank
|
94
|
+
|
95
|
+
first_rule = promotion.rules.first
|
96
|
+
expect(first_rule.class).to eq(Spree::Promotion::Rules::ItemTotal)
|
97
|
+
expect(first_rule.preferred_amount_min).to eq(30)
|
98
|
+
expect(first_rule.preferred_amount_max).to eq(60)
|
99
|
+
|
100
|
+
first_action = promotion.actions.first
|
101
|
+
expect(first_action.class).to eq(Spree::Promotion::Actions::CreateAdjustment)
|
102
|
+
first_action_calculator = first_action.calculator
|
103
|
+
expect(first_action_calculator.class).to eq(Spree::Calculator::FlatPercentItemTotal)
|
104
|
+
expect(first_action_calculator.preferred_flat_percent).to eq(10)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should allow an admin to create an product promo with percent per item discount" do
|
108
|
+
create(:product, name: "RoR Mug")
|
109
|
+
|
110
|
+
fill_in "Name", with: "Promotion"
|
111
|
+
click_button "Create"
|
112
|
+
expect(page).to have_content("Editing Promotion")
|
113
|
+
|
114
|
+
select2 "Product(s)", from: "Add rule of type"
|
115
|
+
within("#rule_fields") { click_button "Add" }
|
116
|
+
select2_search "RoR Mug", from: "Choose products"
|
117
|
+
within('#rule_fields') { click_button "Update" }
|
118
|
+
|
119
|
+
select2 "Create per-line-item adjustment", from: "Add action of type"
|
120
|
+
within('#action_fields') { click_button "Add" }
|
121
|
+
select2 "Percent Per Item", from: "Calculator"
|
122
|
+
within('#actions_container') { click_button "Update" }
|
123
|
+
within('.calculator-fields') { fill_in "Percent", with: "10" }
|
124
|
+
within('#actions_container') { click_button "Update" }
|
125
|
+
|
126
|
+
promotion = Spree::Promotion.find_by_name("Promotion")
|
127
|
+
expect(promotion.code).to be_blank
|
128
|
+
|
129
|
+
first_rule = promotion.rules.first
|
130
|
+
expect(first_rule.class).to eq(Spree::Promotion::Rules::Product)
|
131
|
+
expect(first_rule.products.map(&:name)).to include("RoR Mug")
|
132
|
+
|
133
|
+
first_action = promotion.actions.first
|
134
|
+
expect(first_action.class).to eq(Spree::Promotion::Actions::CreateItemAdjustments)
|
135
|
+
first_action_calculator = first_action.calculator
|
136
|
+
expect(first_action_calculator.class).to eq(Spree::Calculator::PercentOnLineItem)
|
137
|
+
expect(first_action_calculator.preferred_percent).to eq(10)
|
138
|
+
end
|
139
|
+
|
140
|
+
xit "should allow an admin to create an automatic promotion with free shipping (no code)" do
|
141
|
+
fill_in "Name", with: "Promotion"
|
142
|
+
click_button "Create"
|
143
|
+
expect(page).to have_content("Editing Promotion")
|
144
|
+
|
145
|
+
select2 "Item total", from: "Add rule of type"
|
146
|
+
within('#rule_fields') { click_button "Add" }
|
147
|
+
eventually_fill_in "promotion_promotion_rules_attributes_1_preferred_amount", with: "30"
|
148
|
+
within('#rule_fields') { click_button "Update" }
|
149
|
+
|
150
|
+
select2 "Create whole-order adjustment", from: "Add action of type"
|
151
|
+
within('#action_fields') { click_button "Add" }
|
152
|
+
select2 "Free Shipping", from: "Calculator"
|
153
|
+
within('#actions_container') { click_button "Update" }
|
154
|
+
|
155
|
+
promotion = Spree::Promotion.find_by_name("Promotion")
|
156
|
+
expect(promotion.code).to be_blank
|
157
|
+
|
158
|
+
first_rule = promotion.rules.first
|
159
|
+
expect(first_rule.class).to eq(Spree::Promotion::Rules::ItemTotal)
|
160
|
+
|
161
|
+
first_action = promotion.actions.first
|
162
|
+
expect(first_action.class).to eq(Spree::Promotion::Actions::CreateAdjustment)
|
163
|
+
first_action_calculator = first_action.calculator
|
164
|
+
expect(first_action_calculator.class).to eq(Spree::Calculator::FreeShipping)
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should allow an admin to create an automatic promo requiring a landing page to be visited" do
|
168
|
+
fill_in "Name", with: "Promotion"
|
169
|
+
fill_in "Path", with: "content/cvv"
|
170
|
+
click_button "Create"
|
171
|
+
expect(page).to have_content("Editing Promotion")
|
172
|
+
|
173
|
+
select2 "Create whole-order adjustment", from: "Add action of type"
|
174
|
+
within('#action_fields') { click_button "Add" }
|
175
|
+
select2 "Flat Rate", from: "Calculator"
|
176
|
+
within('#actions_container') { click_button "Update" }
|
177
|
+
within('.calculator-fields') { fill_in "Amount", with: "4" }
|
178
|
+
within('#actions_container') { click_button "Update" }
|
179
|
+
|
180
|
+
promotion = Spree::Promotion.find_by_name("Promotion")
|
181
|
+
expect(promotion.path).to eq("content/cvv")
|
182
|
+
expect(promotion.code).to be_blank
|
183
|
+
expect(promotion.rules).to be_blank
|
184
|
+
|
185
|
+
first_action = promotion.actions.first
|
186
|
+
expect(first_action.class).to eq(Spree::Promotion::Actions::CreateAdjustment)
|
187
|
+
first_action_calculator = first_action.calculator
|
188
|
+
expect(first_action_calculator.class).to eq(Spree::Calculator::FlatRate)
|
189
|
+
expect(first_action_calculator.preferred_amount).to eq(4)
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should allow an admin to create a promotion that adds a 'free' item to the cart" do
|
193
|
+
create(:product, name: "RoR Mug")
|
194
|
+
fill_in "Name", with: "Promotion"
|
195
|
+
fill_in "Code", with: "complex"
|
196
|
+
click_button "Create"
|
197
|
+
expect(page).to have_content("Editing Promotion")
|
198
|
+
|
199
|
+
select2 "Create line items", from: "Add action of type"
|
200
|
+
|
201
|
+
within('#action_fields') { click_button "Add" }
|
202
|
+
|
203
|
+
page.find('.create_line_items .select2-choice').click
|
204
|
+
page.find('.select2-input').set('RoR Mug')
|
205
|
+
page.find('.select2-highlighted').click
|
206
|
+
|
207
|
+
within('#actions_container') { click_button "Update" }
|
208
|
+
|
209
|
+
select2 "Create whole-order adjustment", from: "Add action of type"
|
210
|
+
within('#new_promotion_action_form') { click_button "Add" }
|
211
|
+
select2 "Flat Rate", from: "Calculator"
|
212
|
+
within('#actions_container') { click_button "Update" }
|
213
|
+
within('.create_adjustment .calculator-fields') { fill_in "Amount", with: "40.00" }
|
214
|
+
within('#actions_container') { click_button "Update" }
|
215
|
+
|
216
|
+
promotion = Spree::Promotion.find_by_name("Promotion")
|
217
|
+
expect(promotion.code).to eq("complex")
|
218
|
+
|
219
|
+
first_action = promotion.actions.first
|
220
|
+
expect(first_action.class).to eq(Spree::Promotion::Actions::CreateLineItems)
|
221
|
+
line_item = expect(first_action.promotion_action_line_items).not_to be_empty
|
222
|
+
end
|
223
|
+
|
224
|
+
it "ceasing to be eligible for a promotion with item total rule then becoming eligible again" do
|
225
|
+
fill_in "Name", with: "Promotion"
|
226
|
+
click_button "Create"
|
227
|
+
expect(page).to have_content("Editing Promotion")
|
228
|
+
|
229
|
+
select2 "Item total", from: "Add rule of type"
|
230
|
+
within('#rule_fields') { click_button "Add" }
|
231
|
+
eventually_fill_in "promotion_promotion_rules_attributes_1_preferred_amount_min", with: "50"
|
232
|
+
eventually_fill_in "promotion_promotion_rules_attributes_1_preferred_amount_max", with: "150"
|
233
|
+
within('#rule_fields') { click_button "Update" }
|
234
|
+
|
235
|
+
select2 "Create whole-order adjustment", from: "Add action of type"
|
236
|
+
within('#action_fields') { click_button "Add" }
|
237
|
+
select2 "Flat Rate", from: "Calculator"
|
238
|
+
within('#actions_container') { click_button "Update" }
|
239
|
+
within('.calculator-fields') { fill_in "Amount", with: "5" }
|
240
|
+
within('#actions_container') { click_button "Update" }
|
241
|
+
|
242
|
+
promotion = Spree::Promotion.find_by_name("Promotion")
|
243
|
+
|
244
|
+
first_rule = promotion.rules.first
|
245
|
+
expect(first_rule.class).to eq(Spree::Promotion::Rules::ItemTotal)
|
246
|
+
expect(first_rule.preferred_amount_min).to eq(50)
|
247
|
+
expect(first_rule.preferred_amount_max).to eq(150)
|
248
|
+
|
249
|
+
first_action = promotion.actions.first
|
250
|
+
expect(first_action.class).to eq(Spree::Promotion::Actions::CreateAdjustment)
|
251
|
+
expect(first_action.calculator.class).to eq(Spree::Calculator::FlatRate)
|
252
|
+
expect(first_action.calculator.preferred_amount).to eq(5)
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
feature 'Promotion with option value rule' do
|
4
|
+
stub_authorization!
|
5
|
+
|
6
|
+
given(:variant) { create :variant }
|
7
|
+
given!(:product) { variant.product }
|
8
|
+
given!(:option_value) { variant.option_values.first }
|
9
|
+
|
10
|
+
given(:promotion) { create :promotion }
|
11
|
+
|
12
|
+
background do
|
13
|
+
visit spree.edit_admin_promotion_path(promotion)
|
14
|
+
end
|
15
|
+
|
16
|
+
scenario "adding an option value rule", js: true do
|
17
|
+
select2 "Option Value(s)", from: "Add rule of type"
|
18
|
+
within("#rule_fields") { click_button "Add" }
|
19
|
+
|
20
|
+
within("#rules .promotion-block") do
|
21
|
+
click_button "Add"
|
22
|
+
|
23
|
+
expect(page.body).to have_content("Product")
|
24
|
+
expect(page.body).to have_content("Option Values")
|
25
|
+
end
|
26
|
+
|
27
|
+
within('.promo-rule-option-value') do
|
28
|
+
targetted_select2_search product.name, from: '.js-promo-rule-option-value-product-select'
|
29
|
+
targetted_select2_search(
|
30
|
+
option_value.name,
|
31
|
+
from: '.js-promo-rule-option-value-option-values-select'
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
within('#rules_container') { click_button "Update" }
|
36
|
+
|
37
|
+
first_rule = promotion.rules(true).first
|
38
|
+
expect(first_rule.class).to eq Spree::Promotion::Rules::OptionValue
|
39
|
+
expect(first_rule.preferred_eligible_values).to eq Hash[product.id => [option_value.id]]
|
40
|
+
end
|
41
|
+
|
42
|
+
context "with an existing option value rule" do
|
43
|
+
given(:variant1) { create :variant }
|
44
|
+
given(:variant2) { create :variant }
|
45
|
+
background do
|
46
|
+
rule = Spree::Promotion::Rules::OptionValue.new
|
47
|
+
rule.promotion = promotion
|
48
|
+
rule.preferred_eligible_values = Hash[
|
49
|
+
variant1.product_id => variant1.option_values.pluck(:id),
|
50
|
+
variant2.product_id => variant2.option_values.pluck(:id)
|
51
|
+
]
|
52
|
+
rule.save!
|
53
|
+
|
54
|
+
visit spree.edit_admin_promotion_path(promotion)
|
55
|
+
end
|
56
|
+
|
57
|
+
scenario "deleting a product", js: true do
|
58
|
+
within(".promo-rule-option-value:last-child") do
|
59
|
+
find(".delete").click
|
60
|
+
end
|
61
|
+
|
62
|
+
within('#rule_fields') { click_button "Update" }
|
63
|
+
|
64
|
+
first_rule = promotion.rules(true).first
|
65
|
+
expect(first_rule.preferred_eligible_values).to eq(
|
66
|
+
Hash[variant1.product_id => variant1.option_values.pluck(:id)]
|
67
|
+
)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
feature "Tiered Calculator Promotions" do
|
4
|
+
stub_authorization!
|
5
|
+
|
6
|
+
let(:promotion) { create :promotion }
|
7
|
+
|
8
|
+
background do
|
9
|
+
visit spree.edit_admin_promotion_path(promotion)
|
10
|
+
end
|
11
|
+
|
12
|
+
scenario "adding a tiered percent calculator", js: true do
|
13
|
+
select2 "Create whole-order adjustment", from: "Add action of type"
|
14
|
+
within('#action_fields') { click_button "Add" }
|
15
|
+
|
16
|
+
select2 "Tiered Percent", from: "Calculator"
|
17
|
+
within('#actions_container') { click_button "Update" }
|
18
|
+
|
19
|
+
within("#actions_container .settings") do
|
20
|
+
expect(page.body).to have_content("Base Percent")
|
21
|
+
expect(page.body).to have_content("Tiers")
|
22
|
+
|
23
|
+
click_button "Add"
|
24
|
+
end
|
25
|
+
|
26
|
+
fill_in "Base Percent", with: 5
|
27
|
+
|
28
|
+
within(".tier") do
|
29
|
+
find(".js-base-input").set(100)
|
30
|
+
page.execute_script("$('.js-base-input').change();")
|
31
|
+
find(".js-value-input").set(10)
|
32
|
+
page.execute_script("$('.js-value-input').change();")
|
33
|
+
end
|
34
|
+
within('#actions_container') { click_button "Update" }
|
35
|
+
|
36
|
+
first_action = promotion.actions.first
|
37
|
+
expect(first_action.class).to eq Spree::Promotion::Actions::CreateAdjustment
|
38
|
+
|
39
|
+
first_action_calculator = first_action.calculator
|
40
|
+
expect(first_action_calculator.class).to eq Spree::Calculator::TieredPercent
|
41
|
+
expect(first_action_calculator.preferred_base_percent).to eq 5
|
42
|
+
expect(first_action_calculator.preferred_tiers).to eq Hash[100.0 => 10.0]
|
43
|
+
end
|
44
|
+
|
45
|
+
context "with an existing tiered flat rate calculator" do
|
46
|
+
let(:promotion) { create :promotion, :with_order_adjustment }
|
47
|
+
|
48
|
+
background do
|
49
|
+
action = promotion.actions.first
|
50
|
+
|
51
|
+
action.calculator = Spree::Calculator::TieredFlatRate.new
|
52
|
+
action.calculator.preferred_base_amount = 5
|
53
|
+
action.calculator.preferred_tiers = Hash[100 => 10, 200 => 15, 300 => 20]
|
54
|
+
action.calculator.save!
|
55
|
+
|
56
|
+
visit spree.edit_admin_promotion_path(promotion)
|
57
|
+
end
|
58
|
+
|
59
|
+
scenario "deleting a tier", js: true do
|
60
|
+
within(".tier:nth-child(2)") do
|
61
|
+
click_icon :delete
|
62
|
+
end
|
63
|
+
|
64
|
+
within('#actions_container') { click_button "Update" }
|
65
|
+
|
66
|
+
calculator = promotion.actions.first.calculator
|
67
|
+
expect(calculator.preferred_tiers).to eq Hash[100.0 => 10.0, 300.0 => 20.0]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Reports", :type => :feature do
|
4
|
+
stub_authorization!
|
5
|
+
|
6
|
+
context "visiting the admin reports page" do
|
7
|
+
it "should have the right content" do
|
8
|
+
visit spree.admin_path
|
9
|
+
click_link "Reports"
|
10
|
+
click_link "Sales Total"
|
11
|
+
|
12
|
+
expect(page).to have_content("Sales Totals")
|
13
|
+
expect(page).to have_content("Item Total")
|
14
|
+
expect(page).to have_content("Adjustment Total")
|
15
|
+
expect(page).to have_content("Sales Total")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "searching the admin reports page" do
|
20
|
+
before do
|
21
|
+
order = create(:order)
|
22
|
+
order.update_columns({:adjustment_total => 100})
|
23
|
+
order.completed_at = Time.now
|
24
|
+
order.save!
|
25
|
+
|
26
|
+
order = create(:order)
|
27
|
+
order.update_columns({:adjustment_total => 200})
|
28
|
+
order.completed_at = Time.now
|
29
|
+
order.save!
|
30
|
+
|
31
|
+
#incomplete order
|
32
|
+
order = create(:order)
|
33
|
+
order.update_columns({:adjustment_total => 50})
|
34
|
+
order.save!
|
35
|
+
|
36
|
+
order = create(:order)
|
37
|
+
order.update_columns({:adjustment_total => 200})
|
38
|
+
order.completed_at = 3.years.ago
|
39
|
+
order.created_at = 3.years.ago
|
40
|
+
order.save!
|
41
|
+
|
42
|
+
order = create(:order)
|
43
|
+
order.update_columns({:adjustment_total => 200})
|
44
|
+
order.completed_at = 3.years.from_now
|
45
|
+
order.created_at = 3.years.from_now
|
46
|
+
order.save!
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should allow me to search for reports" do
|
50
|
+
visit spree.admin_path
|
51
|
+
click_link "Reports"
|
52
|
+
click_link "Sales Total"
|
53
|
+
|
54
|
+
fill_in "q_completed_at_gt", :with => 1.week.ago
|
55
|
+
fill_in "q_completed_at_lt", :with => 1.week.from_now
|
56
|
+
click_button "Search"
|
57
|
+
|
58
|
+
expect(page).to have_content("$300.00")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|