18
18
end
19
19
20
20
def new_token
21
- Stripe ::Token . create ( card : { number : 4242424242424242 , cvc : 224 , exp_month : 12 , exp_year : 14 } ) . try ( :id )
21
+ Stripe ::Token . create ( card : { number : 4242424242424242 , cvc : 224 , exp_month : 12 , exp_year : 14 } ) . try ( :id )
22
22
end
23
23
24
24
def post_job_for ( team )
@@ -28,42 +28,62 @@ def post_job_for(team)
28
28
describe 'account creation' do
29
29
30
30
it 'should create a valid account locally and on stripe' do
31
- expect ( team . account ) . to be_nil
32
- team . build_account ( account )
33
- team . account . admin_id = admin . id
34
- team . account . save_with_payment
35
- team . reload
36
- expect ( team . account . stripe_card_token ) . to eq ( account [ :stripe_card_token ] )
37
- expect ( team . account . stripe_customer_token ) . not_to be_nil
38
- expect ( team . account . plan_ids ) . to eq ( [ ] )
31
+ # TODO: Refactor api calls to Sidekiq job
32
+ VCR . use_cassette ( "Account" ) do
33
+
34
+ expect ( team . account ) . to be_nil
35
+ team . build_account ( account )
36
+ team . account . admin_id = admin . id
37
+ team . account . save_with_payment
38
+ team . reload
39
+ expect ( team . account . stripe_card_token ) . to eq ( account [ :stripe_card_token ] )
40
+ expect ( team . account . stripe_customer_token ) . not_to be_nil
41
+ expect ( team . account . plan_ids ) . to eq ( [ ] )
42
+
43
+ end
39
44
end
40
45
41
46
it 'should still create an account if account admin not team admin' do
42
- team . build_account ( account )
43
- some_random_user = Fabricate ( :user )
44
- team . account . admin_id = some_random_user . id
45
- team . account . save_with_payment
46
- team . reload
47
- expect ( team . account ) . not_to be_nil
47
+ # TODO: Refactor api calls to Sidekiq job
48
+ VCR . use_cassette ( "Account" ) do
49
+
50
+ team . build_account ( account )
51
+ some_random_user = Fabricate ( :user )
52
+ team . account . admin_id = some_random_user . id
53
+ team . account . save_with_payment
54
+ team . reload
55
+ expect ( team . account ) . not_to be_nil
56
+
57
+ end
48
58
end
49
59
50
60
it 'should not create an account if stripe_card_token invalid' do
51
- account [ :stripe_card_token ] = "invalid"
52
- team . build_account ( account )
53
- team . account . admin_id = admin . id
54
- team . account . save_with_payment
55
- team . reload
56
- expect ( team . account ) . to be_nil
61
+ # TODO: Refactor api calls to Sidekiq job
62
+ VCR . use_cassette ( "Account" ) do
63
+
64
+ account [ :stripe_card_token ] = "invalid"
65
+ team . build_account ( account )
66
+ team . account . admin_id = admin . id
67
+ team . account . save_with_payment
68
+ team . reload
69
+ expect ( team . account ) . to be_nil
70
+
71
+ end
57
72
end
58
73
59
74
it 'should not allow stripe_customer_token or admin to be set/updated' do
60
- some_random_user = Fabricate ( :user )
61
- account [ :stripe_customer_token ] = "invalid_customer_token"
62
- account [ :admin_id ] = some_random_user . id
63
- team . build_account ( account )
64
- team . account . save_with_payment
65
- team . reload
66
- expect ( team . account ) . to be_nil
75
+ # TODO: Refactor api calls to Sidekiq job
76
+ VCR . use_cassette ( "Account" ) do
77
+
78
+ some_random_user = Fabricate ( :user )
79
+ account [ :stripe_customer_token ] = "invalid_customer_token"
80
+ account [ :admin_id ] = some_random_user . id
81
+ team . build_account ( account )
82
+ team . account . save_with_payment
83
+ team . reload
84
+ expect ( team . account ) . to be_nil
85
+
86
+ end
67
87
end
68
88
end
69
89
@@ -74,12 +94,17 @@ def post_job_for(team)
74
94
75
95
describe 'free subscription' do
76
96
before ( :each ) do
77
- expect ( team . account ) . to be_nil
78
- team . build_account ( account )
79
- team . account . admin_id = admin . id
80
- team . account . save_with_payment
81
- team . account . subscribe_to! ( free_plan )
82
- team . reload
97
+ # TODO: Refactor api calls to Sidekiq job
98
+ VCR . use_cassette ( "Account" ) do
99
+
100
+ expect ( team . account ) . to be_nil
101
+ team . build_account ( account )
102
+ team . account . admin_id = admin . id
103
+ team . account . save_with_payment
104
+ team . account . subscribe_to! ( free_plan )
105
+ team . reload
106
+
107
+ end
83
108
end
84
109
85
110
it 'should add a free subscription' do
@@ -88,41 +113,61 @@ def post_job_for(team)
88
113
end
89
114
90
115
it 'should not allow any job posts' do
91
- expect ( team . can_post_job? ) . to eq ( false )
92
- expect ( team . premium? ) . to eq ( false )
93
- expect ( team . valid_jobs? ) . to eq ( false )
94
- expect { Fabricate ( :opportunity , team_document_id : team . id ) } . to raise_error ( ActiveRecord ::RecordNotSaved )
116
+ # TODO: Refactor api calls to Sidekiq job
117
+ VCR . use_cassette ( "Account" ) do
118
+
119
+ expect ( team . can_post_job? ) . to eq ( false )
120
+ expect ( team . premium? ) . to eq ( false )
121
+ expect ( team . valid_jobs? ) . to eq ( false )
122
+ expect { Fabricate ( :opportunity , team_document_id : team . id ) } . to raise_error ( ActiveRecord ::RecordNotSaved )
123
+
124
+ end
95
125
end
96
126
97
127
it 'should allow upgrade to monthly subscription' do
98
- team . account . save_with_payment ( monthly_plan )
99
- team . reload
100
- expect ( team . can_post_job? ) . to eq ( true )
101
- expect ( team . paid_job_posts ) . to eq ( 0 )
102
- expect ( team . valid_jobs? ) . to eq ( true )
103
- expect ( team . has_monthly_subscription? ) . to eq ( true )
104
- expect ( team . premium? ) . to eq ( true )
128
+ # TODO: Refactor api calls to Sidekiq job
129
+ VCR . use_cassette ( "Account" ) do
130
+
131
+ team . account . save_with_payment ( monthly_plan )
132
+ team . reload
133
+ expect ( team . can_post_job? ) . to eq ( true )
134
+ expect ( team . paid_job_posts ) . to eq ( 0 )
135
+ expect ( team . valid_jobs? ) . to eq ( true )
136
+ expect ( team . has_monthly_subscription? ) . to eq ( true )
137
+ expect ( team . premium? ) . to eq ( true )
138
+
139
+ end
105
140
end
106
141
107
142
it 'should allow upgrade to one-time job post charge' do
108
- team . account . update_attributes ( { stripe_card_token : new_token } )
109
- team . account . save_with_payment ( onetime_plan )
110
- team . reload
111
- expect ( team . can_post_job? ) . to eq ( true )
112
- expect ( team . valid_jobs? ) . to eq ( true )
113
- expect ( team . paid_job_posts ) . to eq ( 1 )
114
- expect ( team . premium? ) . to eq ( true )
143
+ # TODO: Refactor api calls to Sidekiq job
144
+ VCR . use_cassette ( "Account" ) do
145
+
146
+ team . account . update_attributes ( { stripe_card_token : new_token } )
147
+ team . account . save_with_payment ( onetime_plan )
148
+ team . reload
149
+ expect ( team . can_post_job? ) . to eq ( true )
150
+ expect ( team . valid_jobs? ) . to eq ( true )
151
+ expect ( team . paid_job_posts ) . to eq ( 1 )
152
+ expect ( team . premium? ) . to eq ( true )
153
+
154
+ end
115
155
end
116
156
end
117
157
118
158
describe 'monthly paid subscription' do
119
159
before ( :each ) do
120
- expect ( team . account ) . to be_nil
121
- team . build_account ( account )
122
- team . account . admin_id = admin . id
123
- team . account . save_with_payment
124
- team . account . subscribe_to! ( monthly_plan )
125
- team . reload
160
+ # TODO: Refactor api calls to Sidekiq job
161
+ VCR . use_cassette ( "Account" ) do
162
+
163
+ expect ( team . account ) . to be_nil
164
+ team . build_account ( account )
165
+ team . account . admin_id = admin . id
166
+ team . account . save_with_payment
167
+ team . account . subscribe_to! ( monthly_plan )
168
+ team . reload
169
+
170
+ end
126
171
end
127
172
128
173
it 'should add a paid monthly subscription' do
@@ -134,21 +179,31 @@ def post_job_for(team)
134
179
end
135
180
136
181
it 'should allow unlimited job posts' do
137
- expect ( team . can_post_job? ) . to eq ( true )
138
- 5 . times do
139
- Fabricate ( :opportunity , team_document_id : team . id )
140
- end
141
- expect ( team . can_post_job? ) . to eq ( true )
182
+ # TODO: Refactor api calls to Sidekiq job
183
+ VCR . use_cassette ( "Account" ) do
184
+
185
+ expect ( team . can_post_job? ) . to eq ( true )
186
+ 5 . times do
187
+ Fabricate ( :opportunity , team_document_id : team . id )
188
+ end
189
+ expect ( team . can_post_job? ) . to eq ( true )
190
+
191
+ end
142
192
end
143
193
end
144
194
145
195
describe 'one-time job post charge' do
146
196
before ( :each ) do
147
- expect ( team . account ) . to be_nil
148
- team . build_account ( account )
149
- team . account . admin_id = admin . id
150
- team . account . save_with_payment ( onetime_plan )
151
- team . reload
197
+ # TODO: Refactor api calls to Sidekiq job
198
+ VCR . use_cassette ( "Account" ) do
199
+
200
+ expect ( team . account ) . to be_nil
201
+ team . build_account ( account )
202
+ team . account . admin_id = admin . id
203
+ team . account . save_with_payment ( onetime_plan )
204
+ team . reload
205
+
206
+ end
152
207
end
153
208
it 'should add a one-time job post charge' do
154
209
expect ( team . account . plan_ids ) . to include ( onetime_plan . id )
@@ -159,44 +214,59 @@ def post_job_for(team)
159
214
end
160
215
161
216
it 'should allow only one job-post' do
162
- expect ( team . can_post_job? ) . to eq ( true )
163
- Fabricate ( :opportunity , team_document_id : team . id )
164
- team . reload
165
- expect ( team . paid_job_posts ) . to eq ( 0 )
166
- expect ( team . can_post_job? ) . to eq ( false )
167
- expect { Fabricate ( :opportunity , team_document_id : team . id ) } . to raise_error ( ActiveRecord ::RecordNotSaved )
217
+ # TODO: Refactor api calls to Sidekiq job
218
+ VCR . use_cassette ( "Account" ) do
219
+
220
+ expect ( team . can_post_job? ) . to eq ( true )
221
+ Fabricate ( :opportunity , team_document_id : team . id )
222
+ team . reload
223
+ expect ( team . paid_job_posts ) . to eq ( 0 )
224
+ expect ( team . can_post_job? ) . to eq ( false )
225
+ expect { Fabricate ( :opportunity , team_document_id : team . id ) } . to raise_error ( ActiveRecord ::RecordNotSaved )
226
+
227
+ end
168
228
end
169
229
170
230
it 'should allow upgrade to monthly subscription' do
171
- team . account . update_attributes ( { stripe_card_token : new_token } )
172
- team . account . save_with_payment ( monthly_plan )
173
- team . reload
174
- expect ( team . can_post_job? ) . to eq ( true )
175
- expect ( team . valid_jobs? ) . to eq ( true )
176
- expect ( team . paid_job_posts ) . to eq ( 1 )
177
- expect ( team . has_monthly_subscription? ) . to eq ( true )
178
- 5 . times do
179
- Fabricate ( :opportunity , team_document_id : team . id )
231
+ # TODO: Refactor api calls to Sidekiq job
232
+ VCR . use_cassette ( "Account" ) do
233
+
234
+ team . account . update_attributes ( { stripe_card_token : new_token } )
235
+ team . account . save_with_payment ( monthly_plan )
236
+ team . reload
237
+ expect ( team . can_post_job? ) . to eq ( true )
238
+ expect ( team . valid_jobs? ) . to eq ( true )
239
+ expect ( team . paid_job_posts ) . to eq ( 1 )
240
+ expect ( team . has_monthly_subscription? ) . to eq ( true )
241
+ 5 . times do
242
+ Fabricate ( :opportunity , team_document_id : team . id )
243
+ end
244
+ expect ( team . can_post_job? ) . to eq ( true )
245
+ expect ( team . paid_job_posts ) . to eq ( 1 )
246
+ expect ( team . premium? ) . to eq ( true )
247
+
180
248
end
181
- expect ( team . can_post_job? ) . to eq ( true )
182
- expect ( team . paid_job_posts ) . to eq ( 1 )
183
- expect ( team . premium? ) . to eq ( true )
184
249
end
185
250
186
251
it 'should allow additional one time job post charges' do
187
- team . account . update_attributes ( { stripe_card_token : new_token } )
188
- team . account . save_with_payment ( onetime_plan )
189
- team . reload
190
- expect ( team . paid_job_posts ) . to eq ( 2 )
191
- expect ( team . can_post_job? ) . to eq ( true )
192
- 2 . times do
193
- Fabricate ( :opportunity , team_document_id : team . id )
194
- end
195
- team . reload
196
- expect ( team . paid_job_posts ) . to eq ( 0 )
197
- expect ( team . has_monthly_subscription? ) . to eq ( false )
198
- expect ( team . premium? ) . to eq ( true )
199
- expect ( team . valid_jobs? ) . to eq ( true )
252
+ # TODO: Refactor api calls to Sidekiq job
253
+ VCR . use_cassette ( "Account" ) do
254
+
255
+ team . account . update_attributes ( { stripe_card_token : new_token } )
256
+ team . account . save_with_payment ( onetime_plan )
257
+ team . reload
258
+ expect ( team . paid_job_posts ) . to eq ( 2 )
259
+ expect ( team . can_post_job? ) . to eq ( true )
260
+ 2 . times do
261
+ Fabricate ( :opportunity , team_document_id : team . id )
262
+ end
263
+ team . reload
264
+ expect ( team . paid_job_posts ) . to eq ( 0 )
265
+ expect ( team . has_monthly_subscription? ) . to eq ( false )
266
+ expect ( team . premium? ) . to eq ( true )
267
+ expect ( team . valid_jobs? ) . to eq ( true )
268
+
269
+ end
200
270
end
201
271
end
202
272
end
0 commit comments