-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathpaystack_subscriptions_spec.rb
More file actions
144 lines (106 loc) · 3.93 KB
/
Copy pathpaystack_subscriptions_spec.rb
File metadata and controls
144 lines (106 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
require 'spec_helper'
require 'paystack/objects/subscriptions.rb'
require 'paystack.rb'
describe PaystackSubscriptions do
public_test_key = "pk_test_ea7c71f838c766922873f1dd3cc529afe13da1c0"
private_test_key = "sk_test_40e9340686e6187697f8309dbae57c002bb16dd0"
it "should return a valid subscriptions object" do
paystack = Paystack.new(public_test_key, private_test_key)
subscriptions = PaystackSubscriptions.new(paystack)
expect(subscriptions.nil?).to eq false
end
it "should return a subscription hashset/object" do
paystack = Paystack.new(public_test_key, private_test_key)
subscriptions = PaystackSubscriptions.new(paystack)
expect(subscriptions.nil?).to eq false
plans = PaystackPlans.new(paystack)
temp = Random.new_seed.to_s
plan = plans.create(
:name => "#{temp[0..6]} Test Plan",
:description => "Dev Test Plan Updated",
:amount => 30000, #in KOBO
:interval => "monthly",
:currency => "NGN"
)
subscription = subscriptions.create(
:customer => "lol@gmail.com",
:plan => plan["data"]["plan_code"]
)
hash = subscriptions.get(subscription['data']['id'])
# puts hash
expect(hash.nil?).to eq false
expect(hash['data']['id'].nil?).to eq false
end
it "should successfuly create a subscription" do
paystack = Paystack.new(public_test_key, private_test_key)
subscriptions = PaystackSubscriptions.new(paystack)
expect(subscriptions.nil?).to eq false
plans = PaystackPlans.new(paystack)
temp = Random.new_seed.to_s
plan= plans.create(
:name => "#{temp[0..6]} Test Plan",
:description => "Dev Test Plan Updated",
:amount => 30000, #in KOBO
:interval => "monthly",
:currency => "NGN"
)
hash = subscriptions.create(
:customer => "lol@gmail.com",
:plan => plan["data"]["plan_code"]
)
# puts hash
expect(hash.nil?).to eq false
expect(hash['data']['id'].nil?).to eq false
end
it "should successfully disable a subscription" do
paystack = Paystack.new(public_test_key, private_test_key)
subscriptions = PaystackSubscriptions.new(paystack)
plans = PaystackPlans.new(paystack)
temp = Random.new_seed.to_s
plan = plans.create(
:name => "#{temp[0..6]} Test Plan",
:description => "Dev Test Plan Updated",
:amount => 30000, #in KOBO
:interval => "monthly", #monthly, yearly, quarterly, weekly etc
:currency => "NGN"
)
subscription = subscriptions.create(
:customer => "lol@gmail.com",
:plan => plan["data"]["plan_code"]
)
hash = subscriptions.disable(
:code => subscription["data"]["subscription_code"],
:token => subscription["data"]["email_token"]
)
expect(hash.nil?).to eq false
expect(hash['status']).to eq true
end
#Skipping test as cancelled subscriptions cannot be re-enabled
xit "should successfully enable a subscription" do
paystack = Paystack.new(public_test_key, private_test_key)
subscriptions = PaystackSubscriptions.new(paystack)
plans = PaystackPlans.new(paystack)
temp = Random.new_seed.to_s
plan = plans.create(
:name => "#{temp[0..6]} Test Plan",
:description => "Dev Test Plan Updated",
:amount => 30000, #in KOBO
:interval => "monthly", #monthly, yearly, quarterly, weekly etc
:currency => "NGN"
)
subscription = subscriptions.create(
:customer => "lol@gmail.com",
:plan => plan["data"]["plan_code"]
)
subscriptions.disable(
:code => subscription["data"]["subscription_code"],
:token => subscription["data"]["email_token"]
)
hash = subscriptions.enable(
:code => subscription["data"]["subscription_code"],
:token => subscription["data"]["email_token"]
)
expect(hash.nil?).to eq false
expect(hash['status']).to eq true
end
end