workarea-api-admin 4.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/README.md +82 -0
- data/Rakefile +10 -0
- data/app/assets/images/workarea/api/admin/icons/api.svg +1 -0
- data/app/controllers/workarea/api/admin/application_controller.rb +73 -0
- data/app/controllers/workarea/api/admin/categories_controller.rb +305 -0
- data/app/controllers/workarea/api/admin/category_product_rules_controller.rb +232 -0
- data/app/controllers/workarea/api/admin/content_assets_controller.rb +299 -0
- data/app/controllers/workarea/api/admin/content_controller.rb +268 -0
- data/app/controllers/workarea/api/admin/discounts_controller.rb +271 -0
- data/app/controllers/workarea/api/admin/email_signups_controller.rb +108 -0
- data/app/controllers/workarea/api/admin/fulfillments_controller.rb +268 -0
- data/app/controllers/workarea/api/admin/inventory_skus_controller.rb +305 -0
- data/app/controllers/workarea/api/admin/navigation_menus_controller.rb +267 -0
- data/app/controllers/workarea/api/admin/navigation_taxons_controller.rb +305 -0
- data/app/controllers/workarea/api/admin/orders_controller.rb +160 -0
- data/app/controllers/workarea/api/admin/pages_controller.rb +305 -0
- data/app/controllers/workarea/api/admin/payment_profiles_controller.rb +305 -0
- data/app/controllers/workarea/api/admin/payment_transactions_controller.rb +108 -0
- data/app/controllers/workarea/api/admin/payments_controller.rb +115 -0
- data/app/controllers/workarea/api/admin/prices_controller.rb +232 -0
- data/app/controllers/workarea/api/admin/pricing_skus_controller.rb +305 -0
- data/app/controllers/workarea/api/admin/product_images_controller.rb +232 -0
- data/app/controllers/workarea/api/admin/products_controller.rb +305 -0
- data/app/controllers/workarea/api/admin/promo_code_lists_controller.rb +305 -0
- data/app/controllers/workarea/api/admin/recommendation_settings_controller.rb +122 -0
- data/app/controllers/workarea/api/admin/redirects_controller.rb +305 -0
- data/app/controllers/workarea/api/admin/releases_controller.rb +304 -0
- data/app/controllers/workarea/api/admin/saved_addresses_controller.rb +232 -0
- data/app/controllers/workarea/api/admin/saved_credit_cards_controller.rb +256 -0
- data/app/controllers/workarea/api/admin/shipping_rates_controller.rb +232 -0
- data/app/controllers/workarea/api/admin/shipping_services_controller.rb +299 -0
- data/app/controllers/workarea/api/admin/shippings_controller.rb +105 -0
- data/app/controllers/workarea/api/admin/swagger_controller.rb +41 -0
- data/app/controllers/workarea/api/admin/tax_categories_controller.rb +242 -0
- data/app/controllers/workarea/api/admin/tax_rates_controller.rb +292 -0
- data/app/controllers/workarea/api/admin/users_controller.rb +296 -0
- data/app/controllers/workarea/api/admin/variants_controller.rb +232 -0
- data/app/models/workarea/api/admin/bulk_upsert.rb +74 -0
- data/app/models/workarea/user.decorator +7 -0
- data/app/views/workarea/admin/users/_api_permissions.html.haml +6 -0
- data/app/workers/workarea/perform_api_bulk_upsert.rb +15 -0
- data/bin/rails +18 -0
- data/config/initializers/append_points.rb +4 -0
- data/config/initializers/config.rb +15 -0
- data/config/locales/en.yml +9 -0
- data/config/routes.rb +81 -0
- data/lib/workarea/api/admin.rb +21 -0
- data/lib/workarea/api/admin/engine.rb +14 -0
- data/lib/workarea/api/admin/swagger.rb +106 -0
- data/test/documentation/workarea/api/admin/categories_documentation_test.rb +106 -0
- data/test/documentation/workarea/api/admin/category_product_rules_documentation_test.rb +78 -0
- data/test/documentation/workarea/api/admin/content_assets_documentation_test.rb +94 -0
- data/test/documentation/workarea/api/admin/content_documentation_test.rb +87 -0
- data/test/documentation/workarea/api/admin/discounts_documentation_test.rb +85 -0
- data/test/documentation/workarea/api/admin/email_signups_documentation_test.rb +41 -0
- data/test/documentation/workarea/api/admin/fulfillment_documentation_test.rb +84 -0
- data/test/documentation/workarea/api/admin/inventory_skus_documentation_test.rb +95 -0
- data/test/documentation/workarea/api/admin/navigation_menus_documentation_test.rb +81 -0
- data/test/documentation/workarea/api/admin/navigation_taxons_documentation_test.rb +94 -0
- data/test/documentation/workarea/api/admin/orders_documentation_test.rb +65 -0
- data/test/documentation/workarea/api/admin/pages_documentation_test.rb +93 -0
- data/test/documentation/workarea/api/admin/payment_profiles_documentation_test.rb +98 -0
- data/test/documentation/workarea/api/admin/payment_transactions_documentation_test.rb +43 -0
- data/test/documentation/workarea/api/admin/payments_documentation_test.rb +41 -0
- data/test/documentation/workarea/api/admin/prices_documentation_test.rb +82 -0
- data/test/documentation/workarea/api/admin/pricing_skus_documentation_test.rb +95 -0
- data/test/documentation/workarea/api/admin/product_images_documentation_test.rb +101 -0
- data/test/documentation/workarea/api/admin/products_documentation_test.rb +96 -0
- data/test/documentation/workarea/api/admin/promo_code_lists_documentation_test.rb +94 -0
- data/test/documentation/workarea/api/admin/recommendation_settings_documentation_test.rb +37 -0
- data/test/documentation/workarea/api/admin/redirects_documentation_test.rb +96 -0
- data/test/documentation/workarea/api/admin/release_changes_documentation_test.rb +32 -0
- data/test/documentation/workarea/api/admin/releases_documentation_test.rb +93 -0
- data/test/documentation/workarea/api/admin/saved_addresses_documentation_test.rb +92 -0
- data/test/documentation/workarea/api/admin/saved_credit_cards_documentation_test.rb +86 -0
- data/test/documentation/workarea/api/admin/shipping_rates_documentation_test.rb +78 -0
- data/test/documentation/workarea/api/admin/shipping_services_documentation_test.rb +93 -0
- data/test/documentation/workarea/api/admin/shippings_documentation_test.rb +41 -0
- data/test/documentation/workarea/api/admin/tax_categories_documentation_test.rb +95 -0
- data/test/documentation/workarea/api/admin/tax_rates_documentation_test.rb +78 -0
- data/test/documentation/workarea/api/admin/users_documentation_test.rb +99 -0
- data/test/documentation/workarea/api/admin/variants_documentation_test.rb +80 -0
- data/test/dummy/Rakefile +7 -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/.keep +0 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/.keep +0 -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 +4 -0
- data/test/dummy/config/application.rb +25 -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 +55 -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 +8 -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 +6 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/db/seeds.rb +2 -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 +1 -0
- data/test/integration/workarea/api/admin/audit_log_integration_test.rb +20 -0
- data/test/integration/workarea/api/admin/authentication_integration_test.rb +61 -0
- data/test/integration/workarea/api/admin/categories_integration_test.rb +64 -0
- data/test/integration/workarea/api/admin/category_product_rules_integration_test.rb +58 -0
- data/test/integration/workarea/api/admin/content_assets_integration_test.rb +65 -0
- data/test/integration/workarea/api/admin/content_integration_test.rb +59 -0
- data/test/integration/workarea/api/admin/discounts_integration_test.rb +64 -0
- data/test/integration/workarea/api/admin/email_signups_integration_test.rb +32 -0
- data/test/integration/workarea/api/admin/error_handling_integration_test.rb +16 -0
- data/test/integration/workarea/api/admin/fulfillments_integration_test.rb +62 -0
- data/test/integration/workarea/api/admin/inventory_skus_integration_test.rb +70 -0
- data/test/integration/workarea/api/admin/navigation_menus_integration_test.rb +54 -0
- data/test/integration/workarea/api/admin/navigation_taxons_integration_test.rb +63 -0
- data/test/integration/workarea/api/admin/orders_integration_test.rb +53 -0
- data/test/integration/workarea/api/admin/pages_integration_test.rb +64 -0
- data/test/integration/workarea/api/admin/payment_profiles_integration_test.rb +75 -0
- data/test/integration/workarea/api/admin/payment_transactions_integration_test.rb +45 -0
- data/test/integration/workarea/api/admin/payments_integration_test.rb +29 -0
- data/test/integration/workarea/api/admin/prices_integration_test.rb +55 -0
- data/test/integration/workarea/api/admin/pricing_skus_integration_test.rb +72 -0
- data/test/integration/workarea/api/admin/product_images_integration_test.rb +56 -0
- data/test/integration/workarea/api/admin/products_integration_test.rb +66 -0
- data/test/integration/workarea/api/admin/promo_code_lists_integration_test.rb +70 -0
- data/test/integration/workarea/api/admin/recommendation_settings_integration_test.rb +41 -0
- data/test/integration/workarea/api/admin/redirects_integration_test.rb +69 -0
- data/test/integration/workarea/api/admin/release_changes_integration_test.rb +32 -0
- data/test/integration/workarea/api/admin/releases_integration_test.rb +60 -0
- data/test/integration/workarea/api/admin/saved_addresses_integration_test.rb +70 -0
- data/test/integration/workarea/api/admin/saved_credit_cards_integration_test.rb +76 -0
- data/test/integration/workarea/api/admin/shipping_rates_integration_test.rb +54 -0
- data/test/integration/workarea/api/admin/shipping_services_integration_test.rb +64 -0
- data/test/integration/workarea/api/admin/shippings_integration_test.rb +34 -0
- data/test/integration/workarea/api/admin/tax_categories_integration_test.rb +64 -0
- data/test/integration/workarea/api/admin/tax_rates_integration_test.rb +66 -0
- data/test/integration/workarea/api/admin/users_integration_test.rb +67 -0
- data/test/integration/workarea/api/admin/variants_integration_test.rb +59 -0
- data/test/models/workarea/api/admin/bulk_upsert_test.rb +79 -0
- data/test/test_helper.rb +10 -0
- data/test/vcr_cassettes/product_image_from_url.yml +43 -0
- data/workarea-api-admin.gemspec +18 -0
- metadata +252 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Admin
|
6
|
+
class NavigationTaxonsIntegrationTest < IntegrationTest
|
7
|
+
include Workarea::Admin::IntegrationTest
|
8
|
+
|
9
|
+
setup :set_sample_attributes
|
10
|
+
|
11
|
+
def set_sample_attributes
|
12
|
+
@sample_attributes = create_taxon.as_json.except('_id')
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_lists_taxons
|
16
|
+
2.times { create_taxon }
|
17
|
+
get admin_api.navigation_taxons_path
|
18
|
+
result = JSON.parse(response.body)['navigation_taxons']
|
19
|
+
assert_equal(4, result.length)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_creates_taxons
|
23
|
+
assert_difference 'Navigation::Taxon.count', 1 do
|
24
|
+
post admin_api.navigation_taxons_path,
|
25
|
+
params: { navigation_taxon: @sample_attributes }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_shows_taxons
|
30
|
+
taxon = create_taxon
|
31
|
+
get admin_api.navigation_taxon_path(taxon.id)
|
32
|
+
result = JSON.parse(response.body)['navigation_taxon']
|
33
|
+
assert_equal(taxon, Navigation::Taxon.new(result))
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_updates_taxons
|
37
|
+
taxon = create_taxon
|
38
|
+
patch admin_api.navigation_taxon_path(taxon.id),
|
39
|
+
params: { navigation_taxon: { name: 'foo' } }
|
40
|
+
|
41
|
+
assert_equal('foo', taxon.reload.name)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_bulk_upserts_taxons
|
45
|
+
data = [@sample_attributes] * 10
|
46
|
+
|
47
|
+
assert_difference 'Navigation::Taxon.count', 10 do
|
48
|
+
patch admin_api.bulk_navigation_taxons_path,
|
49
|
+
params: { navigation_taxons: data }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_destroys_taxons
|
54
|
+
taxon = create_taxon
|
55
|
+
|
56
|
+
assert_difference 'Navigation::Taxon.count', -1 do
|
57
|
+
delete admin_api.navigation_taxon_path(taxon.id)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Admin
|
6
|
+
class OrdersIntegrationTest < IntegrationTest
|
7
|
+
include Workarea::Admin::IntegrationTest
|
8
|
+
|
9
|
+
def test_lists_orders
|
10
|
+
orders = [create_order, create_order]
|
11
|
+
get admin_api.orders_path
|
12
|
+
result = JSON.parse(response.body)['orders']
|
13
|
+
|
14
|
+
assert_equal(2, result.length)
|
15
|
+
assert_equal(orders.second, Order.new(result.first))
|
16
|
+
assert_equal(orders.first, Order.new(result.second))
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_filters_orders
|
20
|
+
orders = [
|
21
|
+
create_order(placed_at: 1.week.ago),
|
22
|
+
create_order(placed_at: 2.days.ago)
|
23
|
+
]
|
24
|
+
|
25
|
+
get admin_api.orders_path(
|
26
|
+
placed_at_greater_than: 3.days.ago,
|
27
|
+
placed_at_less_than: 1.days.ago
|
28
|
+
)
|
29
|
+
|
30
|
+
result = JSON.parse(response.body)['orders']
|
31
|
+
|
32
|
+
assert_equal(1, result.length)
|
33
|
+
assert_equal(orders.second, Order.new(result.first))
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_shows_orders
|
37
|
+
order = create_placed_order
|
38
|
+
payment = Payment.find(order.id)
|
39
|
+
fulfillment = Fulfillment.find(order.id)
|
40
|
+
shipping = Shipping.find_by_order(order.id)
|
41
|
+
|
42
|
+
get admin_api.order_path(order.id)
|
43
|
+
result = JSON.parse(response.body)
|
44
|
+
|
45
|
+
assert_equal(order, Order.new(result['order']))
|
46
|
+
assert_equal(payment, Payment.new(result['payment']))
|
47
|
+
assert_equal(fulfillment, Fulfillment.new(result['fulfillment']))
|
48
|
+
assert_equal(shipping, Shipping.new(result['shippings'].first))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Admin
|
6
|
+
class PagesIntegrationTest < IntegrationTest
|
7
|
+
include Workarea::Admin::IntegrationTest
|
8
|
+
|
9
|
+
setup :set_sample_attributes
|
10
|
+
|
11
|
+
def set_sample_attributes
|
12
|
+
@sample_attributes = create_page.as_json.except('_id', 'slug')
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_lists_pages
|
16
|
+
pages = [create_page, create_page]
|
17
|
+
get admin_api.pages_path
|
18
|
+
result = JSON.parse(response.body)['pages']
|
19
|
+
|
20
|
+
assert_equal(3, result.length)
|
21
|
+
assert_equal(pages.second, Content::Page.new(result.first))
|
22
|
+
assert_equal(pages.first, Content::Page.new(result.second))
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_creates_pages
|
26
|
+
assert_difference 'Content::Page.count', 1 do
|
27
|
+
post admin_api.pages_path, params: { page: @sample_attributes }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_shows_pages
|
32
|
+
page = create_page
|
33
|
+
get admin_api.page_path(page.id)
|
34
|
+
result = JSON.parse(response.body)['page']
|
35
|
+
assert_equal(page, Content::Page.new(result))
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_updates_pages
|
39
|
+
page = create_page
|
40
|
+
patch admin_api.page_path(page.id), params: { page: { name: 'foo' } }
|
41
|
+
|
42
|
+
page.reload
|
43
|
+
assert_equal('foo', page.name)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_bulk_upserts_pages
|
47
|
+
data = [@sample_attributes] * 10
|
48
|
+
|
49
|
+
assert_difference 'Content::Page.count', 10 do
|
50
|
+
patch admin_api.bulk_pages_path, params: { pages: data }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_destroys_pages
|
55
|
+
page = create_page
|
56
|
+
|
57
|
+
assert_difference 'Content::Page.count', -1 do
|
58
|
+
delete admin_api.page_path(page.id)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Admin
|
6
|
+
class PaymentProfilesIntegrationTest < IntegrationTest
|
7
|
+
include Workarea::Admin::IntegrationTest
|
8
|
+
|
9
|
+
setup :set_sample_attributes
|
10
|
+
|
11
|
+
def set_sample_attributes
|
12
|
+
@sample_attributes = create_payment_profile.as_json.except('_id')
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_lists_payment_profiles
|
16
|
+
profiles = [
|
17
|
+
create_payment_profile(reference: '1'),
|
18
|
+
create_payment_profile(reference: '2')
|
19
|
+
]
|
20
|
+
get admin_api.payment_profiles_path
|
21
|
+
result = JSON.parse(response.body)['payment_profiles']
|
22
|
+
|
23
|
+
assert_equal(3, result.length)
|
24
|
+
assert_equal(profiles.second, Payment::Profile.new(result.first))
|
25
|
+
assert_equal(profiles.first, Payment::Profile.new(result.second))
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_creates_payment_profiles
|
29
|
+
data = @sample_attributes.merge('reference' => '2')
|
30
|
+
|
31
|
+
assert_difference 'Payment::Profile.count', 1 do
|
32
|
+
post admin_api.payment_profiles_path, params: { payment_profile: data }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_shows_payment_profiles
|
37
|
+
profile = create_payment_profile(reference: 'foo')
|
38
|
+
get admin_api.payment_profile_path(profile.id)
|
39
|
+
result = JSON.parse(response.body)['payment_profile']
|
40
|
+
assert_equal(profile, Payment::Profile.new(result))
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_updates_payment_profiles
|
44
|
+
profile = create_payment_profile(reference: 'foo')
|
45
|
+
patch admin_api.payment_profile_path(profile.id),
|
46
|
+
params: { payment_profile: { store_credit: 29 } }
|
47
|
+
|
48
|
+
profile.reload
|
49
|
+
assert_equal(29.to_m, profile.store_credit)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_bulk_upserts_payment_profiles
|
53
|
+
count = 0
|
54
|
+
data = Array.new(10) do
|
55
|
+
count += 1
|
56
|
+
@sample_attributes.merge('reference' => count)
|
57
|
+
end
|
58
|
+
|
59
|
+
assert_difference 'Payment::Profile.count', 10 do
|
60
|
+
patch admin_api.bulk_payment_profiles_path,
|
61
|
+
params: { payment_profiles: data }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_destroys_payment_profiles
|
66
|
+
profile = create_payment_profile(reference: 'foo')
|
67
|
+
|
68
|
+
assert_difference 'Payment::Profile.count', -1 do
|
69
|
+
delete admin_api.payment_profile_path(profile.id)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Admin
|
6
|
+
class PaymentTransactionsIntegrationTest < IntegrationTest
|
7
|
+
include Workarea::Admin::IntegrationTest
|
8
|
+
|
9
|
+
def create_transaction
|
10
|
+
payment = create_payment
|
11
|
+
payment.set_credit_card(
|
12
|
+
number: '1',
|
13
|
+
month: 1,
|
14
|
+
year: Time.now.year + 1,
|
15
|
+
cvv: '999'
|
16
|
+
)
|
17
|
+
|
18
|
+
Payment::Transaction.create!(
|
19
|
+
payment: payment,
|
20
|
+
tender_id: payment.credit_card.id,
|
21
|
+
amount: 45,
|
22
|
+
action: 'authorize'
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_lists_transactions
|
27
|
+
transactions = [create_transaction, create_transaction]
|
28
|
+
get admin_api.payment_transactions_path
|
29
|
+
result = JSON.parse(response.body)['transactions']
|
30
|
+
|
31
|
+
assert_equal(2, result.length)
|
32
|
+
assert_equal(transactions.second, Payment::Transaction.new(result.first))
|
33
|
+
assert_equal(transactions.first, Payment::Transaction.new(result.second))
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_shows_transactions
|
37
|
+
transaction = create_transaction
|
38
|
+
get admin_api.payment_transaction_path(transaction.id)
|
39
|
+
result = JSON.parse(response.body)['transaction']
|
40
|
+
assert_equal(transaction, Payment::Transaction.new(result))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Admin
|
6
|
+
class PaymentsIntegrationTest < IntegrationTest
|
7
|
+
include Workarea::Admin::IntegrationTest
|
8
|
+
|
9
|
+
def test_lists_payments
|
10
|
+
payments = [create_payment, create_payment]
|
11
|
+
get admin_api.payments_path
|
12
|
+
result = JSON.parse(response.body)['payments']
|
13
|
+
|
14
|
+
assert_equal(2, result.length)
|
15
|
+
assert_equal(payments.second, Payment.new(result.first))
|
16
|
+
assert_equal(payments.first, Payment.new(result.second))
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_shows_payments
|
20
|
+
payment = create_payment
|
21
|
+
get admin_api.payment_path(payment.id)
|
22
|
+
result = JSON.parse(response.body)
|
23
|
+
assert_equal(payment, Payment.new(result['payment']))
|
24
|
+
assert_includes(result.keys, 'payment_transactions')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Admin
|
6
|
+
class PricesIntegrationTest < IntegrationTest
|
7
|
+
include Workarea::Admin::IntegrationTest
|
8
|
+
|
9
|
+
setup :set_sample_attributes
|
10
|
+
|
11
|
+
def set_sample_attributes
|
12
|
+
@sku = create_pricing_sku
|
13
|
+
@sample_attributes = { regular: 15 }
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_price
|
17
|
+
@sku.prices.create!(@sample_attributes)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_lists_prices
|
21
|
+
prices = [create_price, create_price]
|
22
|
+
get admin_api.pricing_sku_prices_path(@sku.id)
|
23
|
+
result = JSON.parse(response.body)['prices']
|
24
|
+
|
25
|
+
assert_equal(2, result.length)
|
26
|
+
assert_equal(prices.first, Pricing::Price.new(result.first))
|
27
|
+
assert_equal(prices.second, Pricing::Price.new(result.second))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_creates_prices
|
31
|
+
assert_difference '@sku.reload.prices.count', 1 do
|
32
|
+
post admin_api.pricing_sku_prices_path(@sku.id),
|
33
|
+
params: { price: @sample_attributes }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_updates_prices
|
38
|
+
price = create_price
|
39
|
+
patch admin_api.pricing_sku_price_path(@sku.id, price.id),
|
40
|
+
params: { price: { sale: 34 } }
|
41
|
+
|
42
|
+
assert_equal(34.to_m, price.reload.sale)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_destroys_prices
|
46
|
+
price = create_price
|
47
|
+
|
48
|
+
assert_difference '@sku.reload.prices.count', -1 do
|
49
|
+
delete admin_api.pricing_sku_price_path(@sku.id, price.id)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Api
|
5
|
+
module Admin
|
6
|
+
class PricingSkusIntegrationTest < IntegrationTest
|
7
|
+
include Workarea::Admin::IntegrationTest
|
8
|
+
|
9
|
+
setup :set_sample_attributes
|
10
|
+
|
11
|
+
def set_sample_attributes
|
12
|
+
@sample_attributes = create_pricing_sku.as_json.except('_id')
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_lists_pricing_skus
|
16
|
+
pricing_skus = [
|
17
|
+
create_pricing_sku(id: '1'),
|
18
|
+
create_pricing_sku(id: '2')
|
19
|
+
]
|
20
|
+
get admin_api.pricing_skus_path
|
21
|
+
result = JSON.parse(response.body)['pricing_skus']
|
22
|
+
|
23
|
+
assert_equal(3, result.length)
|
24
|
+
assert_equal(pricing_skus.second, Pricing::Sku.new(result.first))
|
25
|
+
assert_equal(pricing_skus.first, Pricing::Sku.new(result.second))
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_creates_pricing_skus
|
29
|
+
assert_difference 'Pricing::Sku.count', 1 do
|
30
|
+
post admin_api.pricing_skus_path,
|
31
|
+
params: { pricing_sku: @sample_attributes.merge('id' => '1') }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_shows_pricing_skus
|
36
|
+
pricing_sku = create_pricing_sku(id: 'foo')
|
37
|
+
get admin_api.pricing_sku_path('foo')
|
38
|
+
result = JSON.parse(response.body)['pricing_sku']
|
39
|
+
assert_equal(pricing_sku, Pricing::Sku.new(result))
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_updates_pricing_skus
|
43
|
+
pricing_sku = create_pricing_sku(id: 'foo')
|
44
|
+
patch admin_api.pricing_sku_path('foo'),
|
45
|
+
params: { pricing_sku: { discountable: false } }
|
46
|
+
|
47
|
+
refute(pricing_sku.reload.discountable?)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_bulk_upserts_pricing_skus
|
51
|
+
count = 0
|
52
|
+
data = Array.new(10) do
|
53
|
+
count += 1
|
54
|
+
@sample_attributes.merge('id' => count)
|
55
|
+
end
|
56
|
+
|
57
|
+
assert_difference 'Pricing::Sku.count', 10 do
|
58
|
+
patch admin_api.bulk_pricing_skus_path, params: { pricing_skus: data }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_destroys_pricing_skus
|
63
|
+
create_pricing_sku(id: 'foo')
|
64
|
+
|
65
|
+
assert_difference 'Pricing::Sku.count', -1 do
|
66
|
+
delete admin_api.pricing_sku_path('foo')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|