workarea-testing 3.4.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +52 -0
  3. data/README.md +19 -0
  4. data/app/assets/javascripts/workarea/admin/spec_helper.js +1 -0
  5. data/app/assets/javascripts/workarea/core/feature_test_helper.js +15 -0
  6. data/app/assets/javascripts/workarea/core/spec_helper.js +45 -0
  7. data/app/assets/javascripts/workarea/storefront/spec_helper.js +2 -0
  8. data/app/assets/stylesheets/workarea/admin/_feature_test_helper.scss +16 -0
  9. data/app/assets/stylesheets/workarea/core/_feature_test_helper.scss +8 -0
  10. data/lib/workarea/admin/integration_test.rb +15 -0
  11. data/lib/workarea/core/discount_condition_tests.rb +100 -0
  12. data/lib/workarea/core/featured_products_test.rb +30 -0
  13. data/lib/workarea/core/navigable_test.rb +68 -0
  14. data/lib/workarea/generator_test.rb +5 -0
  15. data/lib/workarea/integration_test.rb +45 -0
  16. data/lib/workarea/performance_test.rb +135 -0
  17. data/lib/workarea/storefront/breakpoint_helpers.rb +27 -0
  18. data/lib/workarea/storefront/catalog_customization_test_class.rb +28 -0
  19. data/lib/workarea/storefront/integration_test.rb +82 -0
  20. data/lib/workarea/storefront/pagination_view_model_test.rb +56 -0
  21. data/lib/workarea/storefront/product_browsing_view_model_test.rb +38 -0
  22. data/lib/workarea/storefront/system_test.rb +142 -0
  23. data/lib/workarea/system_test.rb +161 -0
  24. data/lib/workarea/test_case.rb +197 -0
  25. data/lib/workarea/test_help.rb +67 -0
  26. data/lib/workarea/testing/cassette_persister.rb +40 -0
  27. data/lib/workarea/testing/custom_capybara_matchers.rb +18 -0
  28. data/lib/workarea/testing/decoration_reporter.rb +37 -0
  29. data/lib/workarea/testing/deferred_garbage_collection.rb +21 -0
  30. data/lib/workarea/testing/elasticsearch_response.json +1 -0
  31. data/lib/workarea/testing/engine.rb +6 -0
  32. data/lib/workarea/testing/example_document.pdf +0 -0
  33. data/lib/workarea/testing/factories/bulk_action.rb +17 -0
  34. data/lib/workarea/testing/factories/catalog.rb +66 -0
  35. data/lib/workarea/testing/factories/comment.rb +12 -0
  36. data/lib/workarea/testing/factories/content.rb +38 -0
  37. data/lib/workarea/testing/factories/data_file.rb +21 -0
  38. data/lib/workarea/testing/factories/fulfillment.rb +21 -0
  39. data/lib/workarea/testing/factories/insights.rb +32 -0
  40. data/lib/workarea/testing/factories/metrics.rb +25 -0
  41. data/lib/workarea/testing/factories/navigation.rb +30 -0
  42. data/lib/workarea/testing/factories/order.rb +77 -0
  43. data/lib/workarea/testing/factories/payment.rb +37 -0
  44. data/lib/workarea/testing/factories/performance/catalog.rb +92 -0
  45. data/lib/workarea/testing/factories/pricing.rb +59 -0
  46. data/lib/workarea/testing/factories/recommendation.rb +17 -0
  47. data/lib/workarea/testing/factories/search.rb +72 -0
  48. data/lib/workarea/testing/factories/user.rb +24 -0
  49. data/lib/workarea/testing/factories.rb +146 -0
  50. data/lib/workarea/testing/factory_configuration.rb +90 -0
  51. data/lib/workarea/testing/indexes.rb +22 -0
  52. data/lib/workarea/testing/locale_routing_fixes.rb +33 -0
  53. data/lib/workarea/testing/product_image.jpg +0 -0
  54. data/lib/workarea/testing/teaspoon.rb +186 -0
  55. data/lib/workarea/testing/user_avatar.jpg +0 -0
  56. data/lib/workarea/testing/warning_suppressor.rb +59 -0
  57. data/lib/workarea/view_test.rb +40 -0
  58. data/workarea-testing.gemspec +29 -0
  59. metadata +240 -0
@@ -0,0 +1,38 @@
1
+ module Workarea
2
+ module Factories
3
+ module Content
4
+ Factories.add(self)
5
+
6
+ def create_asset(overrides = {})
7
+ attributes = factory_defaults(:asset).merge(overrides)
8
+ Workarea::Content::Asset.create!(attributes)
9
+ end
10
+
11
+ def create_content(overrides = {})
12
+ attributes = factory_defaults(:content).merge(overrides)
13
+ Workarea::Content.create!(attributes)
14
+ end
15
+
16
+ def create_page(overrides = {})
17
+ attributes = factory_defaults(:page).merge(overrides)
18
+ Workarea::Content::Page.create!(attributes)
19
+ end
20
+
21
+ def pdf_file_path
22
+ Factories::Content.pdf_file_path
23
+ end
24
+
25
+ def pdf_file
26
+ Factories::Content.pdf_file
27
+ end
28
+
29
+ def self.pdf_file_path
30
+ Testing::Engine.root.join('lib', 'workarea', 'testing', 'example_document.pdf')
31
+ end
32
+
33
+ def self.pdf_file
34
+ IO.read(pdf_file_path)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,21 @@
1
+ module Workarea
2
+ module Factories
3
+ module DataFile
4
+ Factories.add(self)
5
+
6
+ def create_import(overrides = {})
7
+ attributes = factory_defaults(:import).merge(overrides)
8
+ Workarea::DataFile::Import.create!(attributes)
9
+ end
10
+
11
+ def create_export(overrides = {})
12
+ attributes = factory_defaults(:export).merge(overrides)
13
+ Workarea::DataFile::Export.create!(attributes)
14
+ end
15
+
16
+ def tax_rates_csv_path
17
+ "#{Core::Engine.root}/test/fixtures/tax_rates.csv"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Workarea
2
+ module Factories
3
+ module Fulfillment
4
+ Factories.add(self)
5
+
6
+ def fulfill_order(order)
7
+ fulfillment = Fulfillment.find(order.id) rescue nil
8
+ fulfillment ||= create_fulfillment_from_order(order)
9
+ fulfillment.ship_items(
10
+ '1z1243',
11
+ order.items.map { |i| { id: i.id, quantity: i.quantity } }
12
+ )
13
+ end
14
+
15
+ def create_fulfillment_from_order(order)
16
+ create = CreateFulfillment.new(order).tap(&:perform)
17
+ create.fulfillment
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ module Workarea
2
+ module Factories
3
+ module Insights
4
+ Factories.add(self)
5
+
6
+ def create_hot_products(overrides = {})
7
+ attributes = factory_defaults(:hot_products).merge(overrides)
8
+ Workarea::Insights::HotProducts.create!(attributes)
9
+ end
10
+
11
+ def create_cold_products(overrides = {})
12
+ attributes = factory_defaults(:cold_products).merge(overrides)
13
+ Workarea::Insights::ColdProducts.create!(attributes)
14
+ end
15
+
16
+ def create_top_products(overrides = {})
17
+ attributes = factory_defaults(:top_products).merge(overrides)
18
+ Workarea::Insights::TopProducts.create!(attributes)
19
+ end
20
+
21
+ def create_trending_products(overrides = {})
22
+ attributes = factory_defaults(:trending_products).merge(overrides)
23
+ Workarea::Insights::TrendingProducts.create!(attributes)
24
+ end
25
+
26
+ def create_top_discounts(overrides = {})
27
+ attributes = factory_defaults(:top_discounts).merge(overrides)
28
+ Workarea::Insights::TopDiscounts.create!(attributes)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,25 @@
1
+ module Workarea
2
+ module Factories
3
+ module Metrics
4
+ Factories.add(self)
5
+
6
+ mattr_accessor :product_by_week_count, :search_by_week_count
7
+ self.product_by_week_count = 0
8
+ self.search_by_week_count = 0
9
+
10
+ def create_product_by_week(overrides = {})
11
+ attributes = factory_defaults(:insights_product_by_week).merge(overrides)
12
+ Workarea::Metrics::ProductByWeek.create!(attributes).tap do
13
+ Factories::Metrics.product_by_week_count += 1
14
+ end
15
+ end
16
+
17
+ def create_search_by_week(overrides = {})
18
+ attributes = factory_defaults(:insights_search_by_week).merge(overrides)
19
+ Workarea::Metrics::SearchByWeek.create!(attributes).tap do
20
+ Factories::Metrics.search_by_week_count += 1
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ module Workarea
2
+ module Factories
3
+ module Navigation
4
+ Factories.add(self)
5
+
6
+ def create_taxon(overrides = {})
7
+ attributes = factory_defaults(:taxon).merge(overrides)
8
+ Workarea::Navigation::Taxon.create!(attributes)
9
+ end
10
+
11
+ def create_redirect(overrides = {})
12
+ attributes = factory_defaults(:redirect).merge(overrides)
13
+ Workarea::Navigation::Redirect.create!(attributes)
14
+ end
15
+
16
+ def create_menu(overrides = {})
17
+ attributes = factory_defaults(:menu).merge(overrides)
18
+ Workarea::Navigation::Menu.create!(attributes)
19
+ end
20
+
21
+ def redirects_csv_path
22
+ "#{Core::Engine.root}/test/fixtures/redirects.csv"
23
+ end
24
+
25
+ def redirects_fail_csv_path
26
+ "#{Core::Engine.root}/test/fixtures/redirects_fail.csv"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,77 @@
1
+ module Workarea
2
+ module Factories
3
+ module Order
4
+ class UnplacedOrderError < RuntimeError; end
5
+
6
+ Factories.add(self)
7
+
8
+ def create_order(overrides = {})
9
+ attributes = factory_defaults(:order).merge(overrides)
10
+ Workarea::Order.new(attributes).tap(&:save!)
11
+ end
12
+
13
+ def create_placed_order(overrides = {})
14
+ attributes = factory_defaults(:placed_order).merge(overrides)
15
+
16
+ shipping_service = create_shipping_service
17
+ sku = 'SKU'
18
+ create_product(variants: [{ sku: sku, regular: 5.to_m }])
19
+ details = OrderItemDetails.find(sku)
20
+ order = Workarea::Order.new(attributes)
21
+ item = { sku: sku, quantity: 2 }.merge(details.to_h)
22
+
23
+ order.add_item(item)
24
+
25
+ checkout = Checkout.new(order)
26
+ checkout.update(
27
+ factory_defaults(:checkout_payment).merge(
28
+ shipping_address: factory_defaults(:shipping_address),
29
+ billing_address: factory_defaults(:billing_address),
30
+ shipping_service: shipping_service.name,
31
+ )
32
+ )
33
+
34
+ unless checkout.place_order
35
+ raise(
36
+ UnplacedOrderError,
37
+ 'failed placing the order in the create_placed_order factory'
38
+ )
39
+ end
40
+
41
+ forced_attrs = overrides.slice(:placed_at, :update_at, :total_price)
42
+ order.update_attributes!(forced_attrs)
43
+ order
44
+ end
45
+
46
+ def complete_checkout(order, options = {})
47
+ shipping_address =
48
+ factory_defaults(:shipping_address).merge(options[:shipping_address] || {})
49
+
50
+ billing_address =
51
+ factory_defaults(:billing_address).merge(options[:billing_address] || {})
52
+
53
+ payment = factory_defaults(:checkout_payment).tap do |payment|
54
+ payment[:credit_card].merge(options[:credit_card] || {})
55
+ end
56
+
57
+ shipping_service = options[:shipping_service].presence ||
58
+ create_shipping_service.name
59
+
60
+ order.items.each do |item|
61
+ item.update_attributes!(OrderItemDetails.find!(item.sku).to_h)
62
+ end
63
+
64
+ checkout = Checkout.new(order)
65
+ checkout.update(
66
+ payment.merge(
67
+ shipping_address: shipping_address,
68
+ billing_address: billing_address,
69
+ shipping_service: shipping_service,
70
+ )
71
+ )
72
+
73
+ checkout.place_order
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,37 @@
1
+ module Workarea
2
+ module Factories
3
+ module Payment
4
+ Factories.add(self)
5
+
6
+ def create_payment(overrides = {})
7
+ attributes = factory_defaults(:payment).merge(overrides)
8
+ Workarea::Payment.create!(attributes)
9
+ end
10
+
11
+ def create_payment_profile(overrides = {})
12
+ attributes = factory_defaults(:payment_profile).merge(overrides)
13
+ Workarea::Payment::Profile.create!(attributes)
14
+ end
15
+
16
+ def create_saved_credit_card(overrides = {})
17
+ attributes = factory_defaults(:saved_credit_card).merge(overrides)
18
+ Workarea::Payment::SavedCreditCard.create!(attributes)
19
+ end
20
+
21
+ def create_transaction(overrides = {})
22
+ attributes = factory_defaults(:transaction).merge(overrides)
23
+ Workarea::Payment::Transaction.create!(attributes)
24
+ end
25
+
26
+ def capture_order(order)
27
+ payment = Workarea::Payment.find(order.id)
28
+ capture = Workarea::Payment::Capture.new(
29
+ payment: payment,
30
+ amounts: payment.tenders.reduce({}) { |m, t| m.merge(t.id => t.capturable_amount) }
31
+ )
32
+
33
+ capture.complete!
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,92 @@
1
+ module Workarea
2
+ module Factories
3
+ module Performance
4
+ module Catalog
5
+ Factories.add(self)
6
+
7
+ def create_complex_variant
8
+ @sku_counter ||= 0
9
+
10
+ details =
11
+ if @sku_counter < variant_details.length
12
+ variant_details[@sku_counter]
13
+ else
14
+ variant_details[@sku_counter % variant_details.length]
15
+ end
16
+
17
+ @sku_counter += 1
18
+
19
+ attributes = {
20
+ sku: "sku#{@sku_counter}",
21
+ details: details
22
+ }
23
+
24
+ create_pricing_sku(
25
+ id: attributes[:sku],
26
+ msrp: (rand * 215.0).round(2),
27
+ prices: [
28
+ { regular: (rand * 101.1).round(2), sale: (rand * 98.6).round(2), min_quantity: 1 },
29
+ { regular: (rand * 101.1).round(2), sale: (rand * 98.6).round(2), min_quantity: 2 },
30
+ { regular: (rand * 101.1).round(2), sale: (rand * 98.6).round(2), min_quantity: 5 }
31
+ ]
32
+ )
33
+
34
+ create_inventory(
35
+ id: attributes[:sku],
36
+ policy: 'standard',
37
+ available: (rand * 100).round + 10,
38
+ reserve: (rand * 5).round
39
+ )
40
+
41
+ Workarea::Catalog::Variant.new(attributes)
42
+ end
43
+
44
+ def create_complex_product(overrides = {})
45
+ attributes = { variants: [], details: {} }.merge(overrides)
46
+
47
+ product = create_product(attributes)
48
+ product.variants = Array.new(100) { create_complex_variant } unless product.variants.any?
49
+
50
+ colors = product.variants.flat_map { |v| v.fetch_detail('Color') }.uniq!
51
+ sizes = product.variants.flat_map { |v| v.fetch_detail('Size') }.uniq!
52
+ materials = product.variants.flat_map { |v| v.fetch_detail('Material') }.uniq!
53
+
54
+ colors.each do |color|
55
+ product.images.build(image: product_image_file, option: color)
56
+ end
57
+
58
+ product.filters = { 'Color' => colors, 'Size' => sizes, 'Material' => materials }
59
+ product.save
60
+ product
61
+ end
62
+
63
+ private
64
+
65
+ def variant_details
66
+ return @variant_details if defined?(@variant_details)
67
+ details = {
68
+ 'Color' => %w(Red Orange Yellow Green Blue Indigo Violet),
69
+ 'Size' => %w(X-Small Small Medium Large X-Large XX-Large),
70
+ 'Material' => %w(Cotton Wool Silk Polyester)
71
+ }
72
+
73
+ @variant_details = []
74
+
75
+ details['Color'].each do |color|
76
+ details['Size'].each do |size|
77
+ details['Material'].each do |material|
78
+ @variant_details << {
79
+ 'Color' => [color],
80
+ 'Size' => [size],
81
+ 'Material' => [material]
82
+ }
83
+ end
84
+ end
85
+ end
86
+
87
+ @variant_details.shuffle
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,59 @@
1
+ module Workarea
2
+ module Factories
3
+ module Pricing
4
+ Factories.add(self)
5
+
6
+ def create_buy_some_get_some_discount(overrides = {})
7
+ attributes = factory_defaults(:buy_some_get_some_discount).merge(overrides)
8
+ Workarea::Pricing::Discount::BuySomeGetSome.create!(attributes)
9
+ end
10
+
11
+ def create_category_discount(overrides = {})
12
+ attributes = factory_defaults(:category_discount).merge(overrides)
13
+ Workarea::Pricing::Discount::Category.create!(attributes)
14
+ end
15
+
16
+ def create_code_list(overrides = {})
17
+ attributes = factory_defaults(:code_list).merge(overrides)
18
+ Workarea::Pricing::Discount::CodeList.new(attributes).tap do |code_list|
19
+ code_list.save!
20
+ end
21
+ end
22
+
23
+ def create_free_gift_discount(overrides = {})
24
+ attributes = factory_defaults(:free_gift_discount).merge(overrides)
25
+ Workarea::Pricing::Discount::FreeGift.create!(attributes)
26
+ end
27
+
28
+ def create_order_total_discount(overrides = {})
29
+ attributes = factory_defaults(:order_total_discount).merge(overrides)
30
+ Workarea::Pricing::Discount::OrderTotal.create!(attributes)
31
+ end
32
+
33
+ def create_pricing_sku(overrides = {})
34
+ attributes = factory_defaults(:pricing_sku).merge(overrides)
35
+ Workarea::Pricing::Sku.new(attributes).tap(&:save!)
36
+ end
37
+
38
+ def create_product_attribute_discount(overrides = {})
39
+ attributes = factory_defaults(:product_attribute_discount).merge(overrides)
40
+ Workarea::Pricing::Discount::ProductAttribute.create!(attributes)
41
+ end
42
+
43
+ def create_product_discount(overrides = {})
44
+ attributes = factory_defaults(:product_discount).merge(overrides)
45
+ Workarea::Pricing::Discount::Product.create!(attributes)
46
+ end
47
+
48
+ def create_quantity_fixed_price_discount(overrides = {})
49
+ attributes = factory_defaults(:quantity_fixed_price_discount).merge(overrides)
50
+ Workarea::Pricing::Discount::QuantityFixedPrice.create!(attributes)
51
+ end
52
+
53
+ def create_shipping_discount(overrides = {})
54
+ attributes = factory_defaults(:shipping_discount).merge(overrides)
55
+ Workarea::Pricing::Discount::Shipping.create!(attributes)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,17 @@
1
+ module Workarea
2
+ module Factories
3
+ module Recommendation
4
+ Factories.add(self)
5
+
6
+ def create_recommendations(overrides = {})
7
+ attributes = factory_defaults(:recommendations).merge(overrides)
8
+ Workarea::Recommendation::Settings.create!(attributes)
9
+ end
10
+
11
+ def create_user_activity(overrides = {})
12
+ attributes = factory_defaults(:user_activity).merge(overrides)
13
+ Workarea::Recommendation::UserActivity.create!(attributes)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,72 @@
1
+ module Workarea
2
+ module Factories
3
+ module Search
4
+ Factories.add(self)
5
+
6
+ def create_search_settings(overrides = {})
7
+ Workarea::Search::Settings.create!(overrides)
8
+ end
9
+
10
+ def create_search_customization(overrides = {})
11
+ attributes = factory_defaults(:search_customization).merge(overrides)
12
+ Workarea::Search::Customization.create!(attributes)
13
+ end
14
+
15
+ def create_product_search(options = {})
16
+ result = Workarea::Search::ProductSearch.new
17
+
18
+ allow(result).to receive_messages(
19
+ create_product_browse_search_options(options)
20
+ )
21
+
22
+ result
23
+ end
24
+
25
+ def create_category_browse_search(options = {})
26
+ result = Workarea::Search::CategoryBrowse.new
27
+
28
+ allow(result).to receive_messages(
29
+ create_product_browse_search_options(options)
30
+ )
31
+
32
+ result
33
+ end
34
+
35
+ def create_admin_search(options = {})
36
+ result = Workarea::Search::AdminSearch.new
37
+ options.reverse_merge!(factory_defaults(:admin_search))
38
+
39
+ options[:results] = PagedArray.from(
40
+ options[:results],
41
+ options[:page],
42
+ options[:per_page],
43
+ options[:total]
44
+ )
45
+
46
+ allow(result).to receive_messages(options)
47
+
48
+ result
49
+ end
50
+
51
+ def elasticsearch_response
52
+ file = "#{File.dirname(__FILE__)}/../elasticsearch_response.json"
53
+ JSON.parse(IO.read(file))
54
+ end
55
+
56
+ def create_product_browse_search_options(options = {})
57
+ options.reverse_merge!(factory_defaults(:product_browse_search_options))
58
+
59
+ options[:results] = options[:products].map do |product|
60
+ { catalog_id: product.id, model: product, option: nil }
61
+ end
62
+
63
+ options.except(:products)
64
+ end
65
+
66
+ def update_search_settings(overrides = {})
67
+ attributes = factory_defaults(:search_settings).merge(overrides)
68
+ Workarea::Search::Settings.current.update_attributes!(attributes)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,24 @@
1
+ module Workarea
2
+ module Factories
3
+ module User
4
+ Factories.add(self)
5
+
6
+ def create_user(overrides = {})
7
+ attributes = factory_defaults(:user).merge(overrides)
8
+
9
+ Workarea::User.new(attributes).tap do |user|
10
+ user.save!
11
+ Factories.user_count += 1
12
+ end
13
+ end
14
+
15
+ def user_avatar_file_path
16
+ Factories::User.user_avatar_file_path
17
+ end
18
+
19
+ def self.user_avatar_file_path
20
+ Testing::Engine.root.join('lib', 'workarea', 'testing', 'user_avatar.jpg')
21
+ end
22
+ end
23
+ end
24
+ end