Add $0 transaction when activating via Google Play

Stephen Paul Weber created

Change summary

lib/registration.rb       | 14 +++++++++++++-
test/test_registration.rb |  2 ++
2 files changed, 15 insertions(+), 1 deletion(-)

Detailed changes

lib/registration.rb 🔗

@@ -181,9 +181,21 @@ class Registration
 
 		protected
 
+			def save_bogus_transaction
+				Transaction.new(
+					customer_id: @customer.customer_id,
+					transaction_id: "google_play_#{@customer.customer_id}",
+					amount: 0,
+					note: "Activated via Google Play",
+					bonus_eligible?: false
+				).insert
+			end
+
 			def save_active_plan(plan, parent)
 				@customer = @customer.with_plan(plan.name, parent_customer_id: parent)
-				@customer.activate_plan_starting_now
+				save_bogus_transaction.then do
+					@customer.activate_plan_starting_now
+				end
 			end
 
 			def use_referral_code(code)

test/test_registration.rb 🔗

@@ -516,6 +516,7 @@ class RegistrationTest < Minitest::Test
 				OpenStruct.new(cmd_tuples: 0),
 				[String, ["test"]]
 			)
+			Transaction::DB.expect(:transaction, true, [])
 			Registration::Activation::GooglePlay::Finish.expect(
 				:new,
 				OpenStruct.new(write: EMPromise.reject(:test_result)),
@@ -525,6 +526,7 @@ class RegistrationTest < Minitest::Test
 			assert_equal :test_result, result
 			assert_mock Command::COMMAND_MANAGER
 			assert_mock CustomerPlan::DB
+			assert_mock Transaction::DB
 			assert_mock Registration::Activation::GooglePlay::Finish
 		end
 		em :test_write