Skip to content

Commit ae2cbfa

Browse files
Billing / API: renamed Reward to Payout
`Payout.belongs_to :app_worker`, not `has_one`. This changes a default route for the resource: `payouts` → `app-workers/:app_worker_id/payouts`. Improved the test. References: [EPMTIOOPS-2954](https://jira.epam.com/jira/browse/EPMTIOOPS-2954).
1 parent 981e8ec commit ae2cbfa

File tree

7 files changed

+58
-53
lines changed

7 files changed

+58
-53
lines changed

lib/cirro_io/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
require 'cirro_io/client/gig_result'
1515
require 'cirro_io/client/gig_time_activity'
1616
require 'cirro_io/client/gig'
17-
require 'cirro_io/client/reward'
17+
require 'cirro_io/client/payout'
1818

1919
module CirroIO
2020
module Client

lib/cirro_io/client/app_worker.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Client
33
class AppWorker < Base
44
has_one :app_user
55
has_many :gig_invitations
6+
has_many :payouts
67
end
78
end
89
end

lib/cirro_io/client/payout.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module CirroIO
2+
module Client
3+
class Payout < Base
4+
belongs_to :app_worker
5+
end
6+
end
7+
end

lib/cirro_io/client/reward.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
RSpec.describe CirroIO::Client::Payout do
2+
let(:app_worker) { CirroIO::Client::AppWorker.load id: 1 }
3+
4+
let :request_headers do
5+
{
6+
'Accept' => 'application/vnd.api+json',
7+
'Accept-Encoding' => 'gzip,deflate',
8+
'Content-Type' => 'application/vnd.api+json',
9+
'User-Agent' => 'Faraday v1.1.0',
10+
'Authorization' => 'Bearer jwt-token',
11+
}
12+
end
13+
14+
let :response_headers do
15+
{
16+
'Content-Type' => 'application/json',
17+
}
18+
end
19+
20+
before do
21+
configure_api_client
22+
allow(JWT).to receive(:encode).and_return('jwt-token')
23+
end
24+
25+
describe '.create' do
26+
let(:payout) { described_class.create app_worker_id: app_worker.id, **attributes }
27+
28+
let(:attributes) do
29+
{
30+
title: Faker::Hipster.sentence,
31+
description: Faker::Hipster.paragraph,
32+
'billing-date': Date.today.to_s,
33+
amount: 100,
34+
}
35+
end
36+
37+
before do
38+
stub_request(:post, "#{test_site}/v1/app-workers/#{app_worker.id}/payouts")
39+
.with(headers: request_headers)
40+
.to_return(body: File.read('./spec/fixtures/payout.json'), headers: response_headers)
41+
end
42+
43+
it 'creates a payout for the app worker' do
44+
expect(payout).to be_persisted
45+
expect(payout.app_worker_id).to eq 1
46+
end
47+
end
48+
end

spec/cirro_io/client/reward_spec.rb

Lines changed: 0 additions & 44 deletions
This file was deleted.

spec/fixtures/reward.json renamed to spec/fixtures/payout.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"data": {
33
"id": "1",
4-
"type": "bonus-payouts",
4+
"type": "payouts",
55
"attributes": {
66
"amount": 8969,
77
"title": "The Soldier's Art",

0 commit comments

Comments
 (0)