spec/integration/braintree/subscription_spec.rb in braintree-2.6.3 vs spec/integration/braintree/subscription_spec.rb in braintree-2.7.0

- old
+ new

@@ -518,10 +518,46 @@ result.success?.should == false result.errors.for(:subscription).for(:add_ons).for(:update).for_index(0).on(:amount)[0].code.should == Braintree::ErrorCodes::Subscription::Modification::AmountIsInvalid result.errors.for(:subscription).for(:add_ons).for(:update).for_index(1).on(:quantity)[0].code.should == Braintree::ErrorCodes::Subscription::Modification::QuantityIsInvalid end end + + context "descriptors" do + it "accepts name and phone and copies them to the transaction" do + result = Braintree::Subscription.create( + :payment_method_token => @credit_card.token, + :plan_id => SpecHelper::TriallessPlan[:id], + :descriptor => { + :name => '123*123456789012345678', + :phone => '3334445555' + } + ) + + result.success?.should == true + result.subscription.descriptor.name.should == '123*123456789012345678' + result.subscription.descriptor.phone.should == '3334445555' + + result.subscription.transactions.size.should == 1 + transaction = result.subscription.transactions.first + transaction.descriptor.name.should == '123*123456789012345678' + transaction.descriptor.phone.should == '3334445555' + end + + it "has validation errors if format is invalid" do + result = Braintree::Subscription.create( + :payment_method_token => @credit_card.token, + :plan_id => SpecHelper::TriallessPlan[:id], + :descriptor => { + :name => 'badcompanyname12*badproduct12', + :phone => '%bad4445555' + } + ) + result.success?.should == false + result.errors.for(:subscription).for(:descriptor).on(:name)[0].code.should == Braintree::ErrorCodes::Descriptor::NameFormatIsInvalid + result.errors.for(:subscription).for(:descriptor).on(:phone)[0].code.should == Braintree::ErrorCodes::Descriptor::PhoneFormatIsInvalid + end + end end describe "self.create!" do it "returns the subscription if valid" do subscription = Braintree::Subscription.create!( @@ -602,9 +638,22 @@ result = Braintree::Subscription.update(@subscription.id, :payment_method_token => new_credit_card.token ) result.subscription.payment_method_token.should == new_credit_card.token + end + + it "allows chaning the descriptors" do + result = Braintree::Subscription.update(@subscription.id, + :descriptor => { + :name => 'aaa*1234', + :phone => '3334443333' + } + ) + + result.success?.should == true + result.subscription.descriptor.name.should == 'aaa*1234' + result.subscription.descriptor.phone.should == '3334443333' end context "when successful" do it "returns a success response with the updated subscription if valid" do new_id = rand(36**9).to_s(36)