dune-balanced 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.gitmodules +3 -0
- data/.rspec +2 -0
- data/.travis.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +125 -0
- data/LICENSE.txt +22 -0
- data/README.md +63 -0
- data/Rakefile +34 -0
- data/app/controllers/dune/balanced/notifications_controller.rb +11 -0
- data/app/decorators/dune/balanced/customer_decorator.rb +14 -0
- data/app/models/dune/balanced/.gitkip +0 -0
- data/app/models/dune/balanced/contributor.rb +11 -0
- data/app/models/dune/balanced/customer.rb +56 -0
- data/app/models/dune/balanced/event.rb +101 -0
- data/app/models/dune/balanced/order.rb +9 -0
- data/app/models/dune/balanced/order_proxy.rb +55 -0
- data/app/models/dune/balanced/payout.rb +77 -0
- data/app/models/dune/balanced/refund.rb +53 -0
- data/app/models/dune/balanced/user.rb +6 -0
- data/app/observers/dune/balanced/events_observer/debit_canceled.rb +13 -0
- data/bin/rails +8 -0
- data/config/initializers/balanced.rb +2 -0
- data/config/initializers/events_observer.rb +2 -0
- data/config/locales/en.yml +9 -0
- data/config/routes.rb +4 -0
- data/db/migrate/20140211203335_create_balanced_contributors.rb +10 -0
- data/db/migrate/20140324175041_add_bank_account_uri_to_balanced_contributors.rb +5 -0
- data/db/migrate/20140817195359_create_dune_balanced_orders.rb +10 -0
- data/dune-balanced.gemspec +32 -0
- data/lib/dune/balanced.rb +9 -0
- data/lib/dune/balanced/engine.rb +13 -0
- data/lib/dune/balanced/version.rb +5 -0
- data/spec/controllers/dune/balanced/notifications_controller_spec.rb +61 -0
- data/spec/decorators/dune/balanced/customer_decorator_spec.rb +19 -0
- data/spec/fixtures/notifications/bank_account_verification.deposited.yml +48 -0
- data/spec/fixtures/notifications/bank_account_verification.verified.yml +48 -0
- data/spec/fixtures/notifications/debit.canceled.yml +74 -0
- data/spec/fixtures/notifications/debit.created.yml +72 -0
- data/spec/fixtures/notifications/debit.succeeded.yml +72 -0
- data/spec/models/dune/balanced/customer_spec.rb +73 -0
- data/spec/models/dune/balanced/event_spec.rb +219 -0
- data/spec/models/dune/balanced/order_proxy_spec.rb +87 -0
- data/spec/models/dune/balanced/order_spec.rb +8 -0
- data/spec/models/dune/balanced/payout_spec.rb +104 -0
- data/spec/models/dune/balanced/refund_spec.rb +157 -0
- data/spec/observers/dune/balanced/events_observer/debit_canceled_spec.rb +32 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/fixtures_test_helper.rb +11 -0
- metadata +223 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
---
|
2
|
+
events:
|
3
|
+
- links: {}
|
4
|
+
occurred_at: '2014-08-14T19:01:19.423000Z'
|
5
|
+
uri: "/events/EV602ee24023e511e49dd30647853a3607"
|
6
|
+
entity:
|
7
|
+
bank_account_verifications:
|
8
|
+
- verification_status: succeeded
|
9
|
+
links:
|
10
|
+
bank_account: BA7AA3yiW6upqETZwU8pyqYg
|
11
|
+
created_at: '2014-08-14T18:58:44.399925Z'
|
12
|
+
attempts_remaining: 2
|
13
|
+
updated_at: '2014-08-14T19:01:19.423788Z'
|
14
|
+
deposit_status: succeeded
|
15
|
+
attempts: 1
|
16
|
+
href: "/verifications/BZ6V6wsEkufWOpfszp360nj"
|
17
|
+
meta: {}
|
18
|
+
id: BZ6V6wsEkufWOpfszp360nj
|
19
|
+
links:
|
20
|
+
bank_account_verifications.bank_account: "/bank_accounts/{bank_account_verifications.bank_account}"
|
21
|
+
href: "/events/EV602ee24023e511e49dd30647853a3607"
|
22
|
+
type: bank_account_verification.verified
|
23
|
+
id: EV602ee24023e511e49dd30647853a3607
|
24
|
+
links: {}
|
25
|
+
registration:
|
26
|
+
events:
|
27
|
+
- links: {}
|
28
|
+
occurred_at: '2014-08-14T19:01:19.423000Z'
|
29
|
+
uri: "/events/EV602ee24023e511e49dd30647853a3607"
|
30
|
+
entity:
|
31
|
+
bank_account_verifications:
|
32
|
+
- verification_status: succeeded
|
33
|
+
links:
|
34
|
+
bank_account: BA7AA3yiW6upqETZwU8pyqYg
|
35
|
+
created_at: '2014-08-14T18:58:44.399925Z'
|
36
|
+
attempts_remaining: 2
|
37
|
+
updated_at: '2014-08-14T19:01:19.423788Z'
|
38
|
+
deposit_status: succeeded
|
39
|
+
attempts: 1
|
40
|
+
href: "/verifications/BZ6V6wsEkufWOpfszp360nj"
|
41
|
+
meta: {}
|
42
|
+
id: BZ6V6wsEkufWOpfszp360nj
|
43
|
+
links:
|
44
|
+
bank_account_verifications.bank_account: "/bank_accounts/{bank_account_verifications.bank_account}"
|
45
|
+
href: "/events/EV602ee24023e511e49dd30647853a3607"
|
46
|
+
type: bank_account_verification.verified
|
47
|
+
id: EV602ee24023e511e49dd30647853a3607
|
48
|
+
links: {}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# This fixture was created based on "debit.succeeded" one.
|
2
|
+
# Couldn't trigger a real "debit.canceled" in a test marketplace.
|
3
|
+
---
|
4
|
+
events:
|
5
|
+
- links: {}
|
6
|
+
occurred_at: '2014-08-14T18:43:51.647000Z'
|
7
|
+
uri: "/events/EVefa81dae23e211e485a802d2dca51d8a"
|
8
|
+
entity:
|
9
|
+
debits:
|
10
|
+
- status: canceled
|
11
|
+
description:
|
12
|
+
links:
|
13
|
+
customer: CU6DfXZjt1WfMr1K2jWsHZUk
|
14
|
+
source: BA3UXn8c8zJ4Vluzntb7h3ZH
|
15
|
+
order:
|
16
|
+
dispute:
|
17
|
+
amount: 50
|
18
|
+
created_at: '2014-08-14T18:43:51.366150Z'
|
19
|
+
updated_at: '2014-08-14T18:43:51.647707Z'
|
20
|
+
failure_reason:
|
21
|
+
currency: USD
|
22
|
+
transaction_number: W679-624-0149
|
23
|
+
href: "/debits/WD7hGWwIl9kQLAScc2bQJsod"
|
24
|
+
meta: {}
|
25
|
+
failure_reason_code:
|
26
|
+
appears_on_statement_as: BAL*example.com
|
27
|
+
id: WD7hGWwIl9kQLAScc2bQJsod
|
28
|
+
links:
|
29
|
+
debits.customer: "/customers/{debits.customer}"
|
30
|
+
debits.dispute: "/disputes/{debits.dispute}"
|
31
|
+
debits.source: "/resources/{debits.source}"
|
32
|
+
debits.order: "/orders/{debits.order}"
|
33
|
+
debits.refunds: "/debits/{debits.id}/refunds"
|
34
|
+
debits.events: "/debits/{debits.id}/events"
|
35
|
+
href: "/events/EVefa81dae23e211e485a802d2dca51d8a"
|
36
|
+
type: debit.canceled
|
37
|
+
id: EVefa81dae23e211e485a802d2dca51d8a
|
38
|
+
links: {}
|
39
|
+
registration:
|
40
|
+
events:
|
41
|
+
- links: {}
|
42
|
+
occurred_at: '2014-08-14T18:43:51.647000Z'
|
43
|
+
uri: "/events/EVefa81dae23e211e485a802d2dca51d8a"
|
44
|
+
entity:
|
45
|
+
debits:
|
46
|
+
- status: canceled
|
47
|
+
description:
|
48
|
+
links:
|
49
|
+
customer: CU6DfXZjt1WfMr1K2jWsHZUk
|
50
|
+
source: BA3UXn8c8zJ4Vluzntb7h3ZH
|
51
|
+
order:
|
52
|
+
dispute:
|
53
|
+
amount: 50
|
54
|
+
created_at: '2014-08-14T18:43:51.366150Z'
|
55
|
+
updated_at: '2014-08-14T18:43:51.647707Z'
|
56
|
+
failure_reason:
|
57
|
+
currency: USD
|
58
|
+
transaction_number: W679-624-0149
|
59
|
+
href: "/debits/WD7hGWwIl9kQLAScc2bQJsod"
|
60
|
+
meta: {}
|
61
|
+
failure_reason_code:
|
62
|
+
appears_on_statement_as: BAL*example.com
|
63
|
+
id: WD7hGWwIl9kQLAScc2bQJsod
|
64
|
+
links:
|
65
|
+
debits.customer: "/customers/{debits.customer}"
|
66
|
+
debits.dispute: "/disputes/{debits.dispute}"
|
67
|
+
debits.source: "/resources/{debits.source}"
|
68
|
+
debits.order: "/orders/{debits.order}"
|
69
|
+
debits.refunds: "/debits/{debits.id}/refunds"
|
70
|
+
debits.events: "/debits/{debits.id}/events"
|
71
|
+
href: "/events/EVefa81dae23e211e485a802d2dca51d8a"
|
72
|
+
type: debit.canceled
|
73
|
+
id: EVefa81dae23e211e485a802d2dca51d8a
|
74
|
+
links: {}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
---
|
2
|
+
events:
|
3
|
+
- links: {}
|
4
|
+
occurred_at: '2014-08-14T18:43:51.647707Z'
|
5
|
+
uri: "/events/EVef85706a23e211e4b78b061e5f402045"
|
6
|
+
entity:
|
7
|
+
debits:
|
8
|
+
- status: succeeded
|
9
|
+
transaction_number: W679-624-0149
|
10
|
+
description:
|
11
|
+
links:
|
12
|
+
customer: CU6DfXZjt1WfMr1K2jWsHZUk
|
13
|
+
source: BA3UXn8c8zJ4Vluzntb7h3ZH
|
14
|
+
order:
|
15
|
+
dispute:
|
16
|
+
created_at: '2014-08-14T18:43:51.366150Z'
|
17
|
+
updated_at: '2014-08-14T18:43:51.647707Z'
|
18
|
+
failure_reason:
|
19
|
+
currency: USD
|
20
|
+
amount: 50
|
21
|
+
href: "/debits/WD7hGWwIl9kQLAScc2bQJsod"
|
22
|
+
meta: {}
|
23
|
+
failure_reason_code:
|
24
|
+
appears_on_statement_as: BAL*example.com
|
25
|
+
id: WD7hGWwIl9kQLAScc2bQJsod
|
26
|
+
links:
|
27
|
+
debits.customer: "/customers/{debits.customer}"
|
28
|
+
debits.dispute: "/disputes/{debits.dispute}"
|
29
|
+
debits.source: "/resources/{debits.source}"
|
30
|
+
debits.order: "/orders/{debits.order}"
|
31
|
+
debits.refunds: "/debits/{debits.id}/refunds"
|
32
|
+
debits.events: "/debits/{debits.id}/events"
|
33
|
+
href: "/events/EVef85706a23e211e4b78b061e5f402045"
|
34
|
+
type: debit.created
|
35
|
+
id: EVef85706a23e211e4b78b061e5f402045
|
36
|
+
links: {}
|
37
|
+
registration:
|
38
|
+
events:
|
39
|
+
- links: {}
|
40
|
+
occurred_at: '2014-08-14T18:43:51.647707Z'
|
41
|
+
uri: "/events/EVef85706a23e211e4b78b061e5f402045"
|
42
|
+
entity:
|
43
|
+
debits:
|
44
|
+
- status: succeeded
|
45
|
+
transaction_number: W679-624-0149
|
46
|
+
description:
|
47
|
+
links:
|
48
|
+
customer: CU6DfXZjt1WfMr1K2jWsHZUk
|
49
|
+
source: BA3UXn8c8zJ4Vluzntb7h3ZH
|
50
|
+
order:
|
51
|
+
dispute:
|
52
|
+
created_at: '2014-08-14T18:43:51.366150Z'
|
53
|
+
updated_at: '2014-08-14T18:43:51.647707Z'
|
54
|
+
failure_reason:
|
55
|
+
currency: USD
|
56
|
+
amount: 50
|
57
|
+
href: "/debits/WD7hGWwIl9kQLAScc2bQJsod"
|
58
|
+
meta: {}
|
59
|
+
failure_reason_code:
|
60
|
+
appears_on_statement_as: BAL*example.com
|
61
|
+
id: WD7hGWwIl9kQLAScc2bQJsod
|
62
|
+
links:
|
63
|
+
debits.customer: "/customers/{debits.customer}"
|
64
|
+
debits.dispute: "/disputes/{debits.dispute}"
|
65
|
+
debits.source: "/resources/{debits.source}"
|
66
|
+
debits.order: "/orders/{debits.order}"
|
67
|
+
debits.refunds: "/debits/{debits.id}/refunds"
|
68
|
+
debits.events: "/debits/{debits.id}/events"
|
69
|
+
href: "/events/EVef85706a23e211e4b78b061e5f402045"
|
70
|
+
type: debit.created
|
71
|
+
id: EVef85706a23e211e4b78b061e5f402045
|
72
|
+
links: {}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
---
|
2
|
+
events:
|
3
|
+
- links: {}
|
4
|
+
occurred_at: '2014-08-14T18:43:51.647000Z'
|
5
|
+
uri: "/events/EVefa81dae23e211e485a802d2dca51d8a"
|
6
|
+
entity:
|
7
|
+
debits:
|
8
|
+
- status: succeeded
|
9
|
+
description:
|
10
|
+
links:
|
11
|
+
customer: CU6DfXZjt1WfMr1K2jWsHZUk
|
12
|
+
source: BA3UXn8c8zJ4Vluzntb7h3ZH
|
13
|
+
order:
|
14
|
+
dispute:
|
15
|
+
amount: 50
|
16
|
+
created_at: '2014-08-14T18:43:51.366150Z'
|
17
|
+
updated_at: '2014-08-14T18:43:51.647707Z'
|
18
|
+
failure_reason:
|
19
|
+
currency: USD
|
20
|
+
transaction_number: W679-624-0149
|
21
|
+
href: "/debits/WD7hGWwIl9kQLAScc2bQJsod"
|
22
|
+
meta: {}
|
23
|
+
failure_reason_code:
|
24
|
+
appears_on_statement_as: BAL*example.com
|
25
|
+
id: WD7hGWwIl9kQLAScc2bQJsod
|
26
|
+
links:
|
27
|
+
debits.customer: "/customers/{debits.customer}"
|
28
|
+
debits.dispute: "/disputes/{debits.dispute}"
|
29
|
+
debits.source: "/resources/{debits.source}"
|
30
|
+
debits.order: "/orders/{debits.order}"
|
31
|
+
debits.refunds: "/debits/{debits.id}/refunds"
|
32
|
+
debits.events: "/debits/{debits.id}/events"
|
33
|
+
href: "/events/EVefa81dae23e211e485a802d2dca51d8a"
|
34
|
+
type: debit.succeeded
|
35
|
+
id: EVefa81dae23e211e485a802d2dca51d8a
|
36
|
+
links: {}
|
37
|
+
registration:
|
38
|
+
events:
|
39
|
+
- links: {}
|
40
|
+
occurred_at: '2014-08-14T18:43:51.647000Z'
|
41
|
+
uri: "/events/EVefa81dae23e211e485a802d2dca51d8a"
|
42
|
+
entity:
|
43
|
+
debits:
|
44
|
+
- status: succeeded
|
45
|
+
description:
|
46
|
+
links:
|
47
|
+
customer: CU6DfXZjt1WfMr1K2jWsHZUk
|
48
|
+
source: BA3UXn8c8zJ4Vluzntb7h3ZH
|
49
|
+
order:
|
50
|
+
dispute:
|
51
|
+
amount: 50
|
52
|
+
created_at: '2014-08-14T18:43:51.366150Z'
|
53
|
+
updated_at: '2014-08-14T18:43:51.647707Z'
|
54
|
+
failure_reason:
|
55
|
+
currency: USD
|
56
|
+
transaction_number: W679-624-0149
|
57
|
+
href: "/debits/WD7hGWwIl9kQLAScc2bQJsod"
|
58
|
+
meta: {}
|
59
|
+
failure_reason_code:
|
60
|
+
appears_on_statement_as: BAL*example.com
|
61
|
+
id: WD7hGWwIl9kQLAScc2bQJsod
|
62
|
+
links:
|
63
|
+
debits.customer: "/customers/{debits.customer}"
|
64
|
+
debits.dispute: "/disputes/{debits.dispute}"
|
65
|
+
debits.source: "/resources/{debits.source}"
|
66
|
+
debits.order: "/orders/{debits.order}"
|
67
|
+
debits.refunds: "/debits/{debits.id}/refunds"
|
68
|
+
debits.events: "/debits/{debits.id}/events"
|
69
|
+
href: "/events/EVefa81dae23e211e485a802d2dca51d8a"
|
70
|
+
type: debit.succeeded
|
71
|
+
id: EVefa81dae23e211e485a802d2dca51d8a
|
72
|
+
links: {}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dune::Balanced::Customer do
|
4
|
+
let(:user) { double('User').as_null_object }
|
5
|
+
let(:params) { ActionController::Parameters.new( {
|
6
|
+
payment: {
|
7
|
+
user: { name: 'Name',
|
8
|
+
address_street: '',
|
9
|
+
address_city: '',
|
10
|
+
address_state: '',
|
11
|
+
address_zip_code: '' } }
|
12
|
+
} ) }
|
13
|
+
|
14
|
+
let(:balanced_customer) do
|
15
|
+
double('::Balanced::Customer', href: '/qwertyuiop').as_null_object
|
16
|
+
end
|
17
|
+
|
18
|
+
before do
|
19
|
+
::Balanced::Customer.stub(:find).and_return(balanced_customer)
|
20
|
+
::Balanced::Customer.stub(:new).and_return(balanced_customer)
|
21
|
+
end
|
22
|
+
|
23
|
+
subject { Dune::Balanced::Customer.new(user, params) }
|
24
|
+
|
25
|
+
describe '#fetch' do
|
26
|
+
context 'when user already has a balanced_contributor associated' do
|
27
|
+
before do
|
28
|
+
contributor = double('Dune::Balanced::Contributor',
|
29
|
+
href: '/qwertyuiop')
|
30
|
+
user.stub(:balanced_contributor).
|
31
|
+
and_return(contributor)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'skips creation of new costumer' do
|
35
|
+
expect(balanced_customer).to_not receive(:save)
|
36
|
+
subject.fetch
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when user don't has balanced_contributor associated" do
|
41
|
+
before do
|
42
|
+
user.stub(:balanced_contributor)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'saves a new costumer' do
|
46
|
+
expect(balanced_customer).to receive(:save)
|
47
|
+
subject.fetch
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'defines user_id in the meta data of the costumer' do
|
51
|
+
customer_attrs = hash_including(meta: hash_including(:user_id))
|
52
|
+
::Balanced::Customer.should_receive(:new).with(customer_attrs)
|
53
|
+
subject.fetch
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#update!' do
|
58
|
+
describe 'update of user attributes' do
|
59
|
+
it "reflects attributes in user's resource " do
|
60
|
+
expect(user).to receive(:update!)
|
61
|
+
subject.update!
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'update balanced customer' do
|
66
|
+
it "balanced_customer should receive save on update" do
|
67
|
+
expect(balanced_customer).to receive(:save)
|
68
|
+
subject.update!
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,219 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dune::Balanced::Event do
|
4
|
+
let(:user) { double('User') }
|
5
|
+
let(:contributor) { double('Dune::Balanced::Contributor', user: user) }
|
6
|
+
let(:notification_type) { 'debit.created' }
|
7
|
+
let(:params) { attributes_for_notification(notification_type) }
|
8
|
+
subject { described_class.new(params) }
|
9
|
+
|
10
|
+
it 'gets the type from request params' do
|
11
|
+
expect(subject.type).to eql('debit.created')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'gets the entity href from request params' do
|
15
|
+
expect(subject.entity_href).to eql('/debits/WD7hGWwIl9kQLAScc2bQJsod')
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'validability' do
|
19
|
+
context 'with predefined types' do
|
20
|
+
before do
|
21
|
+
params[:events].last[:type] = 'bank_account_verification.deposited'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'is valid' do
|
25
|
+
expect(subject).to be_valid
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with types other than the those predefined' do
|
30
|
+
before do
|
31
|
+
params[:events].last[:type] = 'fee_settlement.created'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'is invalid' do
|
35
|
+
expect(subject).to_not be_valid
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#resource' do
|
41
|
+
context 'when exists a contribution' do
|
42
|
+
before do
|
43
|
+
Contribution.stub(:find_by).and_return(Contribution.new)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns a contribution instance' do
|
47
|
+
expect(subject.resource).to be_instance_of(Contribution)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'does not call find_by on Match' do
|
51
|
+
expect(Match).not_to receive(:find_by)
|
52
|
+
subject.resource
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when does not exists a contribution' do
|
57
|
+
before do
|
58
|
+
Contribution.stub(:find_by)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'calls find_by on Match' do
|
62
|
+
expect(Match).to receive(:find_by)
|
63
|
+
subject.resource
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when exists a Match and not a Contribution' do
|
68
|
+
before do
|
69
|
+
Contribution.stub(:find_by)
|
70
|
+
Match.stub(:find_by).and_return(Match.new)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'returns a match instance' do
|
74
|
+
expect(subject.resource).to be_instance_of(Match)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'calls find_by on Contribution' do
|
78
|
+
expect(Contribution).to receive(:find_by)
|
79
|
+
subject.resource
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
shared_examples 'eventable' do
|
85
|
+
before do
|
86
|
+
allow(subject).to receive(:resource).and_return(resource)
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'validability' do
|
90
|
+
context 'when resource exists' do
|
91
|
+
context 'when its value and payment matches' do
|
92
|
+
it { should be_valid }
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'when value does not match with payment' do
|
96
|
+
before do
|
97
|
+
subject.stub_chain(:resource, :price_in_cents).and_return(123_456)
|
98
|
+
end
|
99
|
+
|
100
|
+
it { should_not be_valid }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'when no resource does not exist' do
|
105
|
+
let(:resource) { nil }
|
106
|
+
|
107
|
+
it { should_not be_valid }
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'with \'bank_account_verification.deposited\'' do
|
111
|
+
let(:notification_type) do
|
112
|
+
'bank_account_verification.deposited'
|
113
|
+
end
|
114
|
+
|
115
|
+
it { should be_valid }
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'with \'bank_account_verification.verified\'' do
|
119
|
+
let(:notification_type) do
|
120
|
+
'bank_account_verification.verified'
|
121
|
+
end
|
122
|
+
|
123
|
+
it { should be_valid }
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
shared_examples 'storing payment notification' do
|
128
|
+
it 'creates a new payment notification' do
|
129
|
+
expect(PaymentEngine).to receive(:create_payment_notification).
|
130
|
+
with(hash_including(resource_key => resource.id))
|
131
|
+
subject.save
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'stores metadata of event' do
|
135
|
+
expect(PaymentEngine).to receive(:create_payment_notification).
|
136
|
+
with(hash_including(:extra_data))
|
137
|
+
subject.save
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'sets as changed for observers' do
|
141
|
+
expect(described_class).to receive(:changed)
|
142
|
+
subject.save
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'notifies observers' do
|
146
|
+
expect(described_class).to receive(:notify_observers).with(subject)
|
147
|
+
subject.save
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context 'with debit.created params' do
|
152
|
+
let(:notification_type) { 'debit.created' }
|
153
|
+
|
154
|
+
it_behaves_like 'storing payment notification'
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'with debit.succeeded params' do
|
158
|
+
let(:notification_type) { 'debit.succeeded' }
|
159
|
+
|
160
|
+
it_behaves_like 'storing payment notification'
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'with bank_account_verification.deposited params' do
|
164
|
+
let(:notification_type) { 'bank_account_verification.deposited' }
|
165
|
+
|
166
|
+
it_behaves_like 'storing payment notification'
|
167
|
+
|
168
|
+
it 'gets its contributor from request params' do
|
169
|
+
Dune::Balanced::Contributor.stub(:find_by).
|
170
|
+
with(bank_account_href: '/bank_accounts/BA7AA3yiW6upqETZwU8pyqYg').
|
171
|
+
and_return(contributor)
|
172
|
+
expect(subject.contributor).to eql(contributor)
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'gets its user from request params' do
|
176
|
+
subject.stub(:contributor).and_return(contributor)
|
177
|
+
expect(subject.user).to eql(user)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context 'with debit.canceled params' do
|
182
|
+
let(:notification_type) { 'debit.canceled' }
|
183
|
+
|
184
|
+
it_behaves_like 'storing payment notification'
|
185
|
+
end
|
186
|
+
|
187
|
+
context 'with bank_account_verification.verified params' do
|
188
|
+
let(:notification_type) { 'bank_account_verification.verified' }
|
189
|
+
|
190
|
+
it_behaves_like 'storing payment notification'
|
191
|
+
|
192
|
+
it 'gets its contributor from request params' do
|
193
|
+
Dune::Balanced::Contributor.stub(:find_by).
|
194
|
+
with(bank_account_href: '/bank_accounts/BA7AA3yiW6upqETZwU8pyqYg').
|
195
|
+
and_return(contributor)
|
196
|
+
expect(subject.contributor).to eql(contributor)
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'gets its user from request params' do
|
200
|
+
subject.stub(:contributor).and_return(contributor)
|
201
|
+
expect(subject.user).to eql(user)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context 'when resource is Contribution' do
|
207
|
+
let(:resource) { Contribution.new }
|
208
|
+
let(:resource_key) { :contribution_id }
|
209
|
+
|
210
|
+
it_behaves_like 'eventable'
|
211
|
+
end
|
212
|
+
|
213
|
+
context 'when resource is Match' do
|
214
|
+
let(:resource) { Match.new }
|
215
|
+
let(:resource_key) { :match_id }
|
216
|
+
|
217
|
+
it_behaves_like 'eventable'
|
218
|
+
end
|
219
|
+
end
|