Skip to content

Commit

Permalink
Allow Amend and Cancel Transport Permit for Exempt MHR (#1885)
Browse files Browse the repository at this point in the history
* Enable Amend Cancel Permits for Exempt MHRs
* Disable Amend Transport Permit if not allowed by API (changePermit flag)
* Add Unit Tests
  • Loading branch information
dimak1 authored May 21, 2024
1 parent 924b642 commit dd1125f
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ppr-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ppr-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ppr-ui",
"version": "3.1.29",
"version": "3.1.30",
"private": true,
"appName": "Assets UI",
"sbcName": "SBC Common Components",
Expand Down
33 changes: 31 additions & 2 deletions ppr-ui/src/composables/mhrInformation/useTransportPermits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ import { useStore } from '@/store/store'
import { storeToRefs } from 'pinia'
import { locationChangeTypes } from '@/resources/mhr-transport-permits/transport-permits'
import { LocationChangeTypes } from '@/enums/transportPermits'
import { MhrRegistrationHomeLocationIF, MhrTransportPermitIF, StaffPaymentIF } from '@/interfaces'
import { APIRegistrationTypes, HomeLocationTypes, MhApiStatusTypes, UnitNoteDocTypes } from '@/enums'
import { MhrRegistrationHomeLocationIF, MhrTransportPermitIF, StaffPaymentIF, UnitNoteIF } from '@/interfaces'
import {
APIRegistrationTypes,
HomeLocationTypes,
MhApiStatusTypes,
UnitNoteDocTypes,
UnitNoteStatusTypes
} from '@/enums'
import { cloneDeep, get, isEqual } from 'lodash'

// Global constants
Expand Down Expand Up @@ -149,6 +155,28 @@ export const useTransportPermits = () => {
)
)

/**
* Check if Amend or Cancel Transport Permit is allowed for Exempt MHR based on few conditions.
*
* @returns {boolean} Returns true if:
* - the MHR status is exempt
* - the role is either staff or qualified supplier
* - the registered location is not in BC
* - there is no active exemption registration
* - there is an active transport permit
* - Otherwise, it returns false.
*/
const isExemptMhrTransportPermitChangesEnabled = computed((): boolean =>
getMhrInformation.value.statusType === MhApiStatusTypes.EXEMPT && // mhr status is exempt
(isRoleStaffReg.value || isRoleQualifiedSupplier.value) && // only for staff and qs
getMhrRegistrationLocation.value.address.region !== 'BC' && // civic address is not BC
!getMhrUnitNotes.value.some((unitNote: UnitNoteIF) => // has no active exemption registration
[UnitNoteDocTypes.RESIDENTIAL_EXEMPTION_ORDER, UnitNoteDocTypes.NON_RESIDENTIAL_EXEMPTION]
.includes(unitNote.documentType) &&
unitNote.status === UnitNoteStatusTypes.ACTIVE) &&
hasActiveTransportPermit.value // has active transport permit
)

const resetTransportPermit = async (shouldResetLocationChange: boolean = false): Promise<void> => {
setEmptyMhrTransportPermit(initTransportPermit())
shouldResetLocationChange && setLocationChange(false)
Expand Down Expand Up @@ -342,6 +370,7 @@ export const useTransportPermits = () => {
isRegisteredLocationChange,
isTransportPermitDisabled,
isActivePermitWithinSamePark,
isExemptMhrTransportPermitChangesEnabled,
isValueAmended,
hasAmendmentChanges,
setLocationChange,
Expand Down
5 changes: 3 additions & 2 deletions ppr-ui/src/views/mhrInformation/MhrInformation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -826,14 +826,15 @@ export default defineComponent({
isCancelChangeLocationActive,
isTransportPermitDisabled,
isRegisteredLocationChange,
isExemptMhrTransportPermitChangesEnabled,
setLocationChange,
getUiFeeSummaryLocationType,
getUiLocationType,
resetTransportPermit,
setLocationChangeType,
initTransportPermit,
populateLocationInfoForSamePark,
buildAndSubmitTransportPermit,
buildAndSubmitTransportPermit
} = useTransportPermits()
// Refs
Expand Down Expand Up @@ -890,7 +891,7 @@ export default defineComponent({
showCancelTransportPermitDialog: false,
isTransportPermitDisabled: computed((): boolean =>
localState.showTransferType ||
isExemptMhr.value ||
(isExemptMhr.value && !isExemptMhrTransportPermitChangesEnabled.value) ||
isTransportPermitDisabled.value ||
(!isRoleStaffReg.value && isFrozenMhrDueToAffidavit.value)
),
Expand Down
2 changes: 1 addition & 1 deletion ppr-ui/src/views/mhrInformation/MhrTransportPermit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class=""
color="primary"
:ripple="false"
:disabled="disable"
:disabled="disable || !getTransportPermitChangeAllowed"
data-test-id="amend-transport-permit-btn"
@click="toggleAmendLocationChange()"
>
Expand Down
38 changes: 37 additions & 1 deletion ppr-ui/tests/unit/MhrInformation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ import {
mockedPerson2,
mockedExecutor,
mockedAdministrator,
mockedAddressOutsideBC,
mockedResidentialExemptionOrder,
mockedUnitNotes,
mockedUnitNotes3,
} from './test-data'
import {
CertifyIF,
Expand All @@ -52,6 +56,7 @@ import { TransferDetails, TransferDetailsReview, TransferType } from '@/componen

import { defaultFlagSet, toDisplayPhone } from '@/utils'
import { QualifiedSupplierTransferTypes, StaffTransferTypes, StaffTransferTypesOrg, UnitNotesInfo } from '@/resources'
import { useTransportPermits } from '@/composables'

const store = useStore()

Expand Down Expand Up @@ -1114,7 +1119,7 @@ describe('Mhr Information', async () => {

it('should have read only view for exempt MHR (Residential Exemption filed)', async () => {
// add unit notes with Residential Exemption
// await store.setMhrUnitNotes([mockedResidentialExemptionOrder, ...mockedUnitNotes3])
await store.setMhrUnitNotes([mockedResidentialExemptionOrder, ...mockedUnitNotes3])
await store.setAuthRoles([AuthRoles.PPR_STAFF])
await store.setMhrStatusType(MhApiStatusTypes.EXEMPT)
wrapper.vm.dataLoaded = true
Expand Down Expand Up @@ -1160,4 +1165,35 @@ describe('Mhr Information', async () => {
await store.setMhrStatusType(MhApiStatusTypes.ACTIVE)
})

it('should enable amend and cancel transport permit', async () => {
defaultFlagSet['mhr-transport-permit-enabled'] = true

const transportPermitComposable = useTransportPermits()

// set all conditions to enable the Amend/Cancel Permits
store.setMhrStatusType(MhApiStatusTypes.EXEMPT)
store.setAuthRoles([AuthRoles.PPR_STAFF])
store.setMhrLocation({ key: 'address', value: mockedAddressOutsideBC })
store.setMhrUnitNotes(mockedUnitNotes)
transportPermitComposable.setLocationChange(true) // set this flag to prevent side effect
store.setMhrInformationPermitData({
permitKey: 'Status',
permitData: MhApiStatusTypes.ACTIVE
})

await nextTick()
expect(transportPermitComposable.isExemptMhrTransportPermitChangesEnabled.value).toBe(true)

// set a false condition to disable Amend/Cancel Permit
await store.setMhrInformationPermitData({
permitKey: 'Status',
permitData: MhApiStatusTypes.CANCELLED
})

expect(transportPermitComposable.isExemptMhrTransportPermitChangesEnabled.value).toBe(false)

// reset exempt status
await store.setAuthRoles([AuthRoles.MHR])
})

})
8 changes: 8 additions & 0 deletions ppr-ui/tests/unit/test-data/mock-mhr-registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ export const mockedAddressAlt: AddressIF = {
deliveryInstructions: 'Front Door'
}

export const mockedAddressOutsideBC: AddressIF = {
city: 'TORONTO',
country: 'CA',
postalCode: 'M5E1E5',
region: 'ON',
street: '1 YONGE ST, SUITE 100'
}

export const mockedEmptyGroup: MhrRegistrationHomeOwnerGroupIF = {
groupId: 100,
owners: [],
Expand Down
1 change: 1 addition & 0 deletions ppr-ui/tests/unit/utils/helper-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,5 @@ export async function setupActiveTransportPermit (): Promise<void> {
await store.setMhrTransportPermit({ key: 'newLocation', value: mockTransportPermitNewLocation })
await store.setMhrTransportPermit({ key: 'ownLand', value: true })
await store.setMhrTransportPermitPreviousLocation(mockTransportPermitPreviousLocation)
await store.setTransportPermitChangeAllowed(true)
}

0 comments on commit dd1125f

Please sign in to comment.