@@ -10,16 +10,6 @@ const {
10
10
expectToThrowAuthenticationErrorToResult, expectToThrowAccessDeniedErrorToResult,
11
11
} = require ( '@open-condo/keystone/test.utils' )
12
12
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' )
23
13
const { MANAGING_COMPANY_TYPE , SERVICE_PROVIDER_TYPE } = require ( '@condo/domains/organization/constants/common' )
24
14
const {
25
15
registerNewOrganization,
@@ -219,6 +209,56 @@ describe('manageResidentToPropertyAndOrganizationConnections worker task tests',
219
209
expect ( anotherResident . property . id ) . toEqual ( olderProperty . id )
220
210
} )
221
211
} )
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
+ } )
222
262
} )
223
263
224
264
describe ( 'RegisterResidentService' , ( ) => {
0 commit comments