Skip to content

Commit

Permalink
Proxy borrowers now inherit group standing/status. (#285)
Browse files Browse the repository at this point in the history
Proxy borrowers now inherit group standing/status.
  • Loading branch information
camillevilla authored Jul 26, 2019
2 parents e2479b2 + 0666038 commit 12d8523
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 12 deletions.
13 changes: 13 additions & 0 deletions app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ def sponsor
members.find(&:sponsor?)
end

def barred?
members.any?(&:barred?)
end

def status
Patron::PATRON_STANDING.fetch(standing, '')
end

def standing
possible_standings = Patron::PATRON_STANDING.keys
members.map(&:standing).min_by { |s| possible_standings.index(s) || Float::INFINITY }
end

def checkouts
@checkouts ||= member_list.flat_map(&:checkouts)
end
Expand Down
28 changes: 20 additions & 8 deletions app/models/patron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ class Patron
CHARGE_LIMIT_THRESHOLD = 25_000

PATRON_STANDING = {
'COLLECTION' => 'Blocked',
'BARRED' => 'Contact us',
'COLLECTION' => 'Blocked',
'BLOCKED' => 'Blocked',
'OK' => 'OK',
'DELINQUENT' => 'OK'
'DELINQUENT' => 'OK',
'OK' => 'OK'
}.freeze

USER_PROFILE = {
Expand All @@ -36,8 +36,24 @@ def barcode
def status
if expired?
'Expired'
elsif proxy_borrower?
# proxy borrowers inherit from the group
group.status
else
PATRON_STANDING.fetch(fields['standing']['key'], '')
PATRON_STANDING.fetch(standing, '')
end
end

def standing
fields.dig('standing', 'key')
end

def barred?
# proxy borrowers inherit from the group
if proxy_borrower?
group.standing == 'BARRED'
else
standing == 'BARRED'
end
end

Expand Down Expand Up @@ -129,10 +145,6 @@ def group?
group.member_list.any?
end

def barred?
fields.dig('standing', 'key') == 'BARRED'
end

def to_partial_path
'patron/patron'
end
Expand Down
55 changes: 55 additions & 0 deletions spec/models/group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,61 @@
end
end

describe '#barred?' do
context 'when a member of the group is barred' do
let(:member_list) do
[
{ key: '1', fields: {} },
{ key: '2', fields: { groupSettings: {
fields: { responsibility: { key: 'SPONSOR' } }
} } },
{ key: '3', fields: { standing: { key: 'BARRED' } } },
{ key: '411612', fields: { firstName: 'Mark (P=Wangchuk)' } }
]
end

it 'is barred' do
expect(group).to be_barred
end
end

context 'with all members in good standing' do
it 'is not barred' do
expect(group).not_to be_barred
end
end
end

describe '#standing' do
let(:member_list) do
[
{ key: '1', fields: {} },
{ key: '2', fields: { standing: { key: 'OK' } } },
{ key: '3', fields: { standing: { key: 'BARRED' } } },
{ key: '411612', fields: { standing: { key: 'OK' } } }
]
end

it 'is the worst possible standing of the members of the group' do
expect(group.standing).to eq 'BARRED'
end
end

describe '#status' do
let(:member_list) do
[
{ key: '1', fields: {} },
{ key: '2', fields: { standing: { key: 'OK' } } },
{ key: '3', fields: { standing: { key: 'DELINQUENT' } } },
{ key: '411612', fields: { standing: { key: 'BLOCKED' } } }
]
end

it 'is the worst possible status of the members of the group' do
expect(group.status).to eq 'Blocked'
end
end

describe '#checkouts' do
let(:member_list) do
[fields: {
Expand Down
51 changes: 47 additions & 4 deletions spec/models/patron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@
fields: {
group: {
fields: {
memberList: [
key: '521187'
]
memberList: member_list
}
}
}
}
}
end

let(:member_list) { [key: '521187'] }

it 'has a key' do
expect(patron.key).to eq '1'
end
Expand Down Expand Up @@ -202,7 +202,16 @@

context 'with a proxy borrower' do
before do
fields[:groupSettings] = { fields: { responsibility: { key: 'PROXY' } } }
fields[:groupSettings] = {
fields: {
responsibility: { key: 'PROXY' },
group: {
fields: {
memberList: member_list
}
}
}
}
fields[:firstName] = 'Second (P=FirstProxyLN)'
end

Expand All @@ -217,6 +226,40 @@
expect(patron.proxy_borrower_name).to eq 'Proxy FirstProxyLN'
end
end

describe '#status' do
context 'when the group is blocked' do
let(:member_list) do
[
{ key: '1', fields: {} },
{ key: '2', fields: { standing: { key: 'OK' } } },
{ key: '3', fields: { standing: { key: 'DELINQUENT' } } },
{ key: '411612', fields: { standing: { key: 'BLOCKED' } } }
]
end

it 'inherits the group status' do
expect(patron.status).to eq 'Blocked'
end
end
end

describe '#barred?' do
context 'when the group is barred' do
let(:member_list) do
[
{ key: '1', fields: {} },
{ key: '2', fields: { standing: { key: 'OK' } } },
{ key: '3', fields: { standing: { key: 'DELINQUENT' } } },
{ key: '411612', fields: { standing: { key: 'BARRED' } } }
]
end

it 'inherits the group barred status' do
expect(patron).to be_barred
end
end
end
end

it 'is not a sponsor' do
Expand Down

0 comments on commit 12d8523

Please sign in to comment.