forked from ustaxcourt/ef-cms
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1455 from ustaxcourt/test
Merge Test into Staging
- Loading branch information
Showing
16 changed files
with
658 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
shared/src/business/useCaseHelper/caseAssociation/removeCounselFromRemovedPetitioner.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const { | ||
isAuthorized, | ||
ROLE_PERMISSIONS, | ||
} = require('../../../authorization/authorizationClientService'); | ||
const { UnauthorizedError } = require('../../../errors/errors'); | ||
|
||
/** | ||
* removeCounselFromRemovedPetitioner | ||
* | ||
* @param {object} options the options object | ||
* @param {object} options.applicationContext the applicationContext | ||
* @param {object} options.caseEntity the case entity to modify and return | ||
* @param {string} options.petitionerContactId the contactId of the petitioner being removed from the case | ||
* @returns {Case} the updated case entity | ||
*/ | ||
exports.removeCounselFromRemovedPetitioner = async ({ | ||
applicationContext, | ||
caseEntity, | ||
petitionerContactId, | ||
}) => { | ||
const authorizedUser = applicationContext.getCurrentUser(); | ||
|
||
if ( | ||
!isAuthorized(authorizedUser, ROLE_PERMISSIONS.QC_PETITION) && | ||
!isAuthorized(authorizedUser, ROLE_PERMISSIONS.REMOVE_PETITIONER) | ||
) { | ||
throw new UnauthorizedError('Unauthorized'); | ||
} | ||
|
||
const practitioners = | ||
caseEntity.getPractitionersRepresenting(petitionerContactId); | ||
|
||
for (const practitioner of practitioners) { | ||
if (!practitioner.isRepresenting(petitionerContactId)) continue; | ||
|
||
if (practitioner.representing.length === 1) { | ||
caseEntity.removePrivatePractitioner(practitioner); | ||
|
||
await applicationContext.getPersistenceGateway().deleteUserFromCase({ | ||
applicationContext, | ||
docketNumber: caseEntity.docketNumber, | ||
userId: practitioner.userId, | ||
}); | ||
} else { | ||
caseEntity.removeRepresentingFromPractitioners(petitionerContactId); | ||
} | ||
} | ||
|
||
return caseEntity.validate(); | ||
}; |
124 changes: 124 additions & 0 deletions
124
shared/src/business/useCaseHelper/caseAssociation/removeCounselFromRemovedPetitioner.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
const { | ||
applicationContext, | ||
} = require('../../test/createTestApplicationContext'); | ||
const { | ||
CONTACT_TYPES, | ||
PARTY_TYPES, | ||
ROLES, | ||
} = require('../../entities/EntityConstants'); | ||
const { | ||
MOCK_PRACTITIONER, | ||
petitionsClerkUser, | ||
} = require('../../../test/mockUsers'); | ||
const { | ||
removeCounselFromRemovedPetitioner, | ||
} = require('./removeCounselFromRemovedPetitioner'); | ||
const { Case } = require('../../entities/cases/Case'); | ||
const { MOCK_CASE } = require('../../../test/mockCase'); | ||
|
||
describe('removeCounselFromRemovedPetitioner', () => { | ||
const mockContactPrimaryId = MOCK_CASE.petitioners[0].contactId; | ||
const mockContactSecondaryId = 'bff888e0-6070-40ac-a7d0-6b4d88ef4b01'; | ||
const mockSecondPractitionerUserId = '5dde0389-6e09-4e2f-a7f4-34e4f2a534a8'; | ||
const mockThirdPractitionerUserId = '0bd63272-781f-4cbd-8b7d-7cb649ca255d'; | ||
|
||
beforeEach(() => { | ||
applicationContext.getCurrentUser.mockReturnValue(petitionsClerkUser); | ||
}); | ||
|
||
it('throws an unauthorized error if user does not have correct permissions', async () => { | ||
applicationContext.getCurrentUser.mockReturnValue({ | ||
role: ROLES.petitioner, | ||
}); | ||
|
||
await expect( | ||
removeCounselFromRemovedPetitioner({ | ||
applicationContext, | ||
caseEntity: new Case(MOCK_CASE, { applicationContext }), | ||
petitionerContactId: mockContactPrimaryId, | ||
}), | ||
).rejects.toThrow('Unauthorized'); | ||
}); | ||
|
||
it('should remove the petitioner from privatePractitioner representing array but not remove them completely from the case if another petitioner is also represented', async () => { | ||
const caseEntity = new Case( | ||
{ | ||
...MOCK_CASE, | ||
partyType: PARTY_TYPES.petitionerSpouse, | ||
petitioners: [ | ||
MOCK_CASE.petitioners[0], | ||
{ | ||
...MOCK_CASE.petitioners[0], | ||
contactId: mockContactSecondaryId, | ||
contactType: CONTACT_TYPES.secondary, | ||
}, | ||
], | ||
privatePractitioners: [ | ||
{ | ||
...MOCK_PRACTITIONER, | ||
representing: [mockContactPrimaryId, mockContactSecondaryId], | ||
}, | ||
], | ||
}, | ||
{ applicationContext }, | ||
); | ||
|
||
const updatedCase = await removeCounselFromRemovedPetitioner({ | ||
applicationContext, | ||
caseEntity, | ||
petitionerContactId: mockContactSecondaryId, | ||
}); | ||
|
||
expect(updatedCase.privatePractitioners[0].representing).toEqual([ | ||
mockContactPrimaryId, | ||
]); | ||
expect( | ||
applicationContext.getPersistenceGateway().deleteUserFromCase, | ||
).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should remove the privatePractitioner from the case privatePractitioner if they are only representing the petitioner being removed', async () => { | ||
const caseEntity = new Case( | ||
{ | ||
...MOCK_CASE, | ||
partyType: PARTY_TYPES.petitionerSpouse, | ||
petitioners: [ | ||
MOCK_CASE.petitioners[0], | ||
{ | ||
...MOCK_CASE.petitioners[0], | ||
contactId: mockContactSecondaryId, | ||
contactType: CONTACT_TYPES.secondary, | ||
}, | ||
], | ||
privatePractitioners: [ | ||
{ | ||
...MOCK_PRACTITIONER, | ||
representing: [mockContactSecondaryId], | ||
userId: mockSecondPractitionerUserId, | ||
}, | ||
{ | ||
...MOCK_PRACTITIONER, | ||
representing: [mockContactPrimaryId], | ||
userId: mockThirdPractitionerUserId, | ||
}, | ||
], | ||
}, | ||
{ applicationContext }, | ||
); | ||
|
||
const updatedCase = await removeCounselFromRemovedPetitioner({ | ||
applicationContext, | ||
caseEntity, | ||
petitionerContactId: mockContactSecondaryId, | ||
}); | ||
|
||
expect( | ||
applicationContext.getPersistenceGateway().deleteUserFromCase.mock | ||
.calls[0][0].userId, | ||
).toEqual(mockSecondPractitionerUserId); | ||
expect(updatedCase.privatePractitioners.length).toEqual(1); | ||
expect(updatedCase.privatePractitioners[0].representing).toEqual([ | ||
mockContactPrimaryId, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.