From 3ce422ffbe412c6c155b7b9f6f9e6a767e2e8412 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Tue, 21 Sep 2021 18:12:17 +0530 Subject: [PATCH] FIX: set interval field correctly in object root for recurring plans. (#91) The interval field was missing in the Ember object since it was only available inside the nested object. Co-authored-by: Jarek Radosz --- .../discourse_subscriptions/admin/plans_controller.rb | 4 +++- spec/requests/admin/plans_controller_spec.rb | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/discourse_subscriptions/admin/plans_controller.rb b/app/controllers/discourse_subscriptions/admin/plans_controller.rb index 2326f62..b66f648 100644 --- a/app/controllers/discourse_subscriptions/admin/plans_controller.rb +++ b/app/controllers/discourse_subscriptions/admin/plans_controller.rb @@ -55,7 +55,9 @@ module DiscourseSubscriptions trial_days = plan[:recurring][:trial_period_days] end - serialized = plan.to_h.merge(trial_period_days: trial_days, currency: plan[:currency].upcase) + interval = plan.dig(:recurring, :interval) + + serialized = plan.to_h.merge(trial_period_days: trial_days, currency: plan[:currency].upcase, interval: interval) render_json_dump serialized diff --git a/spec/requests/admin/plans_controller_spec.rb b/spec/requests/admin/plans_controller_spec.rb index d5b619b..d919f01 100644 --- a/spec/requests/admin/plans_controller_spec.rb +++ b/spec/requests/admin/plans_controller_spec.rb @@ -79,9 +79,12 @@ module DiscourseSubscriptions end it "upcases the currency" do - ::Stripe::Price.expects(:retrieve).with('plan_12345').returns(currency: 'aud') + ::Stripe::Price.expects(:retrieve).with('plan_12345').returns(currency: 'aud', recurring: { interval: 'year' }) get "/s/admin/plans/plan_12345.json" - expect(response.parsed_body["currency"]).to eq 'AUD' + + plan = response.parsed_body + expect(plan["currency"]).to eq 'AUD' + expect(plan["interval"]).to eq 'year' end end