FIX: set interval field correctly in object root for recurring plans. (#91)

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 jradosz@gmail.com

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
 

GitHub sha: 3ce422ffbe412c6c155b7b9f6f9e6a767e2e8412

This commit appears in #91 which was approved by CvX. It was merged by vinothkannans.