Skip to content

Commit b54d6d3

Browse files
Merge branch 'master' into fix_same_name_branch_env_vars_am
2 parents 2435606 + 2d5f2e8 commit b54d6d3

File tree

6 files changed

+55
-4
lines changed

6 files changed

+55
-4
lines changed

lib/travis/api/v3/models/allowance.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class Models::Allowance
55
def initialize(subscription_type, owner_id, attributes = {})
66
@subscription_type = subscription_type
77
@id = owner_id
8+
@subscription_type = 3 if !!attributes['no_plan']
89
@public_repos = attributes.fetch('public_repos', nil)
910
@private_repos = attributes.fetch('private_repos', nil)
1011
@concurrency_limit = attributes.fetch('concurrency_limit', nil)

lib/travis/api/v3/models/v2_plan_config.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Travis::API::V3
22
class Models::V2PlanConfig
33
attr_reader :id, :name, :private_repos, :starting_price, :starting_users, :plan_type,
4-
:private_credits, :public_credits, :addon_configs, :concurrency_limit, :available_standalone_addons, :auto_refill_enabled
4+
:private_credits, :public_credits, :addon_configs, :concurrency_limit, :available_standalone_addons, :auto_refill_enabled, :trial_plan
55

66
def initialize(attrs)
77
@id = attrs.fetch('id')
@@ -15,6 +15,7 @@ def initialize(attrs)
1515
@plan_type = attrs.fetch('plan_type')
1616
@concurrency_limit = attrs.fetch('concurrency_limit')
1717
@available_standalone_addons = attrs.fetch('available_standalone_addons')
18+
@trial_plan = attrs.fetch('trial_plan', false)
1819
end
1920
end
2021
end
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module Travis::API::V3
22
class Renderer::V2PlanConfig < ModelRenderer
33
representation(:standard, :id, :name, :private_repos, :starting_price, :starting_users, :private_credits,
4-
:public_credits, :addon_configs, :plan_type, :concurrency_limit, :available_standalone_addons)
4+
:public_credits, :addon_configs, :plan_type, :concurrency_limit, :available_standalone_addons, :trial_plan)
55
representation(:minimal, :id, :name, :private_repos, :starting_price, :starting_users, :private_credits,
6-
:public_credits, :addon_configs, :plan_type, :concurrency_limit)
6+
:public_credits, :addon_configs, :plan_type, :concurrency_limit, :trial_plan)
77
end
88
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require 'spec_helper'
2+
3+
RSpec.describe Travis::API::V3::Services::Allowance::ForOwner, set_app: true, billing_spec_helper: true do
4+
let(:billing_url) { 'http://billingfake.travis-ci.com' }
5+
let(:billing_auth_key) { 'secret' }
6+
let(:json_headers) { { 'HTTP_ACCEPT' => 'application/json' } }
7+
let(:user_token) { Travis::Api::App::AccessToken.create(user: user, app_id: 1) }
8+
9+
before do
10+
Travis.config.host = 'travis-ci.com'
11+
Travis.config.billing.url = billing_url
12+
Travis.config.billing.auth_key = billing_auth_key
13+
end
14+
15+
context 'authenticated' do
16+
let(:user) { FactoryBot.create(:user, name: 'Joe', login: 'joe') }
17+
let(:v2_response_body) { JSON.dump(allowance_data) }
18+
19+
before do
20+
stub_billing_request(:get, "/usage/users/#{user.id}/allowance", auth_key: billing_auth_key, user_id: user.id)
21+
.to_return(status: 200, body: v2_response_body)
22+
end
23+
24+
context 'when user has no plan' do
25+
let(:allowance_data) { {'no_plan' => true} }
26+
27+
describe 'returns subscription_type=3' do
28+
before { get("/v3/owner/#{user.login}/allowance", {}, json_headers.merge('HTTP_AUTHORIZATION' => "token #{user_token}")) }
29+
30+
example { expect(last_response).to be_ok }
31+
example { expect(JSON.parse(last_response.body)['subscription_type']).to eq(3) }
32+
end
33+
end
34+
35+
context 'when user has a plan' do
36+
let(:allowance_data) { {'no_plan' => false} }
37+
38+
describe 'returns subscription_type=3' do
39+
before { get("/v3/owner/#{user.login}/allowance", {}, json_headers.merge('HTTP_AUTHORIZATION' => "token #{user_token}")) }
40+
41+
example { expect(last_response).to be_ok }
42+
example { expect(JSON.parse(last_response.body)['subscription_type']).to eq(2) }
43+
end
44+
end
45+
end
46+
end

spec/v3/services/v2_subscriptions/all_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
'starting_users': 10_000,
3333
'private_credits': 500_000,
3434
'public_credits': 40_000,
35+
'trial_plan': false,
3536
'addon_configs' => {
3637
'free_tier_credits' => {
3738
'name' => 'Free 10 000 credits (renewed monthly)',
@@ -94,6 +95,7 @@
9495
'starting_users' => 10_000,
9596
'private_credits' => 500_000,
9697
'public_credits' => 40_000,
98+
'trial_plan' => false,
9799
'available_standalone_addons' => [
98100
{
99101
'id' => 'credits_25k',

spec/v3/services/v2_subscriptions/create_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
'starting_users' => 10_000,
8383
'private_credits' => 500_000,
8484
'public_credits' => 40_000,
85+
'trial_plan': false,
8586
'available_standalone_addons' => [
8687
{
8788
'id' => 'credits_25k',
@@ -198,6 +199,7 @@
198199
'public_credits' => 40_000,
199200
'concurrency_limit' => 20,
200201
'plan_type' => 'metered',
202+
'trial_plan' => false,
201203
'available_standalone_addons' => [
202204
{
203205
'id' => 'credits_25k',
@@ -264,7 +266,6 @@
264266
'addon_id' => 7,
265267
'addon_quantity' => 40_000,
266268
'addon_usage' => 0,
267-
'remaining' => 40000,
268269
'purchase_date' => '2017-11-28T00:09:59.502Z',
269270
'valid_to' => '2017-11-28T00:09:59.502Z',
270271
'remaining' => 40_000,

0 commit comments

Comments
 (0)