rock_rms 1.3.0 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1b5a8912599ca1d74291a287765abdf6f283efb
4
- data.tar.gz: 031df795a7215c4d7c5c2ea350ae9e465b7a9c25
3
+ metadata.gz: 765aea7d65ac938d72b224db13b53ef9a14a01a4
4
+ data.tar.gz: e61962b4c4647bd2c0a75a654c6662ab9a3adcd0
5
5
  SHA512:
6
- metadata.gz: e55025ccb035d05122bb77d4ea7028c35313b48ef607c39d1e119fc72d80b108fe7763fa785613d3aa33b17d47afece8a17a2690f27947437b9784751229250b
7
- data.tar.gz: 1c8b77ad4eca61e4284a6eabcac460ef3fcdb795d3db0aa3654de546ecb58838e5545b4da744d1f499fc180c9dbbfd8fdc732756bdca58ae55aa9672c686e98d
6
+ metadata.gz: 2fbbab71f6c18d1ee19ec069ac1eec9223240bff7a9e38dfcf7256e9d6f4d018af61f1c7be2a15ee07f886eeb950637ae2f210ebfd20136bf7a311882ae61ca4
7
+ data.tar.gz: ae2d0c9953da765fe8af28c1b672bfb97006c260d97254447e945776f8c1ea77657562280d45463dcaa52b576b1df3fe4fa253d0864bf7c92888ea11ef06ba4f
@@ -2,16 +2,18 @@ module RockRMS
2
2
  class Client
3
3
  module TransactionDetail
4
4
  def list_transaction_details(options = {})
5
- get(transaction_detail_path, options)
5
+ res = get(transaction_detail_path, options)
6
+ RockRMS::Responses::TransactionDetail.format(res)
6
7
  end
7
8
 
8
9
  def find_transaction_detail(id)
9
- get(transaction_detail_path(id))
10
+ res = get(transaction_detail_path(id))
11
+ RockRMS::Responses::TransactionDetail.format(res)
10
12
  end
11
13
 
12
- def update_transaction_detail(id, account_id:)
14
+ def update_transaction_detail(id, fund_id:)
13
15
  options = {
14
- 'AccountId' => account_id
16
+ 'AccountId' => fund_id
15
17
  }
16
18
  patch(transaction_detail_path(id), options)
17
19
  end
@@ -1,25 +1,39 @@
1
1
  module RockRMS
2
2
  module Responses
3
3
  class Donation
4
+ MAP = {
5
+ id: 'Id',
6
+ date: 'TransactionDateTime',
7
+ person_id: 'AuthorizedPersonAliasId',
8
+ batch_id: 'BatchId',
9
+ recurring_donation_id: 'ScheduledTransactionId',
10
+ summary: 'Summary',
11
+ transaction_code: 'TransactionCode',
12
+ details: 'TransactionDetails'
13
+ }.freeze
14
+
4
15
  def self.format(response)
5
16
  if response.is_a?(Array)
6
- response.map { |donation| format_donation(donation) }
17
+ response.map { |data| format_single(data) }
7
18
  else
8
- format_donation(response)
19
+ format_single(response)
20
+ end
21
+ end
22
+
23
+ def self.format_single(data)
24
+ response = MAP.each.with_object({}) do |(l, r), object|
25
+ object[l] = if l == :details
26
+ RockRMS::Responses::TransactionDetail.format(data[r])
27
+ else
28
+ data[r]
29
+ end
9
30
  end
31
+ response[:amount] = calculate_total(response[:details])
32
+ response
10
33
  end
11
34
 
12
- def self.format_donation(donation)
13
- {
14
- id: donation['Id'],
15
- date: donation['TransactionDateTime'],
16
- amount: donation['TransactionDetails'].reduce(0) { |sum, td| sum + td['Amount'] },
17
- person_id: donation['AuthorizedPersonAliasId'],
18
- fund: '',
19
- batch_id: donation['BatchId'],
20
- recurring_donation_id: donation['ScheduledTransactionId'],
21
- summary: donation['Summary']
22
- }
35
+ def self.calculate_total(details)
36
+ details.reduce(0) { |sum, td| sum + td[:amount] }
23
37
  end
24
38
  end
25
39
  end
@@ -0,0 +1,25 @@
1
+ module RockRMS
2
+ module Responses
3
+ class TransactionDetail
4
+ MAP = {
5
+ id: 'Id',
6
+ fund_id: 'AccountId',
7
+ amount: 'Amount'
8
+ }.freeze
9
+
10
+ def self.format(data)
11
+ if data.is_a?(Array)
12
+ data.map { |object| format_single(object) }
13
+ else
14
+ format_single(data)
15
+ end
16
+ end
17
+
18
+ def self.format_single(data)
19
+ MAP.each.with_object({}) do |(l, r), object|
20
+ object[l] = data[r]
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module RockRMS
2
- VERSION = '1.3.0'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RockRMS::Client::TransactionDetail, type: :model do
4
+ include_context 'resource specs'
5
+
6
+ describe '#list_transaction_details' do
7
+ it 'returns a array' do
8
+ resource = client.list_transaction_details
9
+ expect(resource).to be_a(Array)
10
+ expect(resource.first).to be_a(Hash)
11
+ end
12
+ end
13
+
14
+ describe '#find_transaction_detail(id)' do
15
+ it 'returns a hash' do
16
+ expect(client.find_transaction_detail(123)).to be_a(Hash)
17
+ end
18
+
19
+ it 'queries ' do
20
+ expect(client).to receive(:get).with('FinancialTransactionDetails/123')
21
+ .and_call_original
22
+
23
+ resource = client.find_transaction_detail(123)
24
+
25
+ expect(resource[:id]).to eq(345)
26
+ end
27
+
28
+ it 'formats with TransactionDetail' do
29
+ response = double
30
+ expect(RockRMS::Responses::TransactionDetail).to receive(:format).with(response)
31
+ allow(client).to receive(:get).and_return(response)
32
+ client.find_transaction_detail(123)
33
+ end
34
+ end
35
+
36
+ describe '#update_transaction_detail' do
37
+ subject(:resource) do
38
+ client.update_transaction_detail(
39
+ 123,
40
+ fund_id: 2,
41
+ )
42
+ end
43
+
44
+ it 'returns nothing' do
45
+ expect(client.update_transaction_detail(123, fund_id: 5)).to eq(nil)
46
+ end
47
+
48
+ it 'passes options' do
49
+ expect(client).to receive(:patch)
50
+ .with(
51
+ 'FinancialTransactionDetails/123',
52
+ 'AccountId' => 2
53
+ ).and_call_original
54
+ resource
55
+ end
56
+ end
57
+ end
@@ -19,6 +19,11 @@ RSpec.describe RockRMS::Responses::Donation, type: :model do
19
19
  expect(r[:batch_id]).to eq(p['BatchId'])
20
20
  expect(r[:recurring_donation_id]).to eq(p['ScheduledTransactionId'])
21
21
  expect(r[:summary]).to eq(p['Summary'])
22
+ expect(r[:transaction_code]).to eq(p['TransactionCode'])
23
+ expect(r[:details]).to eq(
24
+ RockRMS::Responses::TransactionDetail.format(p['TransactionDetails'])
25
+ )
26
+ expect(r[:amount]).to eq(100.00)
22
27
  end
23
28
  end
24
29
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RockRMS::Responses::TransactionDetail, type: :model do
4
+ let(:parsed) { JSON.parse(FixturesHelper.read('transaction_details.json')) }
5
+
6
+ describe '.format' do
7
+ subject(:result) { described_class.format(parsed) }
8
+
9
+ context 'when response is array' do
10
+ it 'returns an array' do
11
+ expect(described_class.format([])).to be_a(Array)
12
+ end
13
+ end
14
+
15
+ it 'translates keys' do
16
+ result.zip(parsed) do |r, p|
17
+ expect(r[:id]).to eq(p['Id'])
18
+ expect(r[:fund_id]).to eq(p['AccountId'])
19
+ expect(r[:amount]).to eq(p['Amount'])
20
+ end
21
+ end
22
+ end
23
+ end
@@ -33,7 +33,11 @@
33
33
  "TransactionCode": 1239,
34
34
  "TransactionDateTime": "2013-01-06T00:00:00",
35
35
  "TransactionTypeValue": null,
36
- "TransactionDetails": [],
36
+ "TransactionDetails": [{
37
+ "Id": 345,
38
+ "AccountId": 23,
39
+ "Amount": 100.00
40
+ }],
37
41
  "TransactionTypeValueId": 53
38
42
  }
39
43
  ]
@@ -0,0 +1,23 @@
1
+ {
2
+ "TransactionId": 1422,
3
+ "AccountId": 23,
4
+ "IsNonCash": false,
5
+ "Amount": 100.00,
6
+ "Summary": null,
7
+ "EntityTypeId": null,
8
+ "EntityId": null,
9
+ "Account": null,
10
+ "EntityType": null,
11
+ "CreatedDateTime": "2018-01-25T02:00:14.973",
12
+ "ModifiedDateTime": "2018-01-25T02:00:14.973",
13
+ "CreatedByPersonAliasId": null,
14
+ "ModifiedByPersonAliasId": null,
15
+ "ModifiedAuditValuesAlreadyUpdated": false,
16
+ "Attributes": null,
17
+ "AttributeValues": null,
18
+ "Id": 345,
19
+ "Guid": "a3bdcc01-5476-4e08-8245-dec2630c9471",
20
+ "ForeignId": null,
21
+ "ForeignGuid": null,
22
+ "ForeignKey": null
23
+ }
@@ -0,0 +1,25 @@
1
+ [
2
+ {
3
+ "TransactionId": 1422,
4
+ "AccountId": 23,
5
+ "IsNonCash": false,
6
+ "Amount": 100.00,
7
+ "Summary": null,
8
+ "EntityTypeId": null,
9
+ "EntityId": null,
10
+ "Account": null,
11
+ "EntityType": null,
12
+ "CreatedDateTime": "2018-01-25T02:00:14.973",
13
+ "ModifiedDateTime": "2018-01-25T02:00:14.973",
14
+ "CreatedByPersonAliasId": null,
15
+ "ModifiedByPersonAliasId": null,
16
+ "ModifiedAuditValuesAlreadyUpdated": false,
17
+ "Attributes": null,
18
+ "AttributeValues": null,
19
+ "Id": 345,
20
+ "Guid": "a3bdcc01-5476-4e08-8245-dec2630c9471",
21
+ "ForeignId": null,
22
+ "ForeignGuid": null,
23
+ "ForeignKey": null
24
+ }
25
+ ]
@@ -26,8 +26,10 @@ class RockMock < Sinatra::Base
26
26
  groups: 'Groups',
27
27
  people_search: 'People/Search',
28
28
  phone_numbers: 'PhoneNumbers',
29
- recurring_donation: 'FinancialScheduledTransactions/:id',
30
- recurring_donations: 'FinancialScheduledTransactions'
29
+ recurring_donation: 'FinancialScheduledTransactions/:id',
30
+ recurring_donations: 'FinancialScheduledTransactions',
31
+ transaction_detail: 'FinancialTransactionDetails/:id',
32
+ transaction_details: 'FinancialTransactionDetails'
31
33
  }.each do |json, end_point|
32
34
  get "/api/#{end_point}" do
33
35
  json_response 200, "#{json}.json"
@@ -49,7 +51,8 @@ class RockMock < Sinatra::Base
49
51
  [
50
52
  'FinancialBatches/:id',
51
53
  'FinancialScheduledTransactions/:id',
52
- 'FinancialTransactions/:id'
54
+ 'FinancialTransactions/:id',
55
+ 'FinancialTransactionDetails/:id'
53
56
  ].each do |end_point|
54
57
  patch "/api/#{end_point}" do
55
58
  content_type :json
@@ -60,12 +63,12 @@ class RockMock < Sinatra::Base
60
63
  post '/api/Auth/Login' do
61
64
  content_type :json
62
65
 
63
- response['Cache-Control'] = 'no-cache'
66
+ response['Cache-Control'] = 'no-cache'
64
67
  response['Content-Secuity-Policy'] = "frame-ancestors 'self'"
65
- response['Date'] = Time.now.httpdate
66
- response['Expires'] = '-1'
67
- response['Pragma'] = 'no-cache'
68
- response['Set-Cookie'] = [
68
+ response['Date'] = Time.now.httpdate
69
+ response['Expires'] = '-1'
70
+ response['Pragma'] = 'no-cache'
71
+ response['Set-Cookie'] = [
69
72
  ".ROCK=#{SecureRandom.hex(100)}",
70
73
  "expires=#{(Time.now + 14).httpdate}",
71
74
  'path=/',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rock_rms
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Brooks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-25 00:00:00.000000000 Z
11
+ date: 2018-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -205,6 +205,7 @@ files:
205
205
  - lib/rock_rms/responses/phone_number.rb
206
206
  - lib/rock_rms/responses/recurring_donation.rb
207
207
  - lib/rock_rms/responses/recurring_donation_details.rb
208
+ - lib/rock_rms/responses/transaction_detail.rb
208
209
  - lib/rock_rms/version.rb
209
210
  - rock_rms.gemspec
210
211
  - spec/rock_rms/client_spec.rb
@@ -216,6 +217,7 @@ files:
216
217
  - spec/rock_rms/resources/person_spec.rb
217
218
  - spec/rock_rms/resources/phone_number_spec.rb
218
219
  - spec/rock_rms/resources/recurring_donation_spec.rb
220
+ - spec/rock_rms/resources/transaction_detail_spec.rb
219
221
  - spec/rock_rms/responses/campus_spec.rb
220
222
  - spec/rock_rms/responses/donation_spec.rb
221
223
  - spec/rock_rms/responses/group_location_spec.rb
@@ -224,6 +226,7 @@ files:
224
226
  - spec/rock_rms/responses/phone_number_spec.rb
225
227
  - spec/rock_rms/responses/recurring_donation_details_spec.rb
226
228
  - spec/rock_rms/responses/recurring_donation_spec.rb
229
+ - spec/rock_rms/responses/transaction_detail_spec.rb
227
230
  - spec/rock_rms_spec.rb
228
231
  - spec/spec_helper.rb
229
232
  - spec/support/client_factory.rb
@@ -248,6 +251,8 @@ files:
248
251
  - spec/support/fixtures/recurring_donation.json
249
252
  - spec/support/fixtures/recurring_donation_details.json
250
253
  - spec/support/fixtures/recurring_donations.json
254
+ - spec/support/fixtures/transaction_detail.json
255
+ - spec/support/fixtures/transaction_details.json
251
256
  - spec/support/fixtures_helper.rb
252
257
  - spec/support/rock_mock.rb
253
258
  homepage: https://github.com/taylorbrooks/rock_rms