Skip to content

Commit

Permalink
Merge pull request #562 from SFDigitalServices/release-12-14-2022
Browse files Browse the repository at this point in the history
December 2022 Release
  • Loading branch information
christine-sfg authored Dec 23, 2022
2 parents 2b11bdc + 8a7550e commit 46389a6
Show file tree
Hide file tree
Showing 13 changed files with 472 additions and 354 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ yarn-debug.log*
.env
/public/packs
/public/packs-test
/node_modules
npm-debug.log

# Using yarn rather than npm
package-lock.json
coverage
TAGS

# IDE
.vscode/*
!.vscode-default/*
.idea/*
*.iml
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ gem 'rails', '~> 5.2.5'
# Set a minimum version for Rack to avoid security vulnerability in Rack <2.2.3
gem 'rack', '>= 2.2.3'
# Use Puma as the app server
gem 'puma', '~> 3.12.6'
gem 'puma', '~> 4.3.12'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
Expand All @@ -33,6 +33,7 @@ gem 'jbuilder', '~> 2.5'
# gem 'capistrano-rails', group: :development

gem 'newrelic_rpm'
gem 'mini_portile2', '~> 2.5', '>= 2.5.1'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
Expand Down
16 changes: 9 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ GEM
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.7.0)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
arel (9.0.0)
ast (2.4.0)
Expand Down Expand Up @@ -128,14 +128,14 @@ GEM
marcel (1.0.0)
method_source (1.0.0)
mini_mime (1.0.3)
mini_portile2 (2.5.0)
mini_portile2 (2.5.1)
minitest (5.14.4)
multi_json (1.14.1)
multi_xml (0.6.0)
multipart-post (2.1.1)
newrelic_rpm (6.9.0.363)
nio4r (2.5.7)
nokogiri (1.11.2)
nio4r (2.5.8)
nokogiri (1.11.4)
mini_portile2 (~> 2.5.0)
racc (~> 1.4)
oauth2 (1.4.4)
Expand Down Expand Up @@ -173,8 +173,9 @@ GEM
pry (~> 0.13.0)
pry-rails (0.3.9)
pry (>= 0.10.4)
public_suffix (4.0.3)
puma (3.12.6)
public_suffix (4.0.6)
puma (4.3.12)
nio4r (~> 2.0)
racc (1.5.2)
rack (2.2.3)
rack-proxy (0.6.5)
Expand Down Expand Up @@ -363,6 +364,7 @@ DEPENDENCIES
hashie (~> 3.5)
jbuilder (~> 2.5)
listen (>= 3.0.5, < 3.2)
mini_portile2 (~> 2.5, >= 2.5.1)
newrelic_rpm
oj
omniauth-rails_csrf_protection
Expand All @@ -371,7 +373,7 @@ DEPENDENCIES
pg (~> 0.21.0)
pry-byebug (~> 3.9.0)
pry-rails
puma (~> 3.12.6)
puma (~> 4.3.12)
rack (>= 2.2.3)
rails (~> 5.2.5)
rails-controller-testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,18 @@ const Lease = ({ form, values }) => {
...map(confirmedPreferences, pluck('id', 'preference_name'))
])

/**
* available units fit the following criteria
* - if it doesn't have any leases
* - if there are leases, they cannot be in draft or signed status
* - if the unit has an application, it must match the current one
*/
const unavailableStatuses = ['Draft', 'Signed']
const availableUnits = state.units.filter(
(unit) => !unit.application_id || unit.application_id === state.application.id
(unit) =>
!Array.isArray(unit.leases) ||
!unit.leases.some((lease) => unavailableStatuses.includes(lease.lease_status)) ||
unit.leases.some((lease) => lease.application_id === state.application.id)
)

const availableUnitsOptions = formUtils.toOptions(
Expand All @@ -166,10 +176,18 @@ const Lease = ({ form, values }) => {
return prefUsed?.preference_name === pref
}

/**
* Checks if a given unit is using the same preference as the provided preference
* @param unit
* @param pref
* @return {false|*} returns true if the unit is used with the same preference on a different application
*/
const unitIsUsedWithPrefElsewhere = (unit, pref) =>
unit.application_id &&
unit.application_id !== state.application.id &&
unit.preference_used_name === pref
Array.isArray(unit.leases) &&
unit.leases.some(
(lease) =>
lease.application_id !== state.application.id && pref === lease.preference_used_name
)

const numUnitsUsingPref = (pref) =>
state.units.filter(
Expand Down
1 change: 1 addition & 0 deletions app/models/force/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Unit < Force::ObjectBase
{ domain: 'max_ami_for_qualifying_unit', salesforce: 'Max_AMI_for_Qualifying_Unit' },
{ domain: 'reserved_type', salesforce: 'Reserved_Type' },
{ domain: 'priority_type', salesforce: 'Priority_Type' },
{ domain: 'leases', salesforce: 'Leases' }
].freeze
end
end
18 changes: 10 additions & 8 deletions app/services/force/units_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ class UnitsService < Force::Base
FIELDS = load_fields(FIELD_NAME).freeze

# Returns units and relevant lease information for specified listing.
# Units contain info about unit number + eligibility. We merge
# this with Lease info about which application is assigned to a unit and
# what preference was used.
# Units contain info about unit number + eligibility. We join
# this with info from Leases
def units_and_leases_for_listing(listing_id)
lease_query = builder.from(:Leases__r)
.select('Application__c, Preference_Used_Name__c')
.select('Application__c, Lease_Status__c, Preference_Used_Name__c')
.to_soql

result = builder.from(:Unit__c)
Expand All @@ -23,12 +22,15 @@ def units_and_leases_for_listing(listing_id)
.query
.records

#format/convert unit and lease objects
domain_units = result.map do |unit|
# Flatten lease fields and merge with unit fields
lease = unit['Leases'] ? unit['Leases'][0] : nil
domain_lease_fields = Force::Lease.from_salesforce(lease).to_domain if lease
domain_unit = Force::Unit.from_salesforce(unit).to_domain
domain_unit.merge(domain_lease_fields || {})
if domain_unit['leases']
domain_unit['leases'] = domain_unit['leases']
.filter { |lease| true if lease }
.map { |lease| Force::Lease.from_salesforce(lease).to_domain }
end
domain_unit
end
domain_units
end
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"final-form": "^4.19.0",
"final-form-arrays": "^1.1.2",
"flat": "^5.0.0",
"lodash": "^4.17.19",
"lodash": "^4.17.21",
"moment": "^2.24.0",
"moment-timezone": "^0.5.25",
"postcss-import": "^12.0.1",
Expand Down Expand Up @@ -72,7 +72,7 @@
"eslint-plugin-react": "^7.20.6",
"eslint-plugin-react-hooks": "^4.1.2",
"eslint-plugin-standard": "^4.0.1",
"grunt": "^1.0.4",
"grunt": "^1.3.0",
"grunt-contrib-clean": "2.0.0",
"grunt-contrib-copy": "1.0.0",
"grunt-json-remove-fields": "^0.1.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ jest.mock('apiService', () => {
unit_type: 'studio',
priority_type: null,
max_ami_for_qualifying_unit: 50,
application_id: 'other application'
leases: [
{
application_id: 'testId',
preference_used_name: '',
lease_status: 'Signed'
}
]
})

return listingId === _ID_NO_AVAILABLE_UNITS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1696,6 +1696,11 @@ Array [
>
2021
</option>
<option
value={2022}
>
2022
</option>
</select>
</div>
</div>
Expand Down
7 changes: 6 additions & 1 deletion spec/services/force/unit_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
describe '#units_and_leases_for_listing' do
expected_lease_keys = %i[
application_id
lease_status
preference_used_name
]

Expand All @@ -23,15 +24,19 @@
unit_number
unit_type
ami_chart_year
leases
]

it 'should return lease fields when there is a lease on the unit' do
VCR.use_cassette('services/force/unit_service/with_lease') do
units = subject.units_and_leases_for_listing(LEASE_UP_LISTING_ID)

(expected_lease_keys + expected_unit_keys).each do |key|
(expected_unit_keys).each do |key|
expect(units.first).to have_key(key)
end
(expected_lease_keys).each do |key|
expect(units.first.leases.first).to have_key(key)
end
end
end

Expand Down
Loading

0 comments on commit 46389a6

Please sign in to comment.