|
3 | 3 | let(:repository) { FactoryBot.create(:repository, owner: owner) }
|
4 | 4 | let(:job) { FactoryBot.create(:job, repository: repository, state: 'canceled') }
|
5 | 5 | let(:user) { FactoryBot.create(:user) }
|
| 6 | + let(:subscription) { nil } |
6 | 7 |
|
7 | 8 | let(:service) { Travis::Enqueue::Services::RestartModel.new(user, { job_id: job.id }) }
|
8 | 9 |
|
9 | 10 | before do
|
10 | 11 | Travis.config.billing.url = 'http://localhost:9292/'
|
11 | 12 | Travis.config.billing.auth_key = 'secret'
|
12 |
| - |
13 |
| - stub_request(:post, /http:\/\/localhost:9292\/(users|organizations)\/(.+)\/authorize_build/).to_return( |
14 |
| - body: MultiJson.dump(allowed: true, rejection_code: nil) |
15 |
| - ) |
16 | 13 | end
|
17 | 14 |
|
18 | 15 | after do
|
|
39 | 36 | end
|
40 | 37 | end
|
41 | 38 |
|
42 |
| - context 'build permissions' do |
43 |
| - context 'when owner is a user' do |
44 |
| - context 'on repo level' do |
45 |
| - context 'when value is nil' do |
46 |
| - before { repository.permissions.create(user: user, build: nil) } |
| 39 | + context 'when owner active plan' do |
| 40 | + before do |
| 41 | + stub_request(:post, /http:\/\/localhost:9292\/(users|organizations)\/(.+)\/authorize_build/).to_return( |
| 42 | + body: MultiJson.dump(allowed: true, rejection_code: nil) |
| 43 | + ) |
| 44 | + end |
| 45 | + context 'build permissions' do |
| 46 | + context 'when owner is a user' do |
| 47 | + context 'on repo level' do |
| 48 | + context 'when value is nil' do |
| 49 | + before { repository.permissions.create(user: user, build: nil) } |
47 | 50 |
|
48 |
| - include_examples 'restarts the job' |
49 |
| - end |
| 51 | + include_examples 'restarts the job' |
| 52 | + end |
50 | 53 |
|
51 |
| - context 'when value is true' do |
52 |
| - before { repository.permissions.create(user: user, build: true) } |
| 54 | + context 'when value is true' do |
| 55 | + before { repository.permissions.create(user: user, build: true) } |
53 | 56 |
|
54 |
| - include_examples 'restarts the job' |
55 |
| - end |
| 57 | + include_examples 'restarts the job' |
| 58 | + end |
56 | 59 |
|
57 |
| - context 'when value is false' do |
58 |
| - before { repository.permissions.create(user: user, build: false) } |
| 60 | + context 'when value is false' do |
| 61 | + before { repository.permissions.create(user: user, build: false) } |
59 | 62 |
|
60 |
| - include_examples 'does not restart the job' |
| 63 | + include_examples 'does not restart the job' |
| 64 | + end |
61 | 65 | end
|
62 | 66 | end
|
63 |
| - end |
64 | 67 |
|
65 |
| - context 'when owner is an organization' do |
66 |
| - let(:owner) { FactoryBot.create(:org) } |
| 68 | + context 'when owner is an organization' do |
| 69 | + let(:owner) { FactoryBot.create(:org) } |
67 | 70 |
|
68 |
| - before { repository.permissions.create(user: user, build: true) } |
| 71 | + before { repository.permissions.create(user: user, build: true) } |
69 | 72 |
|
70 |
| - context 'on organization level' do |
71 |
| - context 'when value is nil' do |
72 |
| - before { owner.memberships.create(user: user, build_permission: nil) } |
| 73 | + context 'on organization level' do |
| 74 | + context 'when value is nil' do |
| 75 | + before { owner.memberships.create(user: user, build_permission: nil) } |
73 | 76 |
|
74 |
| - include_examples 'restarts the job' |
75 |
| - end |
| 77 | + include_examples 'restarts the job' |
| 78 | + end |
76 | 79 |
|
77 |
| - context 'when value is true' do |
78 |
| - before { owner.memberships.create(user: user, build_permission: true) } |
| 80 | + context 'when value is true' do |
| 81 | + before { owner.memberships.create(user: user, build_permission: true) } |
79 | 82 |
|
80 |
| - include_examples 'restarts the job' |
81 |
| - end |
| 83 | + include_examples 'restarts the job' |
| 84 | + end |
82 | 85 |
|
83 |
| - context 'when value is false' do |
84 |
| - before { owner.memberships.create(user: user, build_permission: false) } |
| 86 | + context 'when value is false' do |
| 87 | + before { owner.memberships.create(user: user, build_permission: false) } |
85 | 88 |
|
86 |
| - include_examples 'does not restart the job' |
| 89 | + include_examples 'does not restart the job' |
| 90 | + end |
87 | 91 | end
|
88 | 92 | end
|
89 | 93 | end
|
90 | 94 | end
|
| 95 | + |
| 96 | + context 'when customer does not have active plan' do |
| 97 | + before do |
| 98 | + stub_request(:post, /http:\/\/localhost:9292\/(users|organizations)\/(.+)\/authorize_build/) |
| 99 | + .to_return(status: 404, body: JSON.dump(error: 'Not Found')) |
| 100 | + end |
| 101 | + |
| 102 | + context 'when customer has no old subscription' do |
| 103 | + include_examples 'does not restart the job' |
| 104 | + end |
| 105 | + |
| 106 | + context 'when customer has an old active subscription' do |
| 107 | + before do |
| 108 | + repository.permissions.create(user: user, build: true) |
| 109 | + FactoryBot.create(:valid_stripe_subs, owner: owner) |
| 110 | + end |
| 111 | + |
| 112 | + include_examples 'restarts the job' |
| 113 | + end |
| 114 | + |
| 115 | + context 'when customer has an old canceled subscription' do |
| 116 | + let(:subscription) { FactoryBot.create(:canceled_stripe_subs, owner: owner) } |
| 117 | + |
| 118 | + include_examples 'does not restart the job' |
| 119 | + end |
| 120 | + |
| 121 | + end |
91 | 122 | end
|
92 | 123 | end
|
0 commit comments