Skip to content

Commit da0b257

Browse files
authored
Merge pull request #1144 from AndriiMysko/v2-user-usage-am
Include invoice status
2 parents 46e825b + a0f35ea commit da0b257

File tree

10 files changed

+24
-13
lines changed

10 files changed

+24
-13
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
module Travis::API::V3
22
class Models::Invoice
3-
attr_reader :id, :created_at, :url, :amount_due
3+
attr_reader :id, :created_at, :status, :url, :amount_due
44

55
def initialize(attributes = {})
66
@id = attributes.fetch('id')
77
@created_at = attributes.fetch('created_at') && DateTime.parse(attributes.fetch('created_at'))
8+
@status = attributes.fetch('status')
89
@url = attributes.fetch('url')
910
@amount_due = attributes.fetch('amount_due')
1011
end
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Travis::API::V3
22
class Models::V2AddonUsage
3-
attr_reader :id, :addon_id, :addon_quantity, :addon_usage, :remaining, :active
3+
attr_reader :id, :addon_id, :addon_quantity, :addon_usage, :remaining, :active, :status
44

55
def initialize(attrs)
66
@id = attrs.fetch('id')
@@ -9,6 +9,7 @@ def initialize(attrs)
99
@addon_usage = attrs.fetch('addon_usage')
1010
@remaining = attrs.fetch('remaining')
1111
@active = attrs.fetch('active')
12+
@status = attrs.fetch('status')
1213
end
1314
end
1415
end

lib/travis/api/v3/renderer/invoice.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Travis::API::V3
22
class Renderer::Invoice < ModelRenderer
3-
representation(:standard, :id, :created_at, :url, :amount_due)
3+
representation(:standard, :id, :created_at, :status, :url, :amount_due)
44
end
55
end
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Travis::API::V3
22
class Renderer::V2AddonUsage < ModelRenderer
3-
representation(:standard, :id, :addon_id, :addon_quantity, :addon_usage, :remaining, :active)
4-
representation(:minimal, :id, :addon_id, :addon_quantity, :addon_usage, :remaining, :active)
3+
representation(:standard, :id, :addon_id, :addon_quantity, :addon_usage, :remaining, :active, :status)
4+
representation(:minimal, :id, :addon_id, :addon_quantity, :addon_usage, :remaining, :active, :status)
55
end
66
end

spec/support/billing_spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def billing_addons_response_body
141141
"addon_quantity" => 40000,
142142
"addon_usage" => 0,
143143
"remaining" => 40000,
144+
"status" => "subscribed",
144145
"active" => true
145146
}
146147
},
@@ -154,6 +155,7 @@ def billing_addons_response_body
154155
"addon_quantity" => 10000,
155156
"addon_usage" => 0,
156157
"remaining" => 10000,
158+
"status" => "subscribed",
157159
"active" => true
158160
}
159161
}

spec/v3/billing_client_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
it 'returns a list of invoices' do
4848
stub_billing_request(:get, "/subscriptions/#{subscription_id}/invoices", auth_key: auth_key, user_id: user_id)
49-
.to_return(body: JSON.dump([{'id' => invoice_id, 'created_at' => Time.now, 'url' => 'https://billing-test.travis-ci.com/invoices/111.pdf', amount_due: 999 }]))
49+
.to_return(body: JSON.dump([{'id' => invoice_id, 'created_at' => Time.now, 'url' => 'https://billing-test.travis-ci.com/invoices/111.pdf', amount_due: 999, status: 'paid' }]))
5050
expect(subject.first).to be_a(Travis::API::V3::Models::Invoice)
5151
expect(subject.first.id).to eq(invoice_id)
5252
expect(subject.first.amount_due).to eq(999)
@@ -65,7 +65,7 @@
6565

6666
it 'returns a list of invoices' do
6767
stub_billing_request(:get, "/v2/subscriptions/#{subscription_id}/invoices", auth_key: auth_key, user_id: user_id)
68-
.to_return(body: JSON.dump([{'id' => invoice_id, 'created_at' => Time.now, 'url' => 'https://billing-test.travis-ci.com/invoices/111.pdf', amount_due: 999 }]))
68+
.to_return(body: JSON.dump([{'id' => invoice_id, 'created_at' => Time.now, 'url' => 'https://billing-test.travis-ci.com/invoices/111.pdf', amount_due: 999, status: 'paid' }]))
6969
expect(subject.first).to be_a(Travis::API::V3::Models::Invoice)
7070
expect(subject.first.id).to eq(invoice_id)
7171
expect(subject.first.amount_due).to eq(999)

spec/v3/services/subscription/invoices_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
let(:created_at) { '2018-04-17T18:30:32Z' }
2626
let(:url) { 'https://billing-test.travis-ci.com/invoices/111.pdf' }
2727
let(:amount_due) { 100 }
28+
let(:status) { 'paid' }
2829
let(:subscription_id) { rand(999) }
2930
before do
3031
stub_billing_request(:get, "/subscriptions/#{subscription_id}/invoices", auth_key: billing_auth_key, user_id: user.id)
31-
.to_return(status: 200, body: JSON.dump([{'id' => invoice_id, 'created_at' => created_at, 'url' => url, 'amount_due' => amount_due }]))
32+
.to_return(status: 200, body: JSON.dump([{'id' => invoice_id, 'created_at' => created_at, 'url' => url, 'amount_due' => amount_due, 'status' => status }]))
3233
end
3334

3435
it 'responds with list of subscriptions' do
@@ -45,7 +46,8 @@
4546
'id' => invoice_id,
4647
'created_at' => created_at,
4748
'url' => url,
48-
'amount_due' => amount_due
49+
'amount_due' => amount_due,
50+
'status' => status
4951
}]
5052
})
5153
end

spec/v3/services/v2_subscription/invoices_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
let(:created_at) { '2018-04-17T18:30:32Z' }
2626
let(:url) { 'https://billing-test.travis-ci.com/invoices/111.pdf' }
2727
let(:amount_due) { 100 }
28+
let(:status) { 'paid' }
2829
let(:subscription_id) { rand(999) }
2930
before do
3031
stub_billing_request(:get, "/v2/subscriptions/#{subscription_id}/invoices", auth_key: billing_auth_key, user_id: user.id)
31-
.to_return(status: 200, body: JSON.dump([{'id' => invoice_id, 'created_at' => created_at, 'url' => url, 'amount_due' => amount_due }]))
32+
.to_return(status: 200, body: JSON.dump([{'id' => invoice_id, 'created_at' => created_at, 'url' => url, 'amount_due' => amount_due, 'status' => status }]))
3233
end
3334

3435
it 'responds with list of subscriptions' do
@@ -45,7 +46,8 @@
4546
'id' => invoice_id,
4647
'created_at' => created_at,
4748
'url' => url,
48-
'amount_due' => amount_due
49+
'amount_due' => amount_due,
50+
'status' => status
4951
}]
5052
})
5153
end

spec/v3/services/v2_subscriptions/all_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
'addon_quantity' => 40_000,
151151
'addon_usage' => 0,
152152
'remaining' => 40_000,
153+
'status' => 'subscribed',
153154
'active' => true
154155
}
155156
},
@@ -168,6 +169,7 @@
168169
'addon_quantity' => 10_000,
169170
'addon_usage' => 0,
170171
'remaining' => 10_000,
172+
'status' => 'subscribed',
171173
'active' => true
172174
}
173175
}

spec/v3/services/v2_subscriptions/create_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,10 @@
238238
'@representation' => 'standard',
239239
'id' => 7,
240240
'addon_id' => 7,
241-
'addon_quantity' => 40000,
241+
'addon_quantity' => 40_000,
242242
'addon_usage' => 0,
243-
'remaining' => 40000,
243+
'remaining' => 40_000,
244+
'status' => 'pending',
244245
'active' => false
245246
}
246247
}],

0 commit comments

Comments
 (0)