@@ -5,28 +5,44 @@ module Payola
55 let ( :stripe_helper ) { StripeMock . create_test_helper }
66
77 describe "#call" do
8+ let ( :original_quantity ) { 1 }
9+ let ( :new_quantity ) { original_quantity + 1 }
10+
811 before ( :each ) do
912 @plan = create ( :subscription_plan )
1013 expect ( @plan . errors ) . to be_blank
1114
1215 token = StripeMock . generate_card_token ( { } )
13- @subscription = create ( :subscription , quantity : 1 , stripe_token : token , plan : @plan , state : 'processing' )
16+ @subscription = create ( :subscription , quantity : original_quantity , stripe_token : token , plan : @plan , state : 'processing' )
1417 StartSubscription . call ( @subscription )
1518 expect ( @subscription . error ) . to be_nil
1619 expect ( @subscription . active? ) . to be_truthy
17- @subscription = Payola ::ChangeSubscriptionQuantity . call ( @subscription , 2 )
18- expect ( @subscription . errors ) . to be_blank
20+ end
21+
22+ it "should not produce any subscription errors" do
23+ subscription = Payola ::ChangeSubscriptionQuantity . call ( @subscription , new_quantity )
24+
25+ expect ( subscription . errors ) . to be_blank
1926 end
2027
2128 it "should change the quantity on the stripe subscription" do
22- customer = Stripe ::Customer . retrieve ( @subscription . stripe_customer_id )
23- sub = customer . subscriptions . retrieve ( @subscription . stripe_id )
29+ subscription = Payola ::ChangeSubscriptionQuantity . call ( @subscription , new_quantity )
2430
25- expect ( sub . quantity ) . to eq 2
31+ customer = Stripe ::Customer . retrieve ( subscription . stripe_customer_id )
32+ sub = customer . subscriptions . retrieve ( subscription . stripe_id )
33+ expect ( sub . quantity ) . to eq new_quantity
2634 end
2735
2836 it "should change the quantity on the payola subscription" do
29- expect ( @subscription . reload . quantity ) . to eq 2
37+ subscription = Payola ::ChangeSubscriptionQuantity . call ( @subscription , new_quantity )
38+
39+ expect ( subscription . reload . quantity ) . to eq new_quantity
40+ end
41+
42+ it "should notify quantity has changed" do
43+ expect ( @subscription ) . to receive ( :instrument_quantity_changed ) . with ( original_quantity )
44+
45+ Payola ::ChangeSubscriptionQuantity . call ( @subscription , new_quantity )
3046 end
3147 end
3248 end
0 commit comments