disco_app 0.8.7 → 0.8.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/disco_app/admin/concerns/plans_controller.rb +51 -0
- data/app/controllers/disco_app/admin/plans_controller.rb +3 -0
- data/app/controllers/disco_app/charges_controller.rb +37 -20
- data/app/controllers/disco_app/concerns/app_proxy_controller.rb +1 -1
- data/app/controllers/disco_app/concerns/authenticated_controller.rb +26 -12
- data/app/controllers/disco_app/concerns/carrier_request_controller.rb +1 -1
- data/app/controllers/disco_app/install_controller.rb +20 -19
- data/app/controllers/disco_app/subscriptions_controller.rb +40 -0
- data/app/controllers/disco_app/webhooks_controller.rb +1 -1
- data/app/controllers/sessions_controller.rb +22 -0
- data/app/jobs/disco_app/concerns/app_installed_job.rb +21 -4
- data/app/jobs/disco_app/concerns/app_uninstalled_job.rb +2 -5
- data/app/jobs/disco_app/concerns/subscription_changed_job.rb +7 -0
- data/app/jobs/disco_app/subscription_changed_job.rb +3 -0
- data/app/models/disco_app/application_charge.rb +18 -0
- data/app/models/disco_app/concerns/plan.rb +13 -1
- data/app/models/disco_app/concerns/plan_code.rb +15 -0
- data/app/models/disco_app/concerns/shop.rb +10 -9
- data/app/models/disco_app/concerns/subscription.rb +36 -2
- data/app/models/disco_app/plan_code.rb +3 -0
- data/app/models/disco_app/recurring_application_charge.rb +18 -0
- data/app/services/disco_app/charges_service.rb +66 -58
- data/app/services/disco_app/subscription_service.rb +27 -15
- data/app/views/disco_app/admin/plans/_form.html.erb +27 -0
- data/app/views/disco_app/admin/plans/edit.html.erb +7 -0
- data/app/views/disco_app/admin/plans/index.html.erb +32 -0
- data/app/views/disco_app/admin/plans/new.html.erb +7 -0
- data/app/views/disco_app/charges/new.html.erb +9 -42
- data/app/views/disco_app/subscriptions/new.html.erb +25 -0
- data/app/views/layouts/admin/_navbar.html.erb +1 -0
- data/config/routes.rb +8 -5
- data/db/migrate/20160301223215_update_plans.rb +22 -0
- data/db/migrate/20160301224558_update_subscriptions.rb +13 -0
- data/db/migrate/20160302104816_create_disco_app_recurring_application_charges.rb +14 -0
- data/db/migrate/20160302105259_create_disco_app_application_charges.rb +14 -0
- data/db/migrate/20160302134728_drop_charge_status_from_shops.rb +5 -0
- data/db/migrate/20160302142941_add_shopify_attributes_to_charges.rb +8 -0
- data/db/migrate/20160331093148_create_disco_app_plan_codes.rb +14 -0
- data/db/migrate/20160401044420_add_status_to_plan_codes.rb +5 -0
- data/db/migrate/20160401045551_add_amount_and_plan_code_to_disco_app_subscriptions.rb +7 -0
- data/lib/disco_app/configuration.rb +6 -0
- data/lib/disco_app/version.rb +1 -1
- data/lib/generators/disco_app/reactify/reactify_generator.rb +1 -1
- data/lib/generators/disco_app/templates/initializers/disco_app.rb +9 -4
- data/test/controllers/disco_app/charges_controller_test.rb +91 -0
- data/test/controllers/disco_app/subscriptions_controller_test.rb +73 -0
- data/test/controllers/home_controller_test.rb +37 -6
- data/test/dummy/app/jobs/disco_app/app_installed_job.rb +16 -0
- data/test/dummy/config/initializers/disco_app.rb +9 -4
- data/test/dummy/db/schema.rb +54 -14
- data/test/fixtures/api/widget_store/charges/activate_application_charge_request.json +16 -0
- data/test/fixtures/api/widget_store/charges/activate_application_charge_response.json +1 -0
- data/test/fixtures/api/widget_store/charges/activate_recurring_application_charge_request.json +20 -0
- data/test/fixtures/api/widget_store/charges/activate_recurring_application_charge_response.json +1 -0
- data/test/fixtures/api/widget_store/charges/create_application_charge_request.json +9 -0
- data/test/fixtures/api/widget_store/charges/create_application_charge_response.json +16 -0
- data/test/fixtures/api/widget_store/charges/create_recurring_application_charge_request.json +9 -0
- data/test/fixtures/api/widget_store/charges/create_recurring_application_charge_response.json +20 -0
- data/test/fixtures/api/widget_store/charges/create_second_recurring_application_charge_request.json +9 -0
- data/test/fixtures/api/widget_store/charges/create_second_recurring_application_charge_response.json +20 -0
- data/test/fixtures/api/widget_store/charges/get_accepted_application_charge_response.json +16 -0
- data/test/fixtures/api/widget_store/charges/get_accepted_recurring_application_charge_response.json +20 -0
- data/test/fixtures/api/widget_store/charges/get_declined_application_charge_response.json +16 -0
- data/test/fixtures/api/widget_store/charges/get_declined_recurring_application_charge_response.json +20 -0
- data/test/fixtures/api/widget_store/charges/get_pending_application_charge_response.json +16 -0
- data/test/fixtures/api/widget_store/charges/get_pending_recurring_application_charge_response.json +20 -0
- data/test/fixtures/disco_app/application_charges.yml +11 -0
- data/test/fixtures/disco_app/plan_codes.yml +6 -0
- data/test/fixtures/disco_app/plans.yml +23 -18
- data/test/fixtures/disco_app/recurring_application_charges.yml +11 -0
- data/test/fixtures/disco_app/subscriptions.yml +12 -17
- data/test/jobs/disco_app/app_installed_job_test.rb +17 -5
- data/test/jobs/disco_app/app_uninstalled_job_test.rb +0 -2
- data/test/models/disco_app/shop_test.rb +3 -2
- data/test/services/disco_app/charges_service_test.rb +104 -0
- data/test/services/disco_app/subscription_service_test.rb +39 -8
- data/test/support/test_file_fixtures.rb +1 -1
- data/test/support/test_shopify_api.rb +16 -0
- data/test/test_helper.rb +1 -0
- metadata +73 -3
- data/test/models/disco_app/subscription_test.rb +0 -6
@@ -1,32 +1,37 @@
|
|
1
1
|
development:
|
2
|
-
|
2
|
+
id: 1
|
3
3
|
name: Development
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
plan_type: 0
|
5
|
+
trial_period_days: 0
|
6
|
+
amount: 0
|
7
7
|
|
8
8
|
comped:
|
9
|
-
status: 2
|
10
9
|
name: Comped
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
plan_type: 0
|
11
|
+
trial_period_days: 0
|
12
|
+
amount: 0
|
13
|
+
|
14
|
+
lifetime:
|
15
|
+
name: Lifetime
|
16
|
+
plan_type: 1
|
17
|
+
trial_period_days: 0
|
18
|
+
amount: 4900
|
14
19
|
|
15
20
|
cheapo:
|
16
|
-
status: 1
|
17
21
|
name: Cheapo
|
18
|
-
|
19
|
-
|
20
|
-
|
22
|
+
status: <%= DiscoApp::Plan.statuses[:unavailable] %>
|
23
|
+
plan_type: 0
|
24
|
+
trial_period_days: 14
|
25
|
+
amount: 99
|
21
26
|
|
22
27
|
basic:
|
23
28
|
name: Basic
|
24
|
-
|
25
|
-
|
26
|
-
|
29
|
+
plan_type: 0
|
30
|
+
trial_period_days: 14
|
31
|
+
amount: 999
|
27
32
|
|
28
33
|
premium:
|
29
34
|
name: Premium
|
30
|
-
|
31
|
-
|
32
|
-
|
35
|
+
plan_type: 0
|
36
|
+
trial_period_days: 28
|
37
|
+
amount: 9999
|
@@ -0,0 +1,11 @@
|
|
1
|
+
current_widget_store_subscription_recurring_charge:
|
2
|
+
shop: widget_store
|
3
|
+
subscription: current_widget_store_subscription
|
4
|
+
status: <%= DiscoApp::RecurringApplicationCharge.statuses[:active] %>
|
5
|
+
|
6
|
+
new_widget_store_subscription_recurring_charge:
|
7
|
+
shop: widget_store
|
8
|
+
subscription: current_widget_store_subscription
|
9
|
+
status: <%= DiscoApp::RecurringApplicationCharge.statuses[:pending] %>
|
10
|
+
shopify_id: 654381179
|
11
|
+
confirmation_url: "https://apple.myshopify.com/admin/charges/654381179/confirm_recurring_application_charge?signature=BAhpBHsQASc%3D--b2e90c6e4e94fbae15a464c566a31a1c23e6bffa"
|
@@ -1,26 +1,21 @@
|
|
1
|
-
|
1
|
+
old_widget_store_subscription:
|
2
2
|
shop: widget_store
|
3
3
|
plan: cheapo
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
trial_days: 14
|
4
|
+
amount: 99
|
5
|
+
status: <%= DiscoApp::Subscription.statuses[:cancelled] %>
|
6
|
+
subscription_type: 0
|
7
|
+
cancelled_at: <%= 1.week.ago.to_s(:db) %>
|
9
8
|
|
10
|
-
|
9
|
+
current_widget_store_subscription:
|
11
10
|
shop: widget_store
|
12
11
|
plan: basic
|
12
|
+
amount: 999
|
13
13
|
status: <%= DiscoApp::Subscription.statuses[:active] %>
|
14
|
-
|
15
|
-
charge_type: 0
|
16
|
-
price: 9.99
|
17
|
-
trial_days: 14
|
14
|
+
subscription_type: 0
|
18
15
|
|
19
|
-
|
16
|
+
current_widget_store_dev_subscription:
|
20
17
|
shop: widget_store_dev
|
21
|
-
plan:
|
18
|
+
plan: lifetime
|
19
|
+
amount: 4900
|
22
20
|
status: <%= DiscoApp::Subscription.statuses[:active] %>
|
23
|
-
|
24
|
-
charge_type: 0
|
25
|
-
price: 0.00
|
26
|
-
trial_days: 0
|
21
|
+
subscription_type: 1
|
@@ -5,26 +5,38 @@ class DiscoApp::AppInstalledJobTest < ActionController::TestCase
|
|
5
5
|
|
6
6
|
def setup
|
7
7
|
@shop = disco_app_shops(:widget_store)
|
8
|
+
|
9
|
+
stub_request(:get, "#{@shop.admin_url}/webhooks.json").to_return(status: 200, body: api_fixture('widget_store/webhooks').to_json)
|
10
|
+
stub_request(:post, "#{@shop.admin_url}/webhooks.json").to_return(status: 200)
|
11
|
+
stub_request(:get, "#{@shop.admin_url}/shop.json").to_return(status: 200, body: api_fixture('widget_store/shop').to_json)
|
8
12
|
end
|
9
13
|
|
10
14
|
def teardown
|
11
15
|
@shop = nil
|
16
|
+
|
17
|
+
WebMock.reset!
|
12
18
|
end
|
13
19
|
|
14
20
|
test 'app installed job performs shop update job' do
|
15
|
-
stub_request(:get, "#{@shop.admin_url}/webhooks.json").to_return(status: 200, body: api_fixture('widget_store/webhooks'))
|
16
|
-
stub_request(:post, "#{@shop.admin_url}/webhooks.json").to_return(status: 200)
|
17
|
-
stub_request(:get, "#{@shop.admin_url}/shop.json").to_return(status: 200, body: api_fixture('widget_store/shop'))
|
18
|
-
|
19
21
|
# Assert the main install job can be enqueued and performed.
|
20
22
|
perform_enqueued_jobs do
|
21
23
|
DiscoApp::AppInstalledJob.perform_later(@shop.shopify_domain)
|
22
24
|
end
|
23
|
-
assert_performed_jobs 1
|
24
25
|
|
25
26
|
# Assert the update shop job was performed.
|
26
27
|
@shop.reload
|
27
28
|
assert_equal 'United States', @shop.country_name
|
28
29
|
end
|
29
30
|
|
31
|
+
test 'app installed job automatically subscribes stores to the correct default plan' do
|
32
|
+
@shop.current_subscription.destroy
|
33
|
+
|
34
|
+
perform_enqueued_jobs do
|
35
|
+
DiscoApp::AppInstalledJob.perform_later(@shop.shopify_domain)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Assert the shop was subscribed to the development plan.
|
39
|
+
assert_equal disco_app_plans(:development), @shop.current_subscription.plan
|
40
|
+
end
|
41
|
+
|
30
42
|
end
|
@@ -5,7 +5,6 @@ class DiscoApp::AppUninstalledJobTest < ActionController::TestCase
|
|
5
5
|
|
6
6
|
def setup
|
7
7
|
@shop = disco_app_shops(:widget_store)
|
8
|
-
@shop.charge_active!
|
9
8
|
|
10
9
|
perform_enqueued_jobs do
|
11
10
|
DiscoApp::AppUninstalledJob.perform_later(@shop.shopify_domain, {})
|
@@ -25,7 +24,6 @@ class DiscoApp::AppUninstalledJobTest < ActionController::TestCase
|
|
25
24
|
test 'app uninstalled job can be extended using concerns' do
|
26
25
|
assert_performed_jobs 1
|
27
26
|
@shop.reload
|
28
|
-
assert @shop.charge_cancelled? # Assert base methods still called.
|
29
27
|
assert_equal 'Nowhere', @shop.country_name # Assert extended method called.
|
30
28
|
end
|
31
29
|
|
@@ -18,9 +18,10 @@ class DiscoApp::ShopTest < ActiveSupport::TestCase
|
|
18
18
|
assert_equal 2, @shop.subscriptions.size
|
19
19
|
end
|
20
20
|
|
21
|
-
test 'can fetch a shops
|
21
|
+
test 'can fetch a shops current subscription' do
|
22
22
|
assert_equal 1, @shop.subscriptions.active.size
|
23
|
-
|
23
|
+
assert @shop.current_subscription?
|
24
|
+
assert_equal disco_app_subscriptions(:current_widget_store_subscription), @shop.current_subscription
|
24
25
|
end
|
25
26
|
|
26
27
|
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DiscoApp::ChargesServiceTest < ActiveSupport::TestCase
|
4
|
+
include DiscoApp::Test::ShopifyAPI
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@shop = disco_app_shops(:widget_store)
|
8
|
+
@subscription = disco_app_subscriptions(:current_widget_store_subscription)
|
9
|
+
@new_charge = disco_app_recurring_application_charges(:new_widget_store_subscription_recurring_charge)
|
10
|
+
|
11
|
+
@dev_shop = disco_app_shops(:widget_store_dev)
|
12
|
+
@dev_subscription = disco_app_subscriptions(:current_widget_store_dev_subscription)
|
13
|
+
@dev_new_charge = disco_app_application_charges(:new_widget_store_dev_subscription_one_time_charge)
|
14
|
+
|
15
|
+
Timecop.freeze
|
16
|
+
end
|
17
|
+
|
18
|
+
def teardown
|
19
|
+
@shop = nil
|
20
|
+
@subscription = nil
|
21
|
+
@new_charge = nil
|
22
|
+
|
23
|
+
@dev_shop = nil
|
24
|
+
@dev_subscription = nil
|
25
|
+
@dev_new_charge = nil
|
26
|
+
|
27
|
+
Timecop.return
|
28
|
+
|
29
|
+
WebMock.reset!
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'creating a new charge for a recurring subscription is successful' do
|
33
|
+
stub_api_request(:post, "#{@shop.admin_url}/recurring_application_charges.json", 'widget_store/charges/create_recurring_application_charge')
|
34
|
+
|
35
|
+
new_charge = DiscoApp::ChargesService.create(@shop, @subscription)
|
36
|
+
assert_equal 654381179, new_charge.shopify_id
|
37
|
+
assert_equal 'https://apple.myshopify.com/admin/charges/654381179/confirm_recurring_application_charge?signature=BAhpBHsQASc%3D--b2e90c6e4e94fbae15a464c566a31a1c23e6bffa', new_charge.confirmation_url
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'activating a pending recurring charge is not successful' do
|
41
|
+
stub_api_request(:get, "#{@shop.admin_url}/recurring_application_charges/654381179.json", 'widget_store/charges/get_pending_recurring_application_charge')
|
42
|
+
assert_not DiscoApp::ChargesService.activate(@shop, @new_charge)
|
43
|
+
assert @new_charge.pending?
|
44
|
+
end
|
45
|
+
|
46
|
+
test 'activating a declined recurring charge is not successful' do
|
47
|
+
stub_api_request(:get, "#{@shop.admin_url}/recurring_application_charges/654381179.json", 'widget_store/charges/get_declined_recurring_application_charge')
|
48
|
+
assert_not DiscoApp::ChargesService.activate(@shop, @new_charge)
|
49
|
+
assert @new_charge.declined?
|
50
|
+
end
|
51
|
+
|
52
|
+
test 'activating an accepted recurring charge is successful and cancels any existing recurring charges' do
|
53
|
+
stub_api_request(:get, "#{@shop.admin_url}/recurring_application_charges/654381179.json", 'widget_store/charges/get_accepted_recurring_application_charge')
|
54
|
+
stub_api_request(:post, "#{@shop.admin_url}/recurring_application_charges/654381179/activate.json", 'widget_store/charges/activate_recurring_application_charge')
|
55
|
+
|
56
|
+
old_charge = @subscription.active_charge
|
57
|
+
assert old_charge.active?
|
58
|
+
|
59
|
+
assert DiscoApp::ChargesService.activate(@shop, @new_charge)
|
60
|
+
assert @new_charge.active?
|
61
|
+
|
62
|
+
old_charge.reload
|
63
|
+
assert old_charge.cancelled?
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'activating an accepted recurring charge cancels other recurring charges' do
|
67
|
+
stub_api_request(:get, "#{@shop.admin_url}/recurring_application_charges/654381179.json", 'widget_store/charges/get_accepted_recurring_application_charge')
|
68
|
+
stub_api_request(:post, "#{@shop.admin_url}/recurring_application_charges/654381179/activate.json", 'widget_store/charges/activate_recurring_application_charge')
|
69
|
+
|
70
|
+
assert DiscoApp::ChargesService.activate(@shop, @new_charge)
|
71
|
+
assert @new_charge.active?
|
72
|
+
end
|
73
|
+
|
74
|
+
test 'creating a new charge for a one-time subscription is successful' do
|
75
|
+
stub_api_request(:post, "#{@dev_shop.admin_url}/application_charges.json", 'widget_store/charges/create_application_charge')
|
76
|
+
|
77
|
+
new_charge = DiscoApp::ChargesService.create(@dev_shop, @dev_subscription)
|
78
|
+
assert_equal 1012637323, new_charge.shopify_id
|
79
|
+
assert_equal 'https://apple.myshopify.com/admin/charges/1012637323/confirm_application_charge?signature=BAhpBIueWzw%3D--0ea1abacaf9d6fd538b7e9a7023e9b71ce1c7e98', new_charge.confirmation_url
|
80
|
+
end
|
81
|
+
|
82
|
+
test 'activating a pending one-time charge is not successful' do
|
83
|
+
stub_api_request(:get, "#{@dev_shop.admin_url}/application_charges/1012637323.json", 'widget_store/charges/get_pending_application_charge')
|
84
|
+
|
85
|
+
assert_not DiscoApp::ChargesService.activate(@dev_shop, @dev_new_charge)
|
86
|
+
assert @dev_new_charge.pending?
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'activating a declined one-time charge is not successful' do
|
90
|
+
stub_api_request(:get, "#{@dev_shop.admin_url}/application_charges/1012637323.json", 'widget_store/charges/get_declined_application_charge')
|
91
|
+
|
92
|
+
assert_not DiscoApp::ChargesService.activate(@dev_shop, @dev_new_charge)
|
93
|
+
assert @dev_new_charge.declined?
|
94
|
+
end
|
95
|
+
|
96
|
+
test 'activating an accepted one-time charge is successful' do
|
97
|
+
stub_api_request(:get, "#{@dev_shop.admin_url}/application_charges/1012637323.json", 'widget_store/charges/get_accepted_application_charge')
|
98
|
+
stub_api_request(:post, "#{@dev_shop.admin_url}/application_charges/1012637323/activate.json", 'widget_store/charges/activate_application_charge')
|
99
|
+
|
100
|
+
assert DiscoApp::ChargesService.activate(@dev_shop, @dev_new_charge)
|
101
|
+
assert @dev_new_charge.active?
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
@@ -1,28 +1,59 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class DiscoApp::SubscriptionServiceTest < ActiveSupport::TestCase
|
4
|
+
include ActiveJob::TestHelper
|
4
5
|
|
5
6
|
def setup
|
6
7
|
@shop = disco_app_shops(:widget_store)
|
7
|
-
@
|
8
|
+
@subscription = disco_app_subscriptions(:current_widget_store_subscription)
|
9
|
+
Timecop.freeze
|
8
10
|
end
|
9
11
|
|
10
12
|
def teardown
|
11
13
|
@shop = nil
|
14
|
+
@subscription = nil
|
15
|
+
Timecop.return
|
12
16
|
end
|
13
17
|
|
14
18
|
test 'subscribing to a new plan deactivates current subscription and swaps to new plan' do
|
15
19
|
DiscoApp::SubscriptionService.subscribe(@shop, disco_app_plans(:premium))
|
16
|
-
@
|
17
|
-
assert @
|
20
|
+
@subscription.reload
|
21
|
+
assert @subscription.cancelled?
|
18
22
|
assert_equal disco_app_plans(:premium), @shop.current_subscription.plan
|
19
23
|
end
|
20
24
|
|
21
|
-
test '
|
22
|
-
DiscoApp::
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
test 'subscribing to a new plan enqueues subscription changed background job' do
|
26
|
+
assert_enqueued_with(job: DiscoApp::SubscriptionChangedJob) do
|
27
|
+
DiscoApp::SubscriptionService.subscribe(@shop, disco_app_plans(:premium))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'subscribing to a new plan works for a shop without a subscription' do
|
32
|
+
@subscription.destroy
|
33
|
+
DiscoApp::SubscriptionService.subscribe(@shop, disco_app_plans(:premium))
|
34
|
+
assert_equal disco_app_plans(:premium), @shop.current_subscription.plan
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'new subscription for a plan without a trial period created correctly' do
|
38
|
+
new_subscription = DiscoApp::SubscriptionService.subscribe(@shop, disco_app_plans(:comped))
|
39
|
+
assert new_subscription.active?
|
40
|
+
assert_equal nil, new_subscription.trial_start_at
|
41
|
+
assert_equal nil, new_subscription.trial_end_at
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'new subscription for a plan with a trial period created correctly' do
|
45
|
+
new_subscription = DiscoApp::SubscriptionService.subscribe(@shop, disco_app_plans(:premium))
|
46
|
+
assert new_subscription.trial?
|
47
|
+
assert_equal Time.now, new_subscription.trial_start_at
|
48
|
+
assert_equal 28.days.from_now, new_subscription.trial_end_at
|
49
|
+
end
|
50
|
+
|
51
|
+
test 'new subscription for a plan with a plan code created correctly' do
|
52
|
+
new_subscription = DiscoApp::SubscriptionService.subscribe(@shop, disco_app_plans(:premium), disco_app_plan_codes(:podcast))
|
53
|
+
assert new_subscription.trial?
|
54
|
+
assert_equal Time.now, new_subscription.trial_start_at
|
55
|
+
assert_equal 60.days.from_now, new_subscription.trial_end_at
|
56
|
+
assert_equal 8999, new_subscription.amount
|
26
57
|
end
|
27
58
|
|
28
59
|
end
|
@@ -16,7 +16,7 @@ module DiscoApp::Test
|
|
16
16
|
# API fixtures are special-case JSON fixtures.
|
17
17
|
def api_fixture(path)
|
18
18
|
filename = File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'api', "#{path}.json")
|
19
|
-
File.read(filename)
|
19
|
+
HashWithIndifferentAccess.new(ActiveSupport::JSON.decode(File.read(filename)))
|
20
20
|
end
|
21
21
|
|
22
22
|
# Webhook fixtures are special-case JSON fixtures.
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module DiscoApp::Test
|
2
|
+
module ShopifyAPI
|
3
|
+
|
4
|
+
def stub_api_request(method, endpoint, fixture_name)
|
5
|
+
if method == :get
|
6
|
+
stub_request(method, endpoint)
|
7
|
+
.to_return(status: 200, body: api_fixture("#{fixture_name}_response").to_json)
|
8
|
+
elsif method == :post
|
9
|
+
stub_request(method, endpoint)
|
10
|
+
.with(body: api_fixture("#{fixture_name}_request").to_json)
|
11
|
+
.to_return(status: 201, body: api_fixture("#{fixture_name}_response").to_json)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: disco_app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Ballard
|
@@ -316,7 +316,9 @@ files:
|
|
316
316
|
- app/controllers/disco_app/admin/application_controller.rb
|
317
317
|
- app/controllers/disco_app/admin/concerns/app_settings_controller.rb
|
318
318
|
- app/controllers/disco_app/admin/concerns/authenticated_controller.rb
|
319
|
+
- app/controllers/disco_app/admin/concerns/plans_controller.rb
|
319
320
|
- app/controllers/disco_app/admin/concerns/shops_controller.rb
|
321
|
+
- app/controllers/disco_app/admin/plans_controller.rb
|
320
322
|
- app/controllers/disco_app/admin/resources/shops_controller.rb
|
321
323
|
- app/controllers/disco_app/admin/shops_controller.rb
|
322
324
|
- app/controllers/disco_app/charges_controller.rb
|
@@ -325,26 +327,34 @@ files:
|
|
325
327
|
- app/controllers/disco_app/concerns/carrier_request_controller.rb
|
326
328
|
- app/controllers/disco_app/frame_controller.rb
|
327
329
|
- app/controllers/disco_app/install_controller.rb
|
330
|
+
- app/controllers/disco_app/subscriptions_controller.rb
|
328
331
|
- app/controllers/disco_app/webhooks_controller.rb
|
332
|
+
- app/controllers/sessions_controller.rb
|
329
333
|
- app/helpers/disco_app/application_helper.rb
|
330
334
|
- app/jobs/disco_app/app_installed_job.rb
|
331
335
|
- app/jobs/disco_app/app_uninstalled_job.rb
|
332
336
|
- app/jobs/disco_app/concerns/app_installed_job.rb
|
333
337
|
- app/jobs/disco_app/concerns/app_uninstalled_job.rb
|
334
338
|
- app/jobs/disco_app/concerns/shop_update_job.rb
|
339
|
+
- app/jobs/disco_app/concerns/subscription_changed_job.rb
|
335
340
|
- app/jobs/disco_app/concerns/synchronise_carrier_service_job.rb
|
336
341
|
- app/jobs/disco_app/concerns/synchronise_webhooks_job.rb
|
337
342
|
- app/jobs/disco_app/shop_job.rb
|
338
343
|
- app/jobs/disco_app/shop_update_job.rb
|
344
|
+
- app/jobs/disco_app/subscription_changed_job.rb
|
339
345
|
- app/jobs/disco_app/synchronise_carrier_service_job.rb
|
340
346
|
- app/jobs/disco_app/synchronise_webhooks_job.rb
|
341
347
|
- app/models/disco_app/app_settings.rb
|
348
|
+
- app/models/disco_app/application_charge.rb
|
342
349
|
- app/models/disco_app/concerns/app_settings.rb
|
343
350
|
- app/models/disco_app/concerns/plan.rb
|
351
|
+
- app/models/disco_app/concerns/plan_code.rb
|
344
352
|
- app/models/disco_app/concerns/shop.rb
|
345
353
|
- app/models/disco_app/concerns/subscription.rb
|
346
354
|
- app/models/disco_app/concerns/synchronises.rb
|
347
355
|
- app/models/disco_app/plan.rb
|
356
|
+
- app/models/disco_app/plan_code.rb
|
357
|
+
- app/models/disco_app/recurring_application_charge.rb
|
348
358
|
- app/models/disco_app/session_storage.rb
|
349
359
|
- app/models/disco_app/shop.rb
|
350
360
|
- app/models/disco_app/subscription.rb
|
@@ -356,6 +366,10 @@ files:
|
|
356
366
|
- app/services/disco_app/subscription_service.rb
|
357
367
|
- app/services/disco_app/webhook_service.rb
|
358
368
|
- app/views/disco_app/admin/app_settings/edit.html.erb
|
369
|
+
- app/views/disco_app/admin/plans/_form.html.erb
|
370
|
+
- app/views/disco_app/admin/plans/edit.html.erb
|
371
|
+
- app/views/disco_app/admin/plans/index.html.erb
|
372
|
+
- app/views/disco_app/admin/plans/new.html.erb
|
359
373
|
- app/views/disco_app/admin/shops/index.html.erb
|
360
374
|
- app/views/disco_app/charges/activate.html.erb
|
361
375
|
- app/views/disco_app/charges/create.html.erb
|
@@ -366,6 +380,7 @@ files:
|
|
366
380
|
- app/views/disco_app/proxy_errors/404.html.erb
|
367
381
|
- app/views/disco_app/shared/_card.html.erb
|
368
382
|
- app/views/disco_app/shared/_section.html.erb
|
383
|
+
- app/views/disco_app/subscriptions/new.html.erb
|
369
384
|
- app/views/layouts/admin.html.erb
|
370
385
|
- app/views/layouts/admin/_navbar.html.erb
|
371
386
|
- app/views/layouts/application.html.erb
|
@@ -384,6 +399,15 @@ files:
|
|
384
399
|
- db/migrate/20160112233706_create_disco_app_sessions.rb
|
385
400
|
- db/migrate/20160113194418_add_shop_id_to_disco_app_sessions.rb
|
386
401
|
- db/migrate/20160223111044_create_disco_app_settings.rb
|
402
|
+
- db/migrate/20160301223215_update_plans.rb
|
403
|
+
- db/migrate/20160301224558_update_subscriptions.rb
|
404
|
+
- db/migrate/20160302104816_create_disco_app_recurring_application_charges.rb
|
405
|
+
- db/migrate/20160302105259_create_disco_app_application_charges.rb
|
406
|
+
- db/migrate/20160302134728_drop_charge_status_from_shops.rb
|
407
|
+
- db/migrate/20160302142941_add_shopify_attributes_to_charges.rb
|
408
|
+
- db/migrate/20160331093148_create_disco_app_plan_codes.rb
|
409
|
+
- db/migrate/20160401044420_add_status_to_plan_codes.rb
|
410
|
+
- db/migrate/20160401045551_add_amount_and_plan_code_to_disco_app_subscriptions.rb
|
387
411
|
- lib/disco_app.rb
|
388
412
|
- lib/disco_app/configuration.rb
|
389
413
|
- lib/disco_app/engine.rb
|
@@ -414,7 +438,9 @@ files:
|
|
414
438
|
- lib/tasks/start.rake
|
415
439
|
- lib/tasks/webhooks.rake
|
416
440
|
- test/controllers/disco_app/admin/shops_controller_test.rb
|
441
|
+
- test/controllers/disco_app/charges_controller_test.rb
|
417
442
|
- test/controllers/disco_app/install_controller_test.rb
|
443
|
+
- test/controllers/disco_app/subscriptions_controller_test.rb
|
418
444
|
- test/controllers/disco_app/webhooks_controller_test.rb
|
419
445
|
- test/controllers/home_controller_test.rb
|
420
446
|
- test/controllers/proxy_controller_test.rb
|
@@ -427,6 +453,7 @@ files:
|
|
427
453
|
- test/dummy/app/controllers/home_controller.rb
|
428
454
|
- test/dummy/app/controllers/proxy_controller.rb
|
429
455
|
- test/dummy/app/helpers/application_helper.rb
|
456
|
+
- test/dummy/app/jobs/disco_app/app_installed_job.rb
|
430
457
|
- test/dummy/app/jobs/disco_app/app_uninstalled_job.rb
|
431
458
|
- test/dummy/app/jobs/products_create_job.rb
|
432
459
|
- test/dummy/app/jobs/products_delete_job.rb
|
@@ -468,9 +495,28 @@ files:
|
|
468
495
|
- test/dummy/public/422.html
|
469
496
|
- test/dummy/public/500.html
|
470
497
|
- test/dummy/public/favicon.ico
|
498
|
+
- test/fixtures/api/widget_store/charges/activate_application_charge_request.json
|
499
|
+
- test/fixtures/api/widget_store/charges/activate_application_charge_response.json
|
500
|
+
- test/fixtures/api/widget_store/charges/activate_recurring_application_charge_request.json
|
501
|
+
- test/fixtures/api/widget_store/charges/activate_recurring_application_charge_response.json
|
502
|
+
- test/fixtures/api/widget_store/charges/create_application_charge_request.json
|
503
|
+
- test/fixtures/api/widget_store/charges/create_application_charge_response.json
|
504
|
+
- test/fixtures/api/widget_store/charges/create_recurring_application_charge_request.json
|
505
|
+
- test/fixtures/api/widget_store/charges/create_recurring_application_charge_response.json
|
506
|
+
- test/fixtures/api/widget_store/charges/create_second_recurring_application_charge_request.json
|
507
|
+
- test/fixtures/api/widget_store/charges/create_second_recurring_application_charge_response.json
|
508
|
+
- test/fixtures/api/widget_store/charges/get_accepted_application_charge_response.json
|
509
|
+
- test/fixtures/api/widget_store/charges/get_accepted_recurring_application_charge_response.json
|
510
|
+
- test/fixtures/api/widget_store/charges/get_declined_application_charge_response.json
|
511
|
+
- test/fixtures/api/widget_store/charges/get_declined_recurring_application_charge_response.json
|
512
|
+
- test/fixtures/api/widget_store/charges/get_pending_application_charge_response.json
|
513
|
+
- test/fixtures/api/widget_store/charges/get_pending_recurring_application_charge_response.json
|
471
514
|
- test/fixtures/api/widget_store/shop.json
|
472
515
|
- test/fixtures/api/widget_store/webhooks.json
|
516
|
+
- test/fixtures/disco_app/application_charges.yml
|
517
|
+
- test/fixtures/disco_app/plan_codes.yml
|
473
518
|
- test/fixtures/disco_app/plans.yml
|
519
|
+
- test/fixtures/disco_app/recurring_application_charges.yml
|
474
520
|
- test/fixtures/disco_app/shops.yml
|
475
521
|
- test/fixtures/disco_app/subscriptions.yml
|
476
522
|
- test/fixtures/products.yml
|
@@ -484,9 +530,10 @@ files:
|
|
484
530
|
- test/models/disco_app/plan_test.rb
|
485
531
|
- test/models/disco_app/session_test.rb
|
486
532
|
- test/models/disco_app/shop_test.rb
|
487
|
-
- test/
|
533
|
+
- test/services/disco_app/charges_service_test.rb
|
488
534
|
- test/services/disco_app/subscription_service_test.rb
|
489
535
|
- test/support/test_file_fixtures.rb
|
536
|
+
- test/support/test_shopify_api.rb
|
490
537
|
- test/test_helper.rb
|
491
538
|
homepage: https://github.com/discolabs/disco_app/
|
492
539
|
licenses:
|
@@ -527,6 +574,7 @@ test_files:
|
|
527
574
|
- test/dummy/app/assets/javascripts/application.js
|
528
575
|
- test/dummy/app/jobs/products_create_job.rb
|
529
576
|
- test/dummy/app/jobs/products_update_job.rb
|
577
|
+
- test/dummy/app/jobs/disco_app/app_installed_job.rb
|
530
578
|
- test/dummy/app/jobs/disco_app/app_uninstalled_job.rb
|
531
579
|
- test/dummy/app/jobs/products_delete_job.rb
|
532
580
|
- test/dummy/app/controllers/home_controller.rb
|
@@ -563,16 +611,36 @@ test_files:
|
|
563
611
|
- test/dummy/config/database.yml
|
564
612
|
- test/dummy/config/application.rb
|
565
613
|
- test/fixtures/api/widget_store/webhooks.json
|
614
|
+
- test/fixtures/api/widget_store/charges/create_application_charge_response.json
|
615
|
+
- test/fixtures/api/widget_store/charges/create_second_recurring_application_charge_response.json
|
616
|
+
- test/fixtures/api/widget_store/charges/activate_application_charge_response.json
|
617
|
+
- test/fixtures/api/widget_store/charges/create_application_charge_request.json
|
618
|
+
- test/fixtures/api/widget_store/charges/create_recurring_application_charge_response.json
|
619
|
+
- test/fixtures/api/widget_store/charges/get_pending_recurring_application_charge_response.json
|
620
|
+
- test/fixtures/api/widget_store/charges/get_declined_recurring_application_charge_response.json
|
621
|
+
- test/fixtures/api/widget_store/charges/get_pending_application_charge_response.json
|
622
|
+
- test/fixtures/api/widget_store/charges/activate_recurring_application_charge_response.json
|
623
|
+
- test/fixtures/api/widget_store/charges/get_accepted_recurring_application_charge_response.json
|
624
|
+
- test/fixtures/api/widget_store/charges/activate_recurring_application_charge_request.json
|
625
|
+
- test/fixtures/api/widget_store/charges/get_accepted_application_charge_response.json
|
626
|
+
- test/fixtures/api/widget_store/charges/create_recurring_application_charge_request.json
|
627
|
+
- test/fixtures/api/widget_store/charges/get_declined_application_charge_response.json
|
628
|
+
- test/fixtures/api/widget_store/charges/create_second_recurring_application_charge_request.json
|
629
|
+
- test/fixtures/api/widget_store/charges/activate_application_charge_request.json
|
566
630
|
- test/fixtures/api/widget_store/shop.json
|
631
|
+
- test/fixtures/disco_app/plan_codes.yml
|
567
632
|
- test/fixtures/disco_app/shops.yml
|
633
|
+
- test/fixtures/disco_app/application_charges.yml
|
568
634
|
- test/fixtures/disco_app/subscriptions.yml
|
569
635
|
- test/fixtures/disco_app/plans.yml
|
636
|
+
- test/fixtures/disco_app/recurring_application_charges.yml
|
570
637
|
- test/fixtures/webhooks/app_uninstalled.json
|
571
638
|
- test/fixtures/webhooks/product_updated.json
|
572
639
|
- test/fixtures/webhooks/product_created.json
|
573
640
|
- test/fixtures/webhooks/product_deleted.json
|
574
641
|
- test/fixtures/products.yml
|
575
642
|
- test/support/test_file_fixtures.rb
|
643
|
+
- test/support/test_shopify_api.rb
|
576
644
|
- test/test_helper.rb
|
577
645
|
- test/disco_app_test.rb
|
578
646
|
- test/jobs/disco_app/app_uninstalled_job_test.rb
|
@@ -580,11 +648,13 @@ test_files:
|
|
580
648
|
- test/controllers/disco_app/install_controller_test.rb
|
581
649
|
- test/controllers/disco_app/webhooks_controller_test.rb
|
582
650
|
- test/controllers/disco_app/admin/shops_controller_test.rb
|
651
|
+
- test/controllers/disco_app/subscriptions_controller_test.rb
|
652
|
+
- test/controllers/disco_app/charges_controller_test.rb
|
583
653
|
- test/controllers/proxy_controller_test.rb
|
584
654
|
- test/controllers/home_controller_test.rb
|
585
655
|
- test/integration/synchronises_test.rb
|
586
656
|
- test/models/disco_app/plan_test.rb
|
587
657
|
- test/models/disco_app/shop_test.rb
|
588
658
|
- test/models/disco_app/session_test.rb
|
589
|
-
- test/
|
659
|
+
- test/services/disco_app/charges_service_test.rb
|
590
660
|
- test/services/disco_app/subscription_service_test.rb
|