workarea-wish_lists 3.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +20 -0
- data/.eslintignore +2 -0
- data/.eslintrc +24 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
- data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.gitignore +15 -0
- data/.scss-lint.yml +188 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +610 -0
- data/CODE_OF_CONDUCT.md +3 -0
- data/CONTRIBUTING.md +3 -0
- data/Gemfile +6 -0
- data/LICENSE +52 -0
- data/README.md +58 -0
- data/Rakefile +53 -0
- data/app/assets/javascripts/workarea/storefront/wish_lists/modules/wish_list_button.js +35 -0
- data/app/assets/javascripts/workarea/storefront/wish_lists/modules/wish_list_public_quantity_fields.js +42 -0
- data/app/assets/javascripts/workarea/storefront/wish_lists/templates/hidden_input.jst.ejs +1 -0
- data/app/assets/stylesheets/workarea/storefront/wish_lists/components/_wish_list_button.scss +6 -0
- data/app/assets/stylesheets/workarea/storefront/wish_lists/components/_wish_lists.scss +24 -0
- data/app/controllers/workarea/admin/users_controller.decorator +20 -0
- data/app/controllers/workarea/storefront/users/wish_lists_controller.rb +128 -0
- data/app/controllers/workarea/storefront/wish_lists_controller.rb +22 -0
- data/app/models/workarea/wish_list.rb +212 -0
- data/app/models/workarea/wish_list/item.rb +76 -0
- data/app/models/workarea/wish_list/pricing.rb +14 -0
- data/app/models/workarea/wish_list/pricing/calculators/totals_calculator.rb +26 -0
- data/app/models/workarea/wish_list/public_search.rb +34 -0
- data/app/models/workarea/wish_list/request.rb +36 -0
- data/app/seeds/workarea/wish_list_seeds.rb +24 -0
- data/app/services/workarea/set_wish_list_details.rb +49 -0
- data/app/services/workarea/wish_list_session.rb +53 -0
- data/app/view_models/workarea/admin/user_view_model.decorator +12 -0
- data/app/view_models/workarea/storefront/user_view_model.decorator +31 -0
- data/app/view_models/workarea/storefront/wish_list_item_view_model.rb +35 -0
- data/app/view_models/workarea/storefront/wish_list_view_model.rb +75 -0
- data/app/views/layouts/workarea/storefront/_wish_lists_link.html.haml +6 -0
- data/app/views/workarea/admin/users/_wish_list_card.html.haml +24 -0
- data/app/views/workarea/admin/users/_wish_list_item_summary.html.haml +8 -0
- data/app/views/workarea/admin/users/wish_list.html.haml +26 -0
- data/app/views/workarea/storefront/carts/_move_to_wish_list.html.haml +4 -0
- data/app/views/workarea/storefront/products/_add_to_wish_list.html.haml +4 -0
- data/app/views/workarea/storefront/style_guides/_wish_lists_product_list_docs.html.haml +158 -0
- data/app/views/workarea/storefront/users/accounts/_wish_list_summary.html.haml +15 -0
- data/app/views/workarea/storefront/users/wish_lists/show.html.haml +125 -0
- data/app/views/workarea/storefront/wish_lists/_wish_lists_link.html.haml +4 -0
- data/app/views/workarea/storefront/wish_lists/index.html.haml +32 -0
- data/app/views/workarea/storefront/wish_lists/show.html.haml +97 -0
- data/app/workers/workarea/mark_wish_list_items_purchased.rb +18 -0
- data/app/workers/workarea/update_wish_list_details.rb +19 -0
- data/bin/rails +18 -0
- data/config/initializers/append_points.rb +46 -0
- data/config/initializers/configuration.rb +10 -0
- data/config/locales/en.yml +60 -0
- data/config/routes.rb +23 -0
- data/lib/workarea/testing/factories/wish_lists.rb +22 -0
- data/lib/workarea/wish_lists.rb +13 -0
- data/lib/workarea/wish_lists/engine.rb +15 -0
- data/lib/workarea/wish_lists/version.rb +5 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/config/manifest.js +4 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +34 -0
- data/test/dummy/bin/update +29 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/config/application.rb +24 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +9 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +54 -0
- data/test/dummy/config/environments/production.rb +86 -0
- data/test/dummy/config/environments/test.rb +43 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/new_framework_defaults.rb +21 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/workarea.rb +5 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/puma.rb +47 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/db/seeds.rb +3 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/test/dummy/public/apple-touch-icon.png +0 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/integration/workarea/storefront/wish_lists_integration_test.rb +211 -0
- data/test/models/workarea/wish_list/public_search_test.rb +82 -0
- data/test/models/workarea/wish_list_test.rb +158 -0
- data/test/services/workarea/set_wish_list_details_test.rb +62 -0
- data/test/services/workarea/wish_list_session_test.rb +47 -0
- data/test/system/workarea/admin/wish_lists_system_test.rb +46 -0
- data/test/system/workarea/storefront/wish_lists_system_test.rb +287 -0
- data/test/test_helper.rb +10 -0
- data/test/view_models/workarea/storefront/user_view_model_test.rb +46 -0
- data/test/view_models/workarea/storefront/wish_list_item_view_model_test.rb +47 -0
- data/test/view_models/workarea/storefront/wish_list_view_model_test.rb +74 -0
- data/test/workers/workarea/mark_wish_list_items_purchased_test.rb +21 -0
- data/workarea-wish_lists.gemspec +21 -0
- metadata +188 -0
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,211 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
class Catalog::Customizations::Foo < Catalog::Customizations
|
5
|
+
customized_fields :foo, :baz
|
6
|
+
validates_presence_of :foo
|
7
|
+
end
|
8
|
+
|
9
|
+
module Storefront
|
10
|
+
class WishListsIntegrationTest < Workarea::IntegrationTest
|
11
|
+
setup :user, :product
|
12
|
+
|
13
|
+
def user
|
14
|
+
@user ||= create_user(email: 'test@workarea.com', password: 'w3bl1nc')
|
15
|
+
end
|
16
|
+
|
17
|
+
def wish_list
|
18
|
+
@wish_list ||= WishList.for_user(user.id)
|
19
|
+
end
|
20
|
+
|
21
|
+
def product
|
22
|
+
@product ||= create_product(
|
23
|
+
name: 'Integration Product',
|
24
|
+
variants: [{ sku: 'SKU1', regular: 10.to_m }]
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def login
|
29
|
+
post storefront.login_path,
|
30
|
+
params: {
|
31
|
+
email: 'test@workarea.com',
|
32
|
+
password: 'w3bl1nc'
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_update
|
37
|
+
login
|
38
|
+
|
39
|
+
patch storefront.update_users_wish_list_path,
|
40
|
+
params: { privacy: 'shared' }
|
41
|
+
|
42
|
+
wish_list.reload
|
43
|
+
assert(wish_list.shared?)
|
44
|
+
|
45
|
+
patch storefront.update_users_wish_list_path,
|
46
|
+
params: { privacy: 'private' }
|
47
|
+
|
48
|
+
wish_list.reload
|
49
|
+
assert(wish_list.private?)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_update_item_quantity
|
53
|
+
login
|
54
|
+
|
55
|
+
post storefront.add_to_users_wish_list_path,
|
56
|
+
params: {
|
57
|
+
product_id: product.id,
|
58
|
+
sku: product.skus.first,
|
59
|
+
quantity: 1
|
60
|
+
}
|
61
|
+
|
62
|
+
assert_equal(1, wish_list.quantity)
|
63
|
+
|
64
|
+
patch storefront.update_item_users_wish_list_path(wish_list.items.first),
|
65
|
+
params: { quantity: 3 }
|
66
|
+
|
67
|
+
wish_list.reload
|
68
|
+
assert_equal(3, wish_list.quantity)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_add_item_with_customizations
|
72
|
+
login
|
73
|
+
|
74
|
+
product.update!(customizations: 'foo')
|
75
|
+
|
76
|
+
assert_difference -> { wish_list.quantity } do
|
77
|
+
post storefront.add_to_users_wish_list_path,
|
78
|
+
params: {
|
79
|
+
product_id: product.id,
|
80
|
+
sku: product.skus.first,
|
81
|
+
quantity: 1,
|
82
|
+
foo: 'bar',
|
83
|
+
baz: 'bat'
|
84
|
+
}
|
85
|
+
wish_list.reload
|
86
|
+
end
|
87
|
+
|
88
|
+
assert_redirected_to(storefront.users_wish_list_path)
|
89
|
+
assert(wish_list.items.last.customizations.present?)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_add_item
|
93
|
+
login
|
94
|
+
|
95
|
+
post storefront.add_to_users_wish_list_path,
|
96
|
+
params: {
|
97
|
+
product_id: product.id,
|
98
|
+
sku: product.skus.first,
|
99
|
+
quantity: 1
|
100
|
+
}
|
101
|
+
|
102
|
+
assert_equal(product.id, wish_list.items.first.product_id)
|
103
|
+
assert_equal(product.skus.first, wish_list.items.first.sku)
|
104
|
+
assert_equal(1, wish_list.items.first.quantity)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_add_item_after_login
|
108
|
+
post storefront.add_to_users_wish_list_path,
|
109
|
+
params: {
|
110
|
+
product_id: product.id,
|
111
|
+
sku: product.skus.first,
|
112
|
+
quantity: 1
|
113
|
+
}
|
114
|
+
|
115
|
+
login
|
116
|
+
get storefront.users_wish_list_path
|
117
|
+
|
118
|
+
assert_equal(1, wish_list.quantity)
|
119
|
+
assert_equal(product.id, wish_list.items.first.product_id)
|
120
|
+
assert_equal(product.skus.first, wish_list.items.first.sku)
|
121
|
+
assert_equal(1, wish_list.items.first.quantity)
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_remove_item
|
125
|
+
login
|
126
|
+
|
127
|
+
post storefront.add_to_users_wish_list_path,
|
128
|
+
params: {
|
129
|
+
product_id: product.id,
|
130
|
+
sku: product.skus.first,
|
131
|
+
quantity: 1
|
132
|
+
}
|
133
|
+
|
134
|
+
delete storefront.remove_from_users_wish_list_path,
|
135
|
+
params: { sku: product.skus.first }
|
136
|
+
|
137
|
+
assert_equal(0, wish_list.quantity)
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_cannot_add_out_of_stock_products_from_wish_list_to_cart
|
141
|
+
inventory = create_inventory(
|
142
|
+
id: 'SKU1',
|
143
|
+
policy: 'standard',
|
144
|
+
available: 1
|
145
|
+
)
|
146
|
+
|
147
|
+
login
|
148
|
+
|
149
|
+
post storefront.add_to_users_wish_list_path,
|
150
|
+
params: {
|
151
|
+
product_id: product.id,
|
152
|
+
sku: product.skus.first,
|
153
|
+
quantity: 1
|
154
|
+
}
|
155
|
+
|
156
|
+
inventory.update_attributes(available: 0)
|
157
|
+
|
158
|
+
assert_equal(product.id, wish_list.items.first.product_id)
|
159
|
+
assert_equal(product.skus.first, wish_list.items.first.sku)
|
160
|
+
assert_equal(1, wish_list.items.first.quantity)
|
161
|
+
|
162
|
+
get storefront.users_wish_list_path
|
163
|
+
assert_select '.grid__cell' do
|
164
|
+
assert_select('p[class="unavailable"]', true)
|
165
|
+
end
|
166
|
+
|
167
|
+
post storefront.cart_items_path,
|
168
|
+
params: {
|
169
|
+
product_id: wish_list.items.first.product_id,
|
170
|
+
sku: wish_list.items.first.sku,
|
171
|
+
quantity: 1
|
172
|
+
}
|
173
|
+
|
174
|
+
assert(response.ok?)
|
175
|
+
|
176
|
+
order = Order.first
|
177
|
+
order.reload
|
178
|
+
assert_equal(0, order.quantity)
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_back_out_of_moving_to_wish_list_as_guest
|
182
|
+
post storefront.cart_items_path, params: {
|
183
|
+
product_id: product.id,
|
184
|
+
sku: product.skus.first,
|
185
|
+
quantity: 1
|
186
|
+
}
|
187
|
+
order = Order.last
|
188
|
+
item = order.items.first
|
189
|
+
|
190
|
+
assert_response(:success)
|
191
|
+
refute_empty(order.items)
|
192
|
+
|
193
|
+
post storefront.from_cart_users_wish_list_path(item_id: item.id)
|
194
|
+
|
195
|
+
assert_redirected_to(storefront.login_path)
|
196
|
+
refute_empty(order.reload.items)
|
197
|
+
assert_equal(item.id.to_s, session[:wish_list_item_id])
|
198
|
+
|
199
|
+
login
|
200
|
+
|
201
|
+
assert_redirected_to(storefront.users_wish_list_path)
|
202
|
+
|
203
|
+
follow_redirect!
|
204
|
+
|
205
|
+
assert_response(:success)
|
206
|
+
refute(session.key?(:wish_list_item_id))
|
207
|
+
assert_empty(order.reload.items)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
class WishList
|
5
|
+
class PublicSearchTest < TestCase
|
6
|
+
setup :wish_list, :nameless_wish_list
|
7
|
+
|
8
|
+
def email
|
9
|
+
'test@workarea.com'
|
10
|
+
end
|
11
|
+
|
12
|
+
def first
|
13
|
+
'Ben'
|
14
|
+
end
|
15
|
+
|
16
|
+
def last
|
17
|
+
'Crouse'
|
18
|
+
end
|
19
|
+
|
20
|
+
def full_name
|
21
|
+
[first, last].join(' ')
|
22
|
+
end
|
23
|
+
|
24
|
+
def other_email
|
25
|
+
'test-again@workarea.com'
|
26
|
+
end
|
27
|
+
|
28
|
+
def another_email
|
29
|
+
'test-other@workarea.com'
|
30
|
+
end
|
31
|
+
|
32
|
+
def wish_list
|
33
|
+
@wish_list ||= create_wish_list(
|
34
|
+
email: email,
|
35
|
+
name: full_name,
|
36
|
+
first_name: first,
|
37
|
+
last_name: last,
|
38
|
+
location: 'Philadelphia PA 19106'
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def nameless_wish_list
|
43
|
+
@nameless_wish_list ||= create_wish_list(
|
44
|
+
email: another_email,
|
45
|
+
name: another_email,
|
46
|
+
first_name: '',
|
47
|
+
last_name: '',
|
48
|
+
location: 'Philadelphia PA 19106'
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_results
|
53
|
+
search = Workarea::WishList::PublicSearch.new(full_name)
|
54
|
+
assert_equal([wish_list], search.results.to_a)
|
55
|
+
|
56
|
+
search = Workarea::WishList::PublicSearch.new(another_email)
|
57
|
+
refute_empty(search.results)
|
58
|
+
|
59
|
+
search = Workarea::WishList::PublicSearch.new('bogus@example.com')
|
60
|
+
assert_empty(search.results)
|
61
|
+
|
62
|
+
search = Workarea::WishList::PublicSearch.new(email)
|
63
|
+
assert_equal([wish_list], search.results.to_a)
|
64
|
+
|
65
|
+
search = Workarea::WishList::PublicSearch.new(email)
|
66
|
+
assert_equal([wish_list], search.results.to_a)
|
67
|
+
|
68
|
+
search = Workarea::WishList::PublicSearch.new(full_name, 'Philadelphia')
|
69
|
+
assert_equal([wish_list], search.results.to_a)
|
70
|
+
|
71
|
+
search = Workarea::WishList::PublicSearch.new('bogus')
|
72
|
+
assert(search.results.to_a.empty?)
|
73
|
+
|
74
|
+
wish_list.update_attributes(privacy: 'private')
|
75
|
+
assert(Workarea::WishList::PublicSearch.new(full_name).results.empty?)
|
76
|
+
|
77
|
+
wish_list.update_attributes(privacy: 'shared')
|
78
|
+
assert(Workarea::WishList::PublicSearch.new(full_name).results.empty?)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
class WishListTest < TestCase
|
5
|
+
def user
|
6
|
+
@user ||= create_user(
|
7
|
+
first_name: 'Foo',
|
8
|
+
last_name: 'Bar',
|
9
|
+
email: 'test@workarea.com',
|
10
|
+
addresses: [{
|
11
|
+
first_name: 'Ben',
|
12
|
+
last_name: 'Crouse',
|
13
|
+
street: '22 S. 3rd St.',
|
14
|
+
street_2: 'Second Floor',
|
15
|
+
city: 'Philadelphia',
|
16
|
+
region: 'PA',
|
17
|
+
postal_code: '19106',
|
18
|
+
country: 'US'
|
19
|
+
}]
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def wish_list
|
24
|
+
@wish_list ||= WishList.new(user_id: user.id)
|
25
|
+
end
|
26
|
+
|
27
|
+
def order
|
28
|
+
@order ||= Workarea::Order.new(email: 'test@workarea.com')
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_creation
|
32
|
+
WishList.destroy_all
|
33
|
+
|
34
|
+
wish_list = WishList.for_user(user.id)
|
35
|
+
|
36
|
+
assert_equal('Foo', wish_list.first_name)
|
37
|
+
assert_equal('Bar', wish_list.last_name)
|
38
|
+
assert_equal('Foo Bar', wish_list.name)
|
39
|
+
assert_equal('Philadelphia PA US 19106', wish_list.location)
|
40
|
+
assert_equal('test@workarea.com', wish_list.email)
|
41
|
+
|
42
|
+
existing_wish_list = WishList.for_user(user.id)
|
43
|
+
assert_equal(wish_list, existing_wish_list)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_find_by_token
|
47
|
+
token = 'kjh23r98b'
|
48
|
+
wish_list.update_attributes(token: token)
|
49
|
+
assert_equal(wish_list, WishList.find_by_token(token))
|
50
|
+
|
51
|
+
assert_raise(Workarea::WishList::InvalidToken) { WishList.find_by_token(nil) }
|
52
|
+
|
53
|
+
wish_list.update_attributes(token: 'kjh23r98b')
|
54
|
+
assert_raise(Workarea::WishList::InvalidToken) { WishList.find_by_token('sdkg12gaweb') }
|
55
|
+
|
56
|
+
token = 'kjh23r98b'
|
57
|
+
wish_list.update_attributes(token: token, privacy: 'private')
|
58
|
+
assert_raise(Workarea::WishList::InvalidToken) { WishList.find_by_token(token) }
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_find_products
|
62
|
+
wish_list.add_item('1234', 'SKU1', 1)
|
63
|
+
assert_equal(['1234'], Workarea::WishList.find_products(user.id))
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_named
|
67
|
+
create_wish_list(name: '')
|
68
|
+
create_wish_list(name: 'Zac Owen')
|
69
|
+
|
70
|
+
assert_equal(1, Workarea::WishList.named.size)
|
71
|
+
create_wish_list(name: 'Foo Bar', email: 'test@test.com')
|
72
|
+
assert_equal(2, Workarea::WishList.named.size)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_public
|
76
|
+
wish_list.update_attributes(privacy: 'public')
|
77
|
+
|
78
|
+
assert(wish_list.public?)
|
79
|
+
refute(wish_list.shared?)
|
80
|
+
refute(wish_list.private?)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_shared
|
84
|
+
wish_list.update_attributes(privacy: 'shared')
|
85
|
+
|
86
|
+
refute(wish_list.public?)
|
87
|
+
assert(wish_list.shared?)
|
88
|
+
refute(wish_list.private?)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_private
|
92
|
+
wish_list.update_attributes(privacy: 'private')
|
93
|
+
|
94
|
+
refute(wish_list.public?)
|
95
|
+
refute(wish_list.shared?)
|
96
|
+
assert(wish_list.private?)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_add_item
|
100
|
+
product_id = '1234'
|
101
|
+
sku = 'SKU'
|
102
|
+
|
103
|
+
wish_list.add_item(product_id, sku, 2)
|
104
|
+
assert_equal(2, wish_list.quantity)
|
105
|
+
assert_equal(product_id, wish_list.items.last.product_id)
|
106
|
+
assert_equal(sku, wish_list.items.last.sku)
|
107
|
+
assert_equal(2, wish_list.items.last.quantity)
|
108
|
+
|
109
|
+
wish_list.add_item(product_id, sku, 2)
|
110
|
+
assert_equal(1, wish_list.items.length)
|
111
|
+
assert_equal(4, wish_list.items.last.quantity)
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_add_item_with_customizations
|
115
|
+
product = create_product(customizations: 'unit')
|
116
|
+
sku = 'SKU'
|
117
|
+
|
118
|
+
assert(wish_list.add_item(product.id, sku, 2, {}, foo: 'bar'))
|
119
|
+
assert_equal(2, wish_list.quantity)
|
120
|
+
assert_equal(product.id, wish_list.items.last.product_id)
|
121
|
+
assert_equal(sku, wish_list.items.last.sku)
|
122
|
+
assert_equal(2, wish_list.items.last.quantity)
|
123
|
+
assert(wish_list.items.last.customizations.present?)
|
124
|
+
assert_equal('bar', wish_list.items.last.customizations[:foo])
|
125
|
+
|
126
|
+
wish_list.add_item(product.id, sku, 2, {}, foo: 'bar')
|
127
|
+
assert_equal(1, wish_list.items.length)
|
128
|
+
assert_equal(4, wish_list.items.last.quantity)
|
129
|
+
assert(wish_list.items.last.customizations.present?)
|
130
|
+
assert_equal('bar', wish_list.items.last.customizations[:foo])
|
131
|
+
|
132
|
+
wish_list.add_item(product.id, sku, 2, {}, foo: 'baz')
|
133
|
+
assert_equal(2, wish_list.items.length)
|
134
|
+
assert(wish_list.items.last.customizations.present?)
|
135
|
+
assert_equal('baz', wish_list.items.last.customizations[:foo])
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_mark_item_purchased
|
139
|
+
order.items.build(product_id: '1234', sku: 'SKU', quantity: 1)
|
140
|
+
|
141
|
+
item = wish_list.items.build(product_id: '1234', sku: 'SKU', quantity: 1)
|
142
|
+
|
143
|
+
wish_list.mark_item_purchased(item.sku, item.quantity)
|
144
|
+
assert(wish_list.unpurchased_items.empty?)
|
145
|
+
assert_includes(wish_list.purchased_items, item)
|
146
|
+
assert_equal(1, wish_list.items.first.received)
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_remove_item
|
150
|
+
sku = 'SKU'
|
151
|
+
item = wish_list.items.build(product_id: '1234', sku: sku, quantity: 2)
|
152
|
+
|
153
|
+
assert_equal(2, wish_list.quantity)
|
154
|
+
wish_list.remove_item(sku)
|
155
|
+
assert_equal(0, wish_list.quantity)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|