Skip to content

Commit

Permalink
Map 1363 move basm api to use new roll count (#2280)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mjwillis authored Jun 28, 2024
1 parent c475462 commit 5828895
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 62 deletions.
4 changes: 2 additions & 2 deletions app/lib/nomis_client/rollcount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
module NomisClient
class Rollcount
class << self
def get(agency_id:, unassigned:)
NomisClient::Base.get("/movements/rollcount/#{agency_id}?unassigned=#{unassigned}").parsed
def get(agency_id:)
NomisClient::Base.get("/prison/roll-count/#{agency_id}").parsed
end
end
end
Expand Down
8 changes: 3 additions & 5 deletions app/services/populations/defaults_from_nomis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ module Populations
class DefaultsFromNomis
def self.call(location, date)
nomis_agency_id = location.nomis_agency_id
assigned_cells = NomisClient::Rollcount.get(agency_id: nomis_agency_id, unassigned: false)
unassigned_cells = NomisClient::Rollcount.get(agency_id: nomis_agency_id, unassigned: true)
all_cells = NomisClient::Rollcount.get(agency_id: nomis_agency_id)
movements = NomisClient::Movements.get(agency_id: nomis_agency_id, date:)
discharges = NomisClient::Discharges.get(agency_id: nomis_agency_id, date:)

return {} unless assigned_cells.present? && unassigned_cells.present? && movements.present?
return {} unless all_cells.present? && movements.present?

all_cells = [assigned_cells, unassigned_cells].flatten
cell_total = all_cells.compact.sum { |cell| cell['currentlyInCell'].to_i }
cell_total = all_cells['totals']['currentlyInCell']
arrivals = movements['in'].to_i
discharges = discharges.length

Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
db:
image: postgres
Expand Down
25 changes: 18 additions & 7 deletions spec/fixtures/files/nomis/get_rollcount_200.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
[
{"livingUnitId":8839, "livingUnitDesc":"COURT", "bedsInUse":33, "currentlyInCell":2, "currentlyOut":31, "maximumCapacity":400, "availablePhysical":367, "outOfOrder":0},
{"livingUnitId":180030, "livingUnitDesc":"CSWAP", "bedsInUse":0, "currentlyInCell":0, "currentlyOut":0, "maximumCapacity":50, "availablePhysical":50, "outOfOrder":0},
{"livingUnitId":185744, "livingUnitDesc":"REC/OUT", "bedsInUse":1, "currentlyInCell":0, "currentlyOut":1, "maximumCapacity":100, "availablePhysical":99, "outOfOrder":0},
{"livingUnitId":4021, "livingUnitDesc":"RECP", "bedsInUse":7, "currentlyInCell":7, "currentlyOut":0, "maximumCapacity":100, "availablePhysical":93, "outOfOrder":0},
{"livingUnitId":8838, "livingUnitDesc":"TAP", "bedsInUse":12, "currentlyInCell":0, "currentlyOut":12, "maximumCapacity":50, "availablePhysical":38, "outOfOrder":0}
]
{
"prisonId": "PRI",
"numUnlockRollToday": 0,
"numCurrentPopulation": 97,
"numArrivedToday": 0,
"numInReception": 0,
"numStillToArrive": 0,
"numOutToday": 0,
"numNoCellAllocated": 0,
"totals": {
"bedsInUse": 53,
"currentlyInCell": 7,
"currentlyOut": 44,
"workingCapacity": 0,
"netVacancies": 0,
"outOfOrder": 0
}
}
33 changes: 18 additions & 15 deletions spec/lib/nomis_client/rollcount_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,31 @@

RSpec.describe NomisClient::Rollcount, with_nomis_client_authentication: true do
describe '.get' do
let(:response) { described_class.get(agency_id:, unassigned:) }
let(:response) { described_class.get(agency_id:) }
let(:agency_id) { 'PRI' }
let(:unassigned) { true }

context 'when a resource is found' do
let(:response_status) { 200 }
let(:response_body) { file_fixture('nomis/get_rollcount_200.json').read }

it 'has the correct number of results' do
expect(response.count).to be 5
end

it 'returns the correct data' do
expect(response.first.symbolize_keys).to eq({
availablePhysical: 367,
bedsInUse: 33,
currentlyInCell: 2,
currentlyOut: 31,
livingUnitDesc: 'COURT',
livingUnitId: 8839,
maximumCapacity: 400,
outOfOrder: 0,
expect(response.symbolize_keys).to eq({
prisonId: 'PRI',
numUnlockRollToday: 0,
numCurrentPopulation: 97,
numArrivedToday: 0,
numInReception: 0,
numStillToArrive: 0,
numOutToday: 0,
numNoCellAllocated: 0,
totals: {
'bedsInUse' => 53,
'currentlyInCell' => 7,
'currentlyOut' => 44,
'workingCapacity' => 0,
'netVacancies' => 0,
'outOfOrder' => 0,
},
})
end
end
Expand Down
38 changes: 7 additions & 31 deletions spec/services/populations/defaults_from_nomis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@
let(:location) { create(:location, :prison, nomis_agency_id: agency_id) }
let(:date) { Time.zone.today }

let(:assigned_cells) do
[
{ 'currentlyInCell' => 3 },
{ 'currentlyInCell' => 4 },
]
end
let(:unassigned_cells) do
[
{ 'currentlyInCell' => 1 },
]
let(:all_cells) do
{
'totals' => { 'currentlyInCell' => 8 },
}
end
let(:movements) { { 'in' => 10, 'out' => 5 } }
let(:discharges) do
Expand All @@ -29,8 +23,7 @@
end

before do
allow(NomisClient::Rollcount).to receive(:get).with(agency_id:, unassigned: false).and_return(assigned_cells)
allow(NomisClient::Rollcount).to receive(:get).with(agency_id:, unassigned: true).and_return(unassigned_cells)
allow(NomisClient::Rollcount).to receive(:get).with(agency_id:).and_return(all_cells)
allow(NomisClient::Movements).to receive(:get).with(agency_id:, date:).and_return(movements)
allow(NomisClient::Discharges).to receive(:get).with(agency_id:, date:).and_return(discharges)
end
Expand All @@ -44,24 +37,8 @@
end
end

context 'with blank rollcount details from Nomis' do
let(:unassigned_cells) do
[
nil,
]
end

it 'returns correct unlock and discharges' do
expect(defaults).to eq({
unlock: 3 + 4 - 10 + 2,
discharges: 2,
})
end
end

context 'with missing rollcount details from Nomis' do
let(:assigned_cells) { nil }
let(:unassigned_cells) { nil }
let(:all_cells) { nil }

it 'returns empty hash' do
expect(defaults).to be_empty
Expand All @@ -77,8 +54,7 @@
end

context 'with missing rollcount and movement details from Nomis' do
let(:assigned_cells) { nil }
let(:unassigned_cells) { nil }
let(:all_cells) { nil }
let(:movements) { nil }
let(:discharges) { nil }

Expand Down

0 comments on commit 5828895

Please sign in to comment.