-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathuser_spec.rb
More file actions
130 lines (110 loc) · 3.93 KB
/
user_spec.rb
File metadata and controls
130 lines (110 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
# frozen_string_literal: true
describe User do
let(:user) { FactoryBot.create(:user) }
let(:repo) { FactoryBot.create(:repository) }
let(:authorize_build_url) { "http://localhost:9292/users/#{user.id}/plan" }
let(:repo) { FactoryBot.create(:repository) }
let(:authorize_build_url) { "http://localhost:9292/users/#{user.id}/plan" }
describe 'constants' do
# It isn't often that we see tests for constants, but these are special.
# Changing these values for worker timeout limits impacts our infra teams,
# and should only be adjusted after consulting with them.
#
it 'has correct values for default timeouts' do
expect(User::DEFAULT_SPONSORED_TIMEOUT).to eq 3000
expect(User::DEFAULT_SUBSCRIBED_TIMEOUT).to eq 7200
end
end
describe '#educational?' do
context 'education = true' do
before do
user.education = true
end
it 'returns true' do
expect(user.educational?).to be_truthy
end
end
context 'education = false' do
before do
user.education = false
end
it 'returns true' do
expect(user.educational?).to be_falsey
end
end
context 'education = nil' do
before do
user.education = nil
end
it 'returns true' do
expect(user.educational?).to be_falsey
end
end
end
describe '#default_worker_timeout' do
context 'subscribed? == true' do
before do
user.stubs(:subscribed?).returns(true)
end
it 'returns the DEFAULT_SUBSCRIBED_TIMEOUT' do
expect(user.default_worker_timeout).to eq User::DEFAULT_SUBSCRIBED_TIMEOUT
end
end
context 'educational? == true' do
before do
user.stubs(:educational?).returns(true)
stub_request(:get, authorize_build_url).to_return(
body: MultiJson.dump(plan_name: 'free_tier_plan', hybrid: false, free: true, status: nil, metered: true)
)
end
it 'returns the DEFAULT_SUBSCRIBED_TIMEOUT' do
expect(user.default_worker_timeout).to eq User::DEFAULT_SUBSCRIBED_TIMEOUT
end
end
context 'active_trial? == true' do
before do
user.stubs(:active_trial?).returns(true)
end
it 'returns the DEFAULT_SUBSCRIBED_TIMEOUT' do
expect(user.default_worker_timeout).to eq User::DEFAULT_SUBSCRIBED_TIMEOUT
end
end
context "paid_new_plan? == true" do
before do
user.stubs(:paid_new_plan?).returns(true)
stub_request(:get, authorize_build_url).to_return(
body: MultiJson.dump(plan_name: 'two_concurrent_plan', hybrid: true, free: false, status: 'subscribed', metered: false)
)
end
it "returns the DEFAULT_SUBSCRIBED_TIMEOUT" do
expect(user.default_worker_timeout).to eq Organization::DEFAULT_SUBSCRIBED_TIMEOUT
end
end
context 'paid_new_plan? == true' do
before do
user.stubs(:paid_new_plan?).returns(true)
stub_request(:get, authorize_build_url).to_return(
body: MultiJson.dump(plan_name: 'two_concurrent_plan', hybrid: true, free: false, status: 'subscribed',
metered: false)
)
end
it 'returns the DEFAULT_SUBSCRIBED_TIMEOUT' do
expect(user.default_worker_timeout).to eq Organization::DEFAULT_SUBSCRIBED_TIMEOUT
end
end
describe '#subscribed?, #active_trial?, #educational? == false' do
before do
user.stubs(:subscribed?).returns(false)
user.stubs(:active_trial?).returns(false)
user.stubs(:educational?).returns(false)
stub_request(:get, authorize_build_url).to_return(
body: MultiJson.dump(plan_name: 'two_concurrent_plan', hybrid: true, free: false, status: 'subscribed',
metered: false)
)
end
it 'returns the DEFAULT_SUBSCRIBED_TIMEOUT' do
expect(user.default_worker_timeout).to eq User::DEFAULT_SUBSCRIBED_TIMEOUT
end
end
end
end