From 56ce8534f7ec971faebb7d863aebf71129cefd71 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 17 May 2021 12:34:22 -0500 Subject: [PATCH] Already activated user goes straight to finish If not registered, but activated, they must have paid but failed to get their number setup. Maybe the number was already taken. Maybe they paid manually. In any case we can skip all intervening steps and go straight to buying and configuring their number for them. --- lib/registration.rb | 14 ++++++++------ test/test_registration.rb | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/registration.rb b/lib/registration.rb index bb5d02b..2f5d789 100644 --- a/lib/registration.rb +++ b/lib/registration.rb @@ -4,8 +4,6 @@ require_relative "./oob" class Registration def self.for(iq, customer, web_register_manager) - raise "TODO" if customer&.active? - EMPromise.resolve(customer&.registered?).then do |registered| if registered Registered.new(iq, registered.phone) @@ -36,10 +34,14 @@ class Registration class Activation def self.for(iq, customer, tel) - return EMPromise.resolve(new(iq, customer, tel)) if customer - - # Create customer_id - raise "TODO" + if customer&.active? + Finish.new(iq, customer, tel) + elsif customer + EMPromise.resolve(new(iq, customer, tel)) + else + # Create customer_id + raise "TODO" + end end def initialize(iq, customer, tel) diff --git a/test/test_registration.rb b/test/test_registration.rb index 3b88760..d0ef512 100644 --- a/test/test_registration.rb +++ b/test/test_registration.rb @@ -5,9 +5,21 @@ require "registration" class RegistrationTest < Minitest::Test def test_for_activated - skip "Registration#for activated not implemented yet" + BACKEND_SGX.expect( + :registered?, + EMPromise.resolve(nil), + ["test"] + ) + web_manager = WebRegisterManager.new + web_manager["test@example.com"] = "+15555550000" iq = Blather::Stanza::Iq::Command.new - Registration.for(iq, Customer.new("test"), Minitest::Mock.new).sync + iq.from = "test@example.com" + result = Registration.for( + iq, + Customer.new("test", plan_name: "test_usd", expires_at: Time.now + 999), + web_manager + ).sync + assert_kind_of Registration::Finish, result end em :test_for_activated -- 2.38.5