Skip to content

Commit f69915a

Browse files
authoredFeb 28, 2025··
fix(condo): DOMA-10800 fix resident to property connections when there are more than 100 residents at the address (#5857)
* fix(condo): DOMA-10800 fix manageResidentToPropertyAndOrganizationConnections when there are more than 100 residents at the address * fix(condo): DOMA-10800 skip test with 101 resident
1 parent 3fc3988 commit f69915a

File tree

3 files changed

+55
-15
lines changed

3 files changed

+55
-15
lines changed
 

‎apps/condo/domains/resident/schema/RegisterResidentService.test.js

+50-10
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ const {
1010
expectToThrowAuthenticationErrorToResult, expectToThrowAccessDeniedErrorToResult,
1111
} = require('@open-condo/keystone/test.utils')
1212

13-
const { CONTEXT_FINISHED_STATUS } = require('@condo/domains/acquiring/constants/context')
14-
const {
15-
createTestAcquiringIntegration,
16-
createTestAcquiringIntegrationContext,
17-
} = require('@condo/domains/acquiring/utils/testSchema')
18-
const {
19-
createTestBillingAccount,
20-
makeContextWithOrganizationAndIntegrationAsAdmin,
21-
createTestBillingProperty,
22-
} = require('@condo/domains/billing/utils/testSchema')
2313
const { MANAGING_COMPANY_TYPE, SERVICE_PROVIDER_TYPE } = require('@condo/domains/organization/constants/common')
2414
const {
2515
registerNewOrganization,
@@ -219,6 +209,56 @@ describe('manageResidentToPropertyAndOrganizationConnections worker task tests',
219209
expect(anotherResident.property.id).toEqual(olderProperty.id)
220210
})
221211
})
212+
213+
// Skip this test because it takes a long time
214+
test.skip('Must relink many residents after approve new properties', async () => {
215+
// Create admin for making Resident.getAll requests to fetch all residents in a single query
216+
// instead of making 101 separate requests from resident clients.
217+
const admin = await makeLoggedInAdminClient()
218+
const support = await makeClientWithSupportUser()
219+
const staffUserClient = await makeClientWithNewRegisteredAndLoggedInUser()
220+
221+
const [organization] = await registerNewOrganization(staffUserClient)
222+
const [organization1] = await registerNewOrganization(staffUserClient)
223+
224+
const [olderProperty] = await createTestProperty(staffUserClient, organization, propertyPayload)
225+
const [newerProperty] = await createTestProperty(staffUserClient, organization1, propertyPayload)
226+
227+
const residentsInProperty = 101
228+
229+
const residentIds = await Promise.all(
230+
Array.from({ length: residentsInProperty }).map(async () => {
231+
const residentUserClient = await makeClientWithResidentUser()
232+
const [resident] = await registerResidentByTestClient(residentUserClient, { address: residentAddress, addressMeta: residentAddressMeta })
233+
234+
return resident.id
235+
})
236+
)
237+
238+
// NOTE: Should connect to older property
239+
await waitFor(async () => {
240+
const residents = await Resident.getAll(admin, { id_in: residentIds }, { first: residentsInProperty })
241+
242+
for (const resident of residents) {
243+
expect(resident.organization?.id).toEqual(organization.id)
244+
expect(resident.property?.id).toEqual(olderProperty.id)
245+
}
246+
})
247+
248+
// The newer property company requests support for ownership approval by providing a document of management rights
249+
const [approvedProperty] = await updateTestProperty(support, newerProperty.id, { isApproved: true })
250+
expect(approvedProperty).toHaveProperty('isApproved', true)
251+
252+
// // NOTE: After that all residents reconnect to newer property, since it's approved now
253+
await waitFor(async () => {
254+
const residents = await Resident.getAll(admin, { id_in: residentIds }, { first: residentsInProperty })
255+
256+
for (const resident of residents) {
257+
expect(resident.organization?.id).toEqual(organization1.id)
258+
expect(resident.property?.id).toEqual(newerProperty.id)
259+
}
260+
}, { timeout: 1000 * 60 })
261+
})
222262
})
223263

224264
describe('RegisterResidentService', () => {

‎apps/condo/domains/resident/tasks/residentTicket.task.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@ async function manageResidentToPropertyAndOrganizationConnections (address, dv,
3131
})
3232

3333
if (oldestProperty) {
34-
const residents = await ResidentAPI.getAll(context, {
34+
const residents = await find('Resident', {
3535
address_i: address,
3636
deletedAt: null,
3737
property: { OR: [{ id_not: oldestProperty.id }, { id: null }] },
38-
}, 'id property { id }')
38+
})
3939

4040
// Disconnect residents before reconnecting
4141
await disconnectResidents(context, residents, dv, sender)
4242
// We have residents, not connected to oldest non-deleted property
4343
// They should be reconnected to oldestProperty
4444
await connectResidents(context, residents, oldestProperty, dv, sender)
4545
} else {
46-
const residents = await ResidentAPI.getAll(context, {
46+
const residents = await find('Resident', {
4747
address_i: address,
4848
deletedAt: null,
49-
}, 'id property { id }')
49+
})
5050

5151
// We have no non-deleted properties with such address
5252
// All residents with such address should be disconnected

‎apps/condo/domains/resident/utils/helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const connectResidents = async (context, residents, property, dv, sender) => {
2727
// Already disconnected resident
2828
if (!shouldConnect && isNull(resident.property)) continue
2929
// Resident is already connected to the property
30-
if (shouldConnect && get(resident, 'property.id') === propertyId) continue
30+
if (shouldConnect && get(resident, 'property') === propertyId) continue
3131

3232
await ResidentAPI.update(context, get(resident, 'id'), attrs)
3333
}

0 commit comments

Comments
 (0)
Please sign in to comment.