workarea-package_products 3.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  4. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.gitignore +15 -0
  7. data/CHANGELOG.md +343 -0
  8. data/CODE_OF_CONDUCT.md +3 -0
  9. data/CONTRIBUTING.md +3 -0
  10. data/Gemfile +16 -0
  11. data/LICENSE +52 -0
  12. data/README.md +40 -0
  13. data/Rakefile +52 -0
  14. data/app/assets/javascripts/workarea/storefront/package_products/modules/family_product_add_to_cart.js +83 -0
  15. data/app/assets/javascripts/workarea/storefront/package_products/templates/family_add_to_cart_checkbox.jst.ejs +1 -0
  16. data/app/assets/stylesheets/workarea/admin/package_products/components/_product_cards.scss +7 -0
  17. data/app/assets/stylesheets/workarea/storefront/package_products/components/_product_detail_packaged_products.scss +11 -0
  18. data/app/controllers/workarea/admin/create_catalog_package_products_controller.rb +150 -0
  19. data/app/controllers/workarea/admin/create_catalog_products_controller.decorator +25 -0
  20. data/app/controllers/workarea/storefront/cart_items_controller.decorator +29 -0
  21. data/app/controllers/workarea/storefront/products_controller.decorator +8 -0
  22. data/app/models/workarea/catalog/product.decorator +44 -0
  23. data/app/models/workarea/search/admin/catalog_product.decorator +20 -0
  24. data/app/models/workarea/search/storefront/package_product.rb +40 -0
  25. data/app/queries/workarea/search/product_entries.decorator +8 -0
  26. data/app/seeds/workarea/package_product_seeds.rb +41 -0
  27. data/app/services/workarea/add_package_to_cart.rb +79 -0
  28. data/app/view_models/workarea/admin/product_view_model.decorator +35 -0
  29. data/app/view_models/workarea/storefront/product_templates/family_view_model.rb +6 -0
  30. data/app/view_models/workarea/storefront/product_templates/package_view_model.rb +33 -0
  31. data/app/view_models/workarea/storefront/product_view_model.decorator +13 -0
  32. data/app/views/workarea/admin/catalog_products/_create_package_button.html.haml +1 -0
  33. data/app/views/workarea/admin/catalog_products/_packaged_products_card.html.haml +26 -0
  34. data/app/views/workarea/admin/create_catalog_package_products/categorization.html.haml +64 -0
  35. data/app/views/workarea/admin/create_catalog_package_products/content.html.haml +54 -0
  36. data/app/views/workarea/admin/create_catalog_package_products/details.html.haml +87 -0
  37. data/app/views/workarea/admin/create_catalog_package_products/images.html.haml +57 -0
  38. data/app/views/workarea/admin/create_catalog_package_products/packaged_products.html.haml +79 -0
  39. data/app/views/workarea/admin/create_catalog_package_products/publish.html.haml +61 -0
  40. data/app/views/workarea/admin/create_catalog_package_products/setup.html.haml +68 -0
  41. data/app/views/workarea/admin/create_catalog_products/select.html.haml +34 -0
  42. data/app/views/workarea/storefront/cart_items/package.html.haml +59 -0
  43. data/app/views/workarea/storefront/products/package_show.html.haml +49 -0
  44. data/app/views/workarea/storefront/products/templates/_family.html.haml +42 -0
  45. data/app/views/workarea/storefront/products/templates/_package.html.haml +36 -0
  46. data/app/workers/workarea/update_package_products.rb +21 -0
  47. data/bin/rails +16 -0
  48. data/config/initializers/appends.rb +31 -0
  49. data/config/initializers/configuration.rb +6 -0
  50. data/config/initializers/seeds.rb +1 -0
  51. data/config/locales/en.yml +45 -0
  52. data/config/routes.rb +30 -0
  53. data/lib/tasks/sample_data.rake +16 -0
  54. data/lib/workarea/package_products.rb +10 -0
  55. data/lib/workarea/package_products/engine.rb +8 -0
  56. data/lib/workarea/package_products/version.rb +5 -0
  57. data/test/dummy/Rakefile +6 -0
  58. data/test/dummy/app/assets/config/manifest.js +4 -0
  59. data/test/dummy/app/assets/images/.keep +0 -0
  60. data/test/dummy/app/assets/javascripts/application.js +13 -0
  61. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  62. data/test/dummy/app/controllers/application_controller.rb +3 -0
  63. data/test/dummy/app/controllers/concerns/.keep +0 -0
  64. data/test/dummy/app/helpers/application_helper.rb +2 -0
  65. data/test/dummy/app/jobs/application_job.rb +2 -0
  66. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  67. data/test/dummy/app/models/concerns/.keep +0 -0
  68. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  69. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  70. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  71. data/test/dummy/bin/bundle +3 -0
  72. data/test/dummy/bin/rails +4 -0
  73. data/test/dummy/bin/rake +4 -0
  74. data/test/dummy/bin/setup +34 -0
  75. data/test/dummy/bin/update +29 -0
  76. data/test/dummy/config.ru +5 -0
  77. data/test/dummy/config/application.rb +18 -0
  78. data/test/dummy/config/boot.rb +5 -0
  79. data/test/dummy/config/cable.yml +9 -0
  80. data/test/dummy/config/environment.rb +5 -0
  81. data/test/dummy/config/environments/development.rb +54 -0
  82. data/test/dummy/config/environments/production.rb +83 -0
  83. data/test/dummy/config/environments/test.rb +43 -0
  84. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  85. data/test/dummy/config/initializers/assets.rb +11 -0
  86. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  87. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  88. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  89. data/test/dummy/config/initializers/inflections.rb +16 -0
  90. data/test/dummy/config/initializers/mime_types.rb +4 -0
  91. data/test/dummy/config/initializers/session_store.rb +3 -0
  92. data/test/dummy/config/initializers/workarea.rb +5 -0
  93. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  94. data/test/dummy/config/locales/en.yml +23 -0
  95. data/test/dummy/config/puma.rb +47 -0
  96. data/test/dummy/config/routes.rb +5 -0
  97. data/test/dummy/config/secrets.yml +22 -0
  98. data/test/dummy/db/seeds.rb +2 -0
  99. data/test/dummy/lib/assets/.keep +0 -0
  100. data/test/dummy/log/.keep +0 -0
  101. data/test/dummy/public/404.html +67 -0
  102. data/test/dummy/public/422.html +67 -0
  103. data/test/dummy/public/500.html +66 -0
  104. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  105. data/test/dummy/public/apple-touch-icon.png +0 -0
  106. data/test/dummy/public/favicon.ico +1 -0
  107. data/test/integration/workarea/admin/create_catalog_package_products_integration_test.rb +139 -0
  108. data/test/integration/workarea/storefront/package_cart_items_integration_test.rb +47 -0
  109. data/test/integration/workarea/storefront/products_integration_test.decorator +19 -0
  110. data/test/models/workarea/catalog/package_product_test.rb +68 -0
  111. data/test/models/workarea/search/storefront/package_product_test.rb +44 -0
  112. data/test/queries/workarea/search/product_entries_test.decorator +15 -0
  113. data/test/services/workarea/add_package_to_cart_test.rb +46 -0
  114. data/test/system/workarea/admin/activity_system_test.decorator +53 -0
  115. data/test/system/workarea/admin/package_product_copy_system_test.rb +27 -0
  116. data/test/system/workarea/admin/package_products_system_test.rb +101 -0
  117. data/test/system/workarea/admin/product_copy_system_test.decorator +28 -0
  118. data/test/system/workarea/admin/products_system_test.decorator +69 -0
  119. data/test/system/workarea/storefront/categories_with_packages_system_test.rb +172 -0
  120. data/test/system/workarea/storefront/family_product_system_test.rb +58 -0
  121. data/test/system/workarea/storefront/package_product_system_test.rb +42 -0
  122. data/test/test_helper.rb +10 -0
  123. data/test/view_models/workarea/admin/package_product_view_model_test.rb +41 -0
  124. data/test/view_models/workarea/storefront/package_product_view_model_test.rb +27 -0
  125. data/test/view_models/workarea/storefront/package_templates/package_view_model_test.rb +34 -0
  126. data/test/workers/workarea/update_package_products_test.rb +27 -0
  127. data/workarea-package_products.gemspec +24 -0
  128. metadata +189 -0
@@ -0,0 +1,69 @@
1
+ module Workarea
2
+ decorate Admin::ProductsSystemTest do
3
+ def test_managing_products
4
+ create_category(name: 'Test Category')
5
+
6
+ visit admin.catalog_products_path
7
+ click_link 'Add New Product'
8
+ click_button t('workarea.admin.create_catalog_products.select.button')
9
+
10
+ fill_in 'product[name]', with: 'Test Product'
11
+ click_button 'save_setup'
12
+
13
+ assert(page.has_content?('Success'))
14
+ assert(page.has_content?('Variants'))
15
+
16
+ fill_in 'variants[][sku]', with: 'TESTSKU'
17
+ fill_in 'variants[][price]', match: :first, with: '20'
18
+ fill_in 'variants[][inventory]', match: :first, with: '99'
19
+ click_button 'save_variants'
20
+
21
+ assert(page.has_content?('Success'))
22
+ assert(page.has_content?('Images'))
23
+
24
+ attach_file 'images[][image]', product_image_file_path
25
+ click_button 'save_images'
26
+
27
+ assert(page.has_content?('Success'))
28
+ assert(page.has_content?('Details'))
29
+ click_button 'save_details'
30
+
31
+ assert(page.has_content?('Success'))
32
+ assert(page.has_content?('Content'))
33
+
34
+ page.execute_script(<<-js
35
+ $("body", $("iframe.wysihtml-sandbox").contents())
36
+ .text("Description")
37
+ js
38
+ )
39
+
40
+ click_button 'save_content'
41
+
42
+ assert(page.has_content?('Success'))
43
+ assert(page.has_content?('Categorization'))
44
+
45
+ find('.select2-selection--multiple').click
46
+ assert(page.has_content?('Test Category'))
47
+ find('.select2-results__option', text: 'Test Category').click
48
+
49
+ click_button 'add_categories'
50
+ assert(page.has_content?('Success'))
51
+ assert(page.has_content?('Test Category'))
52
+ click_link 'Continue to Publish'
53
+
54
+ assert(page.has_content?('Publish'))
55
+ click_button 'publish'
56
+
57
+ click_link 'Attributes'
58
+ fill_in 'product[name]', with: 'Edited Product'
59
+ click_button 'save_product'
60
+
61
+ assert(page.has_content?('Success'))
62
+ assert(page.has_content?('Edited Product'))
63
+ click_link 'Delete'
64
+
65
+ assert_current_path(admin.catalog_products_path)
66
+ assert(page.has_no_content?('Edited Category'))
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,172 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class CategoriesWithPackagesSystemTest < Workarea::SystemTest
6
+ include Storefront::SystemTest
7
+
8
+ setup :set_products
9
+ setup :update_search_settings
10
+
11
+ def set_products
12
+ @products ||= [
13
+ create_product(id: 'PROD1',
14
+ name: 'Integration Product 1',
15
+ filters: { 'Size' => 'Medium', 'Color' => %w(Green Red) },
16
+ created_at: Time.now - 1.hour,
17
+ variants: [{ sku: 'SKU1', regular: 10.to_m }]),
18
+ create_product(id: 'PROD2',
19
+ name: 'Integration Product 2',
20
+ filters: { 'Size' => %w(Medium Small), 'Color' => 'Red' },
21
+ created_at: Time.now - 2.hour,
22
+ variants: [{ sku: 'SKU2', regular: 5.to_m, details: { 'Size' => 'Medium' } },
23
+ { sku: 'SKU4', regular: 5.to_m, details: { 'Size' => 'Large' } }]),
24
+ create_product(id: 'PROD3',
25
+ name: 'Integration Product 3',
26
+ filters: { 'Size' => %w(Medium Small), 'Color' => 'Blue' },
27
+ created_at: Time.now - 3.hour,
28
+ variants: [{ sku: 'SKU3', regular: 5.to_m }]),
29
+ create_product(id: 'PROD4',
30
+ name: 'Integration Package Product 1',
31
+ template: 'package',
32
+ filters: { 'Size' => ['Small', 'Medium', 'Large', 'Extra Large'], 'Color' => %w(Red Green) },
33
+ created_at: Time.now - 4.hour,
34
+ product_ids: %w(PROD1 PROD2 PROD3))
35
+ ]
36
+ end
37
+
38
+ def categorize_products(category)
39
+ category.update_attributes!(
40
+ product_ids: [@products.second.id, @products.first.id, @products.fourth.id]
41
+ )
42
+ end
43
+
44
+ def test_basic_category_setup
45
+ category = create_category
46
+ categorize_products(category)
47
+
48
+ visit storefront.category_path(category)
49
+
50
+ assert(page.has_content?('Integration Product 1'))
51
+ assert(page.has_content?('Integration Product 2'))
52
+ assert(page.has_content?('Integration Package Product 1'))
53
+ assert(page.has_content?('$10.00'))
54
+ assert(page.has_content?('$5.00'))
55
+ assert(page.has_content?('Medium (3)'))
56
+ assert(page.has_content?('Small (2)'))
57
+ end
58
+
59
+ def test_sorting_products
60
+ category = create_category
61
+ categorize_products(category)
62
+
63
+ visit storefront.category_path(category)
64
+
65
+ select('Price, Low to High', from: 'sort_top')
66
+ assert(page.has_ordered_text?(
67
+ 'Integration Product 2',
68
+ 'Integration Package Product',
69
+ 'Integration Product 1'
70
+ ))
71
+
72
+ visit storefront.category_path(category)
73
+ select('Price, High to Low', from: 'sort_top')
74
+ assert(page.has_ordered_text?(
75
+ 'Integration Product 1',
76
+ 'Integration Product 2',
77
+ 'Integration Package Product'
78
+ ))
79
+
80
+ visit storefront.category_path(category)
81
+ select('Newest', from: 'sort_top')
82
+ assert(page.has_ordered_text?(
83
+ 'Integration Product 1',
84
+ 'Integration Product 2',
85
+ 'Integration Package Product'
86
+ ))
87
+
88
+ create_product_by_week(product_id: 'PROD2', orders: 3)
89
+ create_product_by_week(product_id: 'PROD1', orders: 1)
90
+ create_product_by_week(product_id: 'PROD3', orders: 2)
91
+ BulkIndexProducts.perform_by_models(@products)
92
+
93
+ visit storefront.category_path(category)
94
+ select('Top Sellers', from: 'sort_top')
95
+ assert(page.has_ordered_text?(
96
+ 'Integration Product 2',
97
+ 'Integration Package Product',
98
+ 'Integration Product 1'
99
+ ))
100
+ end
101
+
102
+ def test_package_out_of_stock
103
+ category = create_category
104
+ categorize_products(category)
105
+
106
+ create_inventory(id: 'SKU', policy: 'standard', available: 0)
107
+ create_inventory(id: 'SKU1', policy: 'standard', available: 0)
108
+ create_inventory(id: 'SKU2', policy: 'standard', available: 0)
109
+ create_inventory(id: 'SKU3', policy: 'standard', available: 0)
110
+ create_inventory(id: 'SKU4', policy: 'standard', available: 0)
111
+
112
+ visit storefront.category_path(category)
113
+
114
+ assert(page.has_no_content?('Integration Product 1'))
115
+ assert(page.has_no_content?('Integration Product 2'))
116
+ assert(page.has_no_content?('Integration Package Product 1'))
117
+ end
118
+
119
+ def test_filtering_products
120
+ category = create_category
121
+ categorize_products(category)
122
+
123
+ visit storefront.category_path(category)
124
+
125
+ Capybara.match = :first
126
+ click_link '$10.00 - $19.99 (2)'
127
+
128
+ assert(page.has_content?('Integration Product 1'))
129
+ assert(page.has_no_content?('Integration Product 2'))
130
+ assert(page.has_content?('Integration Package Product 1'))
131
+
132
+ click_link '$10.00 - $19.99 (remove)'
133
+
134
+ assert(page.has_content?('Integration Product 1'))
135
+ assert(page.has_content?('Integration Product 2'))
136
+ assert(page.has_content?('Integration Package Product 1'))
137
+
138
+ click_link 'Extra Large (1)'
139
+
140
+ assert(page.has_content?('Integration Package Product 1'))
141
+ assert(page.has_no_content?('Integration Product 1'))
142
+ assert(page.has_no_content?('Integration Product 2'))
143
+
144
+ click_link 'Extra Large (remove)'
145
+
146
+ assert(page.has_content?('Integration Product 1'))
147
+ assert(page.has_content?('Integration Product 2'))
148
+ assert(page.has_content?('Integration Package Product 1'))
149
+ end
150
+
151
+ def test_product_filtering_and_sorting
152
+ category = create_category
153
+ categorize_products(category)
154
+
155
+ visit storefront.category_path(category)
156
+
157
+ Capybara.match = :first
158
+ click_link '$10.00 - $19.99 (2)'
159
+
160
+ assert(page.has_content?('Integration Product 1'))
161
+ assert(page.has_no_content?('Integration Product 2'))
162
+ assert(page.has_content?('Integration Package Product 1'))
163
+
164
+ select('Price, Low to High', from: 'sort_top')
165
+
166
+ assert(page.has_content?('Integration Product 1'))
167
+ assert(page.has_no_content?('Integration Product 2'))
168
+ assert(page.has_content?('Integration Package Product 1'))
169
+ end
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,58 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class FamilyProductSystemTest < Workarea::SystemTest
6
+ include Storefront::SystemTest
7
+
8
+ def test_adding_a_family_product_to_cart
9
+ packaged_products = [
10
+ create_product(
11
+ name: 'Packaged Product 1',
12
+ variants: [
13
+ { sku: 'SKU1', regular: 1.to_m },
14
+ { sku: 'SKU2', regular: 2.to_m }
15
+ ]
16
+ ),
17
+ create_product(
18
+ name: 'Packaged Product 2',
19
+ variants: [
20
+ { sku: 'SKU3', regular: 3.to_m },
21
+ { sku: 'SKU4', regular: 4.to_m }
22
+ ]
23
+ )
24
+ ]
25
+
26
+ family = create_product(
27
+ name: 'Test Product',
28
+ template: 'family',
29
+ product_ids: packaged_products.map(&:id)
30
+ )
31
+
32
+ visit storefront.product_path(family)
33
+
34
+ assert(page.has_content?('Test Product'))
35
+ assert(page.has_content?('Packaged Product 1'))
36
+ assert(page.has_content?('Packaged Product 2'))
37
+ assert(page.has_content?('$1.00'))
38
+ assert(page.has_content?('$3.00'))
39
+
40
+ product_1 = packaged_products.first
41
+ check "family_product_#{product_1.id}"
42
+ select product_1.variants.first.sku, from: "sku_catalog_product_#{product_1.id}"
43
+
44
+ product_2 = packaged_products.second
45
+ check "family_product_#{product_2.id}"
46
+ select product_2.variants.first.sku, from: "sku_catalog_product_#{product_2.id}"
47
+
48
+ click_button 'Add to Cart'
49
+
50
+ dialog = find('.ui-dialog')
51
+
52
+ assert(dialog.has_content?('Success'))
53
+ assert(dialog.has_content?(product_1.name))
54
+ assert(dialog.has_content?(product_2.name))
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class PackageProductSystemTest < Workarea::SystemTest
6
+ include Storefront::SystemTest
7
+
8
+ def test_showing_package_product
9
+ packaged_products = [
10
+ create_product(
11
+ name: 'Packaged Product 1',
12
+ variants: [
13
+ { sku: 'SKU1', regular: 1.to_m },
14
+ { sku: 'SKU2', regular: 2.to_m }
15
+ ]
16
+ ),
17
+ create_product(
18
+ name: 'Packaged Product 2',
19
+ variants: [
20
+ { sku: 'SKU3', regular: 3.to_m },
21
+ { sku: 'SKU4', regular: 4.to_m }
22
+ ]
23
+ )
24
+ ]
25
+
26
+ package = create_product(
27
+ name: 'Test Product',
28
+ template: 'package',
29
+ product_ids: packaged_products.map(&:id)
30
+ )
31
+
32
+ visit storefront.product_path(package)
33
+
34
+ assert(page.has_content?('Test Product'))
35
+ assert(page.has_content?('Packaged Product 1'))
36
+ assert(page.has_content?('Packaged Product 2'))
37
+ assert(page.has_content?('$1.00'))
38
+ assert(page.has_content?('$3.00'))
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,10 @@
1
+ # Configure Rails Environment
2
+ ENV['RAILS_ENV'] = 'test'
3
+
4
+ require File.expand_path('../../test/dummy/config/environment.rb', __FILE__)
5
+ require 'rails/test_help'
6
+ require 'workarea/test_help'
7
+
8
+ # Filter out Minitest backtrace while allowing backtrace from other libraries
9
+ # to be shown.
10
+ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Admin
5
+ # TODO: convert to decorator after base test is converted
6
+ class PackageProductViewModelTest < TestCase
7
+ def test_packaged_products
8
+ create_product(id: 'PROD1', name: 'Test Product 1')
9
+ create_product(id: 'PROD2', name: 'Test Product 2')
10
+ create_product(id: 'PROD3', name: 'Test Product 3')
11
+
12
+ product = create_product(
13
+ name: 'Test Package',
14
+ template: 'package',
15
+ product_ids: %w(PROD2 PROD3 PROD1)
16
+ )
17
+
18
+ view_model = Admin::ProductViewModel.new(product)
19
+ assert_equal(%w(PROD2 PROD3 PROD1), view_model.packaged_products.map(&:id))
20
+ end
21
+
22
+ def test_templates
23
+ product = create_product(
24
+ template: 'package',
25
+ product_ids: ['PROD1']
26
+ )
27
+
28
+ view_model = Admin::ProductViewModel.new(product)
29
+ assert_equal(%w(package family), view_model.templates.map(&:last))
30
+
31
+ product = create_product(template: 'generic')
32
+
33
+ view_model = Admin::ProductViewModel.new(product)
34
+ templates = view_model.templates.map(&:last)
35
+ assert_includes(templates, 'generic')
36
+ refute_includes(templates, 'package')
37
+ refute_includes(templates, 'family')
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class PackageProductViewModelTest < TestCase
6
+ def test_packaged_products
7
+ package_child_1 = create_product(variants: [{ sku: 'SKUC1', regular: 5.00 }])
8
+ package_child_2 = create_product
9
+ package_product = create_product(product_ids: [package_child_1.id, package_child_2.id])
10
+
11
+ view_model = ProductViewModel.new(package_product)
12
+ assert_equal(package_child_1.id, view_model.packaged_products[0].id)
13
+ assert_equal(package_child_2.id, view_model.packaged_products[1].id)
14
+
15
+ create_inventory(id: 'SKUC1', policy: 'standard', available: 0)
16
+
17
+ view_model = ProductViewModel.new(package_product)
18
+ assert_equal(package_child_2.id, view_model.packaged_products[0].id)
19
+ assert_equal(1, view_model.packaged_products.count)
20
+
21
+ bad_packaged_product = create_product(product_ids: [package_child_2.id, 'not_an_id'])
22
+ view_model = ProductViewModel.new(bad_packaged_product)
23
+ assert_equal(1, view_model.packaged_products.count)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ module ProductTemplates
6
+ class PackageViewModelTest < TestCase
7
+ def test_packaged_products
8
+ product_one = create_product(template: 'option_selects')
9
+ product_two = create_product
10
+ package = create_product(product_ids: [product_one.id, product_two.id])
11
+
12
+ view_model = Storefront::ProductTemplates::PackageViewModel.new(package)
13
+
14
+ assert_equal(
15
+ Storefront::ProductTemplates::OptionSelectsViewModel,
16
+ view_model.packaged_products.first.class
17
+ )
18
+
19
+ assert_equal(
20
+ Storefront::ProductViewModel,
21
+ view_model.packaged_products.second.class
22
+ )
23
+
24
+ product_one = create_product(template: 'test')
25
+ product_two = create_product(variants: [])
26
+ package = create_product(product_ids: [product_one.id, product_two.id])
27
+
28
+ view_model = Storefront::ProductTemplates::PackageViewModel.new(package)
29
+ assert_equal(1, view_model.packaged_products.length)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end