From fa8f1d256e054ac74bab6354350a76fe6902381e Mon Sep 17 00:00:00 2001 From: driatic Date: Wed, 20 Nov 2024 10:44:25 +0100 Subject: [PATCH 1/5] fix: wip null priority --- .../lease-service/priority-list-service.ts | 24 ++- .../tests/priority-list-service.test.ts | 137 ++++++++++++++++++ 2 files changed, 159 insertions(+), 2 deletions(-) diff --git a/src/services/lease-service/priority-list-service.ts b/src/services/lease-service/priority-list-service.ts index c2930934..0c642e9f 100644 --- a/src/services/lease-service/priority-list-service.ts +++ b/src/services/lease-service/priority-list-service.ts @@ -72,10 +72,30 @@ const assignPriorityToApplicantBasedOnRentalRules = ( } } - //priority 1 + if ( + applicant.currentHousingContract?.residentialArea?.code != + listing.districtCode + ) { + return { + ...applicant, + priority: null, + } + } + + // if ( + // applicant.upcomingHousingContract?.residentialArea?.code != + // listing.districtCode + // ) { + // return { + // ...applicant, + // priority: null, + // } + // } - //Applicant has no active parking space contract and is tenant in same area as listing if (!applicant.parkingSpaceContracts?.length) { + //priority 1 + + //Applicant has no active parking space contract and is tenant in same area as listing if (applicant.currentHousingContract) { if ( applicant.currentHousingContract?.residentialArea?.code === diff --git a/src/services/lease-service/tests/priority-list-service.test.ts b/src/services/lease-service/tests/priority-list-service.test.ts index 3f829112..df742d5e 100644 --- a/src/services/lease-service/tests/priority-list-service.test.ts +++ b/src/services/lease-service/tests/priority-list-service.test.ts @@ -711,4 +711,141 @@ describe('sortApplicantsBasedOnRentalRules', () => { applicant2.contactCode ) }) + + it('should something', () => { + const listing = factory.listing.build({ + rentalObjectCode: '307-714-00-0042', + address: 'Högloftsvägen 1-6', + monthlyRent: 190.45, + districtCaption: 'Vallby', + districtCode: 'VAL', + objectTypeCaption: 'Parkeringsplats utan el', + objectTypeCode: 'PPLUEL', + rentalObjectTypeCaption: 'Standard hyresobjektstyp', + rentalObjectTypeCode: 'STD', + publishedFrom: new Date('2024-11-19T15:29:06.000Z'), + publishedTo: new Date('2024-11-25T23:59:59.000Z'), + vacantFrom: new Date('2023-06-01T00:00:00.000Z'), + status: 1, + waitingListType: 'Bilplats (intern)', + }) + + const detailedApplicant = factory.detailedApplicant + .params({ + applicationType: 'Replace', //todo: add as enum + + parkingSpaceContracts: [ + { + leaseId: '705-808-00-0007/07', + leaseNumber: '07', + rentalPropertyId: '705-808-00-0007', + type: 'P-Platskontrakt ', + leaseStartDate: new Date('2011-11-01T00:00:00.000Z'), + leaseEndDate: undefined, + status: 0, + tenantContactIds: [], + tenants: [], + noticeGivenBy: undefined, + noticeDate: undefined, + noticeTimeTenant: '3', + preferredMoveOutDate: undefined, + terminationDate: undefined, + contractDate: new Date('2011-10-21T00:00:00.000Z'), + lastDebitDate: undefined, + approvalDate: new Date('2011-10-21T00:00:00.000Z'), + residentialArea: { + code: 'MAL', + caption: 'Malmaberg', + }, + rentalProperty: undefined, + rentInfo: undefined, + address: undefined, + }, + { + leaseId: '705-808-00-0002/13', + leaseNumber: '13', + rentalPropertyId: '705-808-00-0002', + type: 'P-Platskontrakt ', + leaseStartDate: new Date('2023-03-01T00:00:00.000Z'), + leaseEndDate: undefined, + status: 0, + tenantContactIds: [], + tenants: [], + noticeGivenBy: undefined, + noticeDate: undefined, + noticeTimeTenant: '3', + preferredMoveOutDate: undefined, + terminationDate: undefined, + contractDate: new Date('2024-10-17T00:00:00.000Z'), + lastDebitDate: undefined, + approvalDate: undefined, + residentialArea: { + code: 'MAL', + caption: 'Malmaberg', + }, + rentalProperty: undefined, + rentInfo: undefined, + address: undefined, + }, + { + leaseId: '705-709-00-0002/05', + leaseNumber: '05', + rentalPropertyId: '705-709-00-0002', + type: 'P-Platskontrakt ', + leaseStartDate: new Date('2023-04-01T00:00:00.000Z'), + leaseEndDate: undefined, + status: 0, + tenantContactIds: [], + tenants: [], + noticeGivenBy: undefined, + noticeDate: undefined, + noticeTimeTenant: '3', + preferredMoveOutDate: undefined, + terminationDate: undefined, + contractDate: new Date('2024-10-17T00:00:00.000Z'), + lastDebitDate: undefined, + approvalDate: undefined, + residentialArea: { + code: 'MAL', + caption: 'Malmaberg', + }, + rentalProperty: undefined, + rentInfo: undefined, + address: undefined, + }, + ], + currentHousingContract: { + leaseId: '705-010-01-0201/05', + leaseNumber: '05', + rentalPropertyId: '705-010-01-0201', + type: 'Bostadskontrakt ', + leaseStartDate: new Date('2001-11-01T00:00:00.000Z'), + leaseEndDate: undefined, + status: 0, + tenantContactIds: [], + tenants: [], + noticeGivenBy: undefined, + noticeDate: undefined, + noticeTimeTenant: '3', + preferredMoveOutDate: undefined, + terminationDate: undefined, + contractDate: new Date('2001-11-01T00:00:00.000Z'), + lastDebitDate: undefined, + approvalDate: new Date('2001-11-01T00:00:00.000Z'), + residentialArea: { + code: 'MAL', + caption: 'Malmaberg', + }, + }, + listingId: listing.id, + queuePoints: 60, + }) + .build() + + const result = assignPriorityToApplicantBasedOnRentalRules( + listing, + detailedApplicant + ) + expect(result.priority).toBe(null) + }) }) From 5656d16f819adf6ee8581d7c4f6d97c11f0bdd61 Mon Sep 17 00:00:00 2001 From: driatic Date: Wed, 20 Nov 2024 12:33:47 +0100 Subject: [PATCH 2/5] fix: replicate local env --- .../lease-service/priority-list-service.ts | 51 +++- .../tests/priority-list-service.test.ts | 249 ++++++++++++++++++ 2 files changed, 291 insertions(+), 9 deletions(-) diff --git a/src/services/lease-service/priority-list-service.ts b/src/services/lease-service/priority-list-service.ts index 0c642e9f..9faec027 100644 --- a/src/services/lease-service/priority-list-service.ts +++ b/src/services/lease-service/priority-list-service.ts @@ -66,21 +66,25 @@ const assignPriorityToApplicantBasedOnRentalRules = ( ) { //special residential area rental rules apply to this listing //applicant is not allowed to rent this object, return priority:undefined + console.log( + applicant.name + + ' - special residential area rental rules apply to this listing. applicant is not allowed to rent this object, return priority:undefined' + ) return { ...applicant, priority: null, } } - if ( - applicant.currentHousingContract?.residentialArea?.code != - listing.districtCode - ) { - return { - ...applicant, - priority: null, - } - } + // if ( + // applicant.currentHousingContract?.residentialArea?.code != + // listing.districtCode + // ) { + // return { + // ...applicant, + // priority: null, + // } + // } // if ( // applicant.upcomingHousingContract?.residentialArea?.code != @@ -101,6 +105,11 @@ const assignPriorityToApplicantBasedOnRentalRules = ( applicant.currentHousingContract?.residentialArea?.code === listing.districtCode ) { + console.log( + applicant.name + + ' - Applicant has no active parking space contract and is tenant in same area as listing' + ) + return { ...applicant, priority: 1, @@ -114,6 +123,10 @@ const assignPriorityToApplicantBasedOnRentalRules = ( applicant.upcomingHousingContract?.residentialArea?.code === listing.districtCode ) { + console.log( + applicant.name + + ' - Applicant has no active parking space contract and has upcoming housing contract in same area as listing' + ) return { ...applicant, priority: 1, @@ -127,6 +140,10 @@ const assignPriorityToApplicantBasedOnRentalRules = ( applicant.parkingSpaceContracts?.length === 1 && applicant.applicationType === 'Replace' ) { + console.log( + applicant.name + + ' - Applicant has 1 active contract for parking space and wishes to replace current parking space' + ) return { ...applicant, priority: 1, @@ -140,6 +157,10 @@ const assignPriorityToApplicantBasedOnRentalRules = ( applicant.parkingSpaceContracts?.length === 1 && applicant.applicationType === 'Additional' ) { + console.log( + applicant.name + + ' - Applicant has 1 active parking space contract and wishes to rent an additional parking space' + ) return { ...applicant, priority: 2, @@ -152,6 +173,10 @@ const assignPriorityToApplicantBasedOnRentalRules = ( applicant.parkingSpaceContracts.length > 1 && applicant.applicationType === 'Replace' ) { + console.log( + applicant.name + + ' - Applicant has more than 1 active parking space contract and wishes to replace 1 parking space contract' + ) return { ...applicant, priority: 2, @@ -165,6 +190,10 @@ const assignPriorityToApplicantBasedOnRentalRules = ( applicant.parkingSpaceContracts && applicant.parkingSpaceContracts.length >= 2 ) { + console.log( + applicant.name + + ' - Applicant has 2 or more active parking space and wishes to rent an additional parking space' + ) return { ...applicant, priority: 3, @@ -172,6 +201,10 @@ const assignPriorityToApplicantBasedOnRentalRules = ( } //Applicant is not in any of the 3 priority groups and is not eligible to rent the parking space. Ie because they don't have a housing contract + console.log( + applicant.name + + " - Applicant is not in any of the 3 priority groups and is not eligible to rent the parking space. Ie because they don't have a housing contract" + ) return { ...applicant, priority: null, diff --git a/src/services/lease-service/tests/priority-list-service.test.ts b/src/services/lease-service/tests/priority-list-service.test.ts index df742d5e..3252d1df 100644 --- a/src/services/lease-service/tests/priority-list-service.test.ts +++ b/src/services/lease-service/tests/priority-list-service.test.ts @@ -848,4 +848,253 @@ describe('sortApplicantsBasedOnRentalRules', () => { ) expect(result.priority).toBe(null) }) + + it('should something 2', () => { + const listing = factory.listing.build({ + id: 1, + rentalObjectCode: '307-706-00-0015', + address: 'Loftbodsvägen 10-12', + monthlyRent: 317.42, + districtCaption: 'Vallby', + districtCode: 'VAL', + objectTypeCaption: 'Parkeringsplats med el', + objectTypeCode: 'PPLMEL', + rentalObjectTypeCaption: 'Standard hyresobjektstyp', + rentalObjectTypeCode: 'STD', + publishedFrom: new Date('2024-10-21T07:55:51.000Z'), + publishedTo: new Date('2024-10-19T22:59:59.000Z'), + vacantFrom: new Date('2022-04-30T22:00:00.000Z'), + status: 4, + waitingListType: 'Bilplats (intern)', + }) + + const detailedApplicant1 = factory.detailedApplicant + .params({ + id: 7071, + name: 'Johansson Fredrik', + nationalRegistrationNumber: '198811247058', + contactCode: 'P086786', + applicationDate: new Date('2024-11-07T14:44:30.920Z'), + applicationType: 'Additional', + status: 6, + listingId: 1, + queuePoints: 16, + address: { + street: 'Skillsta 2 lgh 1002', + number: '', + postalCode: '72592', + city: 'Västerås', + }, + currentHousingContract: { + leaseId: '307-035-02-0302/03', + leaseNumber: '03', + rentalPropertyId: '307-035-02-0302', + type: 'Bostadskontrakt ', + leaseStartDate: new Date('2021-03-01T00:00:00.000Z'), + leaseEndDate: undefined, + status: 0, + tenantContactIds: [], + tenants: [], + noticeGivenBy: undefined, + noticeDate: undefined, + noticeTimeTenant: '3', + preferredMoveOutDate: undefined, + terminationDate: undefined, + contractDate: new Date('2020-12-22T00:00:00.000Z'), + lastDebitDate: undefined, + approvalDate: new Date('2020-12-22T00:00:00.000Z'), + residentialArea: { + code: 'VAL', + caption: 'Vallby', + }, + }, + parkingSpaceContracts: [ + { + leaseId: '307-903-00-0003/05', + leaseNumber: '05', + rentalPropertyId: '307-903-00-0003', + type: 'Garagekontrakt ', + leaseStartDate: new Date('2021-11-01T00:00:00.000Z'), + leaseEndDate: undefined, + status: 0, + tenantContactIds: [], + tenants: [], + noticeGivenBy: undefined, + noticeDate: undefined, + noticeTimeTenant: '3', + preferredMoveOutDate: undefined, + terminationDate: undefined, + contractDate: new Date('2024-10-22T00:00:00.000Z'), + lastDebitDate: undefined, + approvalDate: undefined, + residentialArea: { + code: 'VAL', + caption: 'Vallby', + }, + rentInfo: undefined, + rentalProperty: undefined, + address: undefined, + }, + { + leaseId: '307-903-00-0006/17', + leaseNumber: '17', + rentalPropertyId: '307-903-00-0006', + type: 'Garagekontrakt ', + leaseStartDate: new Date('2021-02-01T00:00:00.000Z'), + leaseEndDate: undefined, + status: 0, + tenantContactIds: [], + tenants: [], + noticeGivenBy: undefined, + noticeDate: undefined, + noticeTimeTenant: '3', + preferredMoveOutDate: undefined, + terminationDate: undefined, + contractDate: new Date('2024-10-24T00:00:00.000Z'), + lastDebitDate: undefined, + approvalDate: undefined, + residentialArea: { + code: 'VAL', + caption: 'Vallby', + }, + rentInfo: undefined, + rentalProperty: undefined, + address: undefined, + }, + { + leaseId: '307-904-00-0005/10', + leaseNumber: '10', + rentalPropertyId: '307-904-00-0005', + type: 'Garagekontrakt ', + leaseStartDate: new Date('2021-08-01T00:00:00.000Z'), + leaseEndDate: undefined, + status: 0, + tenantContactIds: [], + tenants: [], + noticeGivenBy: undefined, + noticeDate: undefined, + noticeTimeTenant: '3', + preferredMoveOutDate: undefined, + terminationDate: undefined, + contractDate: new Date('2024-11-04T00:00:00.000Z'), + lastDebitDate: undefined, + approvalDate: undefined, + residentialArea: { + code: 'VAL', + caption: 'Vallby', + }, + rentInfo: undefined, + rentalProperty: undefined, + address: undefined, + }, + ], + }) + .build() + + const result1 = assignPriorityToApplicantBasedOnRentalRules( + listing, + detailedApplicant1 + ) + expect(result1.priority).toBe(3) + + const detailedApplicant2 = factory.detailedApplicant + .params({ + id: 7073, + name: 'Sökande Fiktiv', + nationalRegistrationNumber: '198912157982', + contactCode: 'P145241', + applicationDate: new Date('2024-11-07T14:44:50.566Z'), + applicationType: 'Additional', + status: 1, + listingId: 1, + queuePoints: 1962, + address: { + street: 'Fiktiggatan 1', + number: '', + postalCode: '72222', + city: 'VÄSTERÅS', + }, + currentHousingContract: { + leaseId: '306-001-01-0101/07', + leaseNumber: '07', + rentalPropertyId: '306-001-01-0101', + type: 'Bostadskontrakt ', + leaseStartDate: new Date('2024-01-01T00:00:00.000Z'), + leaseEndDate: undefined, + status: 0, + tenantContactIds: [], + tenants: [], + noticeGivenBy: undefined, + noticeDate: undefined, + noticeTimeTenant: '3', + preferredMoveOutDate: undefined, + terminationDate: undefined, + contractDate: new Date('2023-09-27T00:00:00.000Z'), + lastDebitDate: undefined, + approvalDate: new Date('2023-09-27T00:00:00.000Z'), + residentialArea: { + code: 'PET', + caption: 'Pettersberg', + }, + }, + parkingSpaceContracts: [], + }) + .build() + + const result2 = assignPriorityToApplicantBasedOnRentalRules( + listing, + detailedApplicant2 + ) + expect(result2.priority).toBe(null) + + const detailedApplicant3 = factory.detailedApplicant + .params({ + id: 7072, + name: 'Lindström Johan', + nationalRegistrationNumber: '199007164750', + contactCode: 'P068937', + applicationDate: new Date('2024-11-07T14:44:40.610Z'), + applicationType: 'Additional', + status: 1, + listingId: 1, + queuePoints: 9, + address: { + street: 'Norra Allégatan', + number: '', + postalCode: '72219', + city: 'Västerås', + }, + currentHousingContract: { + leaseId: '705-008-04-0101/04', + leaseNumber: '04', + rentalPropertyId: '705-008-04-0101', + type: 'Bostadskontrakt ', + leaseStartDate: new Date('2013-03-01T00:00:00.000Z'), + leaseEndDate: undefined, + status: 0, + tenantContactIds: [], + tenants: [], + noticeGivenBy: undefined, + noticeDate: undefined, + noticeTimeTenant: '3', + preferredMoveOutDate: undefined, + terminationDate: undefined, + contractDate: new Date('2013-01-23T00:00:00.000Z'), + lastDebitDate: undefined, + approvalDate: new Date('2013-01-23T00:00:00.000Z'), + residentialArea: { + code: 'MAL', + caption: 'Malmaberg', + }, + }, + parkingSpaceContracts: [], + }) + .build() + + const result3 = assignPriorityToApplicantBasedOnRentalRules( + listing, + detailedApplicant3 + ) + expect(result3.priority).toBe(null) + }) }) From b393856d2d84494226736da3a5890c929c168eff Mon Sep 17 00:00:00 2001 From: driatic Date: Mon, 25 Nov 2024 10:21:36 +0100 Subject: [PATCH 3/5] fix: update test --- .../lease-service/priority-list-service.ts | 20 -- .../tests/priority-list-service.test.ts | 336 +----------------- 2 files changed, 2 insertions(+), 354 deletions(-) diff --git a/src/services/lease-service/priority-list-service.ts b/src/services/lease-service/priority-list-service.ts index 9faec027..854b6ae0 100644 --- a/src/services/lease-service/priority-list-service.ts +++ b/src/services/lease-service/priority-list-service.ts @@ -76,26 +76,6 @@ const assignPriorityToApplicantBasedOnRentalRules = ( } } - // if ( - // applicant.currentHousingContract?.residentialArea?.code != - // listing.districtCode - // ) { - // return { - // ...applicant, - // priority: null, - // } - // } - - // if ( - // applicant.upcomingHousingContract?.residentialArea?.code != - // listing.districtCode - // ) { - // return { - // ...applicant, - // priority: null, - // } - // } - if (!applicant.parkingSpaceContracts?.length) { //priority 1 diff --git a/src/services/lease-service/tests/priority-list-service.test.ts b/src/services/lease-service/tests/priority-list-service.test.ts index 3252d1df..9bad4f34 100644 --- a/src/services/lease-service/tests/priority-list-service.test.ts +++ b/src/services/lease-service/tests/priority-list-service.test.ts @@ -712,144 +712,7 @@ describe('sortApplicantsBasedOnRentalRules', () => { ) }) - it('should something', () => { - const listing = factory.listing.build({ - rentalObjectCode: '307-714-00-0042', - address: 'Högloftsvägen 1-6', - monthlyRent: 190.45, - districtCaption: 'Vallby', - districtCode: 'VAL', - objectTypeCaption: 'Parkeringsplats utan el', - objectTypeCode: 'PPLUEL', - rentalObjectTypeCaption: 'Standard hyresobjektstyp', - rentalObjectTypeCode: 'STD', - publishedFrom: new Date('2024-11-19T15:29:06.000Z'), - publishedTo: new Date('2024-11-25T23:59:59.000Z'), - vacantFrom: new Date('2023-06-01T00:00:00.000Z'), - status: 1, - waitingListType: 'Bilplats (intern)', - }) - - const detailedApplicant = factory.detailedApplicant - .params({ - applicationType: 'Replace', //todo: add as enum - - parkingSpaceContracts: [ - { - leaseId: '705-808-00-0007/07', - leaseNumber: '07', - rentalPropertyId: '705-808-00-0007', - type: 'P-Platskontrakt ', - leaseStartDate: new Date('2011-11-01T00:00:00.000Z'), - leaseEndDate: undefined, - status: 0, - tenantContactIds: [], - tenants: [], - noticeGivenBy: undefined, - noticeDate: undefined, - noticeTimeTenant: '3', - preferredMoveOutDate: undefined, - terminationDate: undefined, - contractDate: new Date('2011-10-21T00:00:00.000Z'), - lastDebitDate: undefined, - approvalDate: new Date('2011-10-21T00:00:00.000Z'), - residentialArea: { - code: 'MAL', - caption: 'Malmaberg', - }, - rentalProperty: undefined, - rentInfo: undefined, - address: undefined, - }, - { - leaseId: '705-808-00-0002/13', - leaseNumber: '13', - rentalPropertyId: '705-808-00-0002', - type: 'P-Platskontrakt ', - leaseStartDate: new Date('2023-03-01T00:00:00.000Z'), - leaseEndDate: undefined, - status: 0, - tenantContactIds: [], - tenants: [], - noticeGivenBy: undefined, - noticeDate: undefined, - noticeTimeTenant: '3', - preferredMoveOutDate: undefined, - terminationDate: undefined, - contractDate: new Date('2024-10-17T00:00:00.000Z'), - lastDebitDate: undefined, - approvalDate: undefined, - residentialArea: { - code: 'MAL', - caption: 'Malmaberg', - }, - rentalProperty: undefined, - rentInfo: undefined, - address: undefined, - }, - { - leaseId: '705-709-00-0002/05', - leaseNumber: '05', - rentalPropertyId: '705-709-00-0002', - type: 'P-Platskontrakt ', - leaseStartDate: new Date('2023-04-01T00:00:00.000Z'), - leaseEndDate: undefined, - status: 0, - tenantContactIds: [], - tenants: [], - noticeGivenBy: undefined, - noticeDate: undefined, - noticeTimeTenant: '3', - preferredMoveOutDate: undefined, - terminationDate: undefined, - contractDate: new Date('2024-10-17T00:00:00.000Z'), - lastDebitDate: undefined, - approvalDate: undefined, - residentialArea: { - code: 'MAL', - caption: 'Malmaberg', - }, - rentalProperty: undefined, - rentInfo: undefined, - address: undefined, - }, - ], - currentHousingContract: { - leaseId: '705-010-01-0201/05', - leaseNumber: '05', - rentalPropertyId: '705-010-01-0201', - type: 'Bostadskontrakt ', - leaseStartDate: new Date('2001-11-01T00:00:00.000Z'), - leaseEndDate: undefined, - status: 0, - tenantContactIds: [], - tenants: [], - noticeGivenBy: undefined, - noticeDate: undefined, - noticeTimeTenant: '3', - preferredMoveOutDate: undefined, - terminationDate: undefined, - contractDate: new Date('2001-11-01T00:00:00.000Z'), - lastDebitDate: undefined, - approvalDate: new Date('2001-11-01T00:00:00.000Z'), - residentialArea: { - code: 'MAL', - caption: 'Malmaberg', - }, - }, - listingId: listing.id, - queuePoints: 60, - }) - .build() - - const result = assignPriorityToApplicantBasedOnRentalRules( - listing, - detailedApplicant - ) - expect(result.priority).toBe(null) - }) - - it('should something 2', () => { + it('should assign priority null if applicant has no upcoming housing contracts or active parking space contracts', () => { const listing = factory.listing.build({ id: 1, rentalObjectCode: '307-706-00-0015', @@ -868,217 +731,22 @@ describe('sortApplicantsBasedOnRentalRules', () => { waitingListType: 'Bilplats (intern)', }) - const detailedApplicant1 = factory.detailedApplicant - .params({ - id: 7071, - name: 'Johansson Fredrik', - nationalRegistrationNumber: '198811247058', - contactCode: 'P086786', - applicationDate: new Date('2024-11-07T14:44:30.920Z'), - applicationType: 'Additional', - status: 6, - listingId: 1, - queuePoints: 16, - address: { - street: 'Skillsta 2 lgh 1002', - number: '', - postalCode: '72592', - city: 'Västerås', - }, - currentHousingContract: { - leaseId: '307-035-02-0302/03', - leaseNumber: '03', - rentalPropertyId: '307-035-02-0302', - type: 'Bostadskontrakt ', - leaseStartDate: new Date('2021-03-01T00:00:00.000Z'), - leaseEndDate: undefined, - status: 0, - tenantContactIds: [], - tenants: [], - noticeGivenBy: undefined, - noticeDate: undefined, - noticeTimeTenant: '3', - preferredMoveOutDate: undefined, - terminationDate: undefined, - contractDate: new Date('2020-12-22T00:00:00.000Z'), - lastDebitDate: undefined, - approvalDate: new Date('2020-12-22T00:00:00.000Z'), - residentialArea: { - code: 'VAL', - caption: 'Vallby', - }, - }, - parkingSpaceContracts: [ - { - leaseId: '307-903-00-0003/05', - leaseNumber: '05', - rentalPropertyId: '307-903-00-0003', - type: 'Garagekontrakt ', - leaseStartDate: new Date('2021-11-01T00:00:00.000Z'), - leaseEndDate: undefined, - status: 0, - tenantContactIds: [], - tenants: [], - noticeGivenBy: undefined, - noticeDate: undefined, - noticeTimeTenant: '3', - preferredMoveOutDate: undefined, - terminationDate: undefined, - contractDate: new Date('2024-10-22T00:00:00.000Z'), - lastDebitDate: undefined, - approvalDate: undefined, - residentialArea: { - code: 'VAL', - caption: 'Vallby', - }, - rentInfo: undefined, - rentalProperty: undefined, - address: undefined, - }, - { - leaseId: '307-903-00-0006/17', - leaseNumber: '17', - rentalPropertyId: '307-903-00-0006', - type: 'Garagekontrakt ', - leaseStartDate: new Date('2021-02-01T00:00:00.000Z'), - leaseEndDate: undefined, - status: 0, - tenantContactIds: [], - tenants: [], - noticeGivenBy: undefined, - noticeDate: undefined, - noticeTimeTenant: '3', - preferredMoveOutDate: undefined, - terminationDate: undefined, - contractDate: new Date('2024-10-24T00:00:00.000Z'), - lastDebitDate: undefined, - approvalDate: undefined, - residentialArea: { - code: 'VAL', - caption: 'Vallby', - }, - rentInfo: undefined, - rentalProperty: undefined, - address: undefined, - }, - { - leaseId: '307-904-00-0005/10', - leaseNumber: '10', - rentalPropertyId: '307-904-00-0005', - type: 'Garagekontrakt ', - leaseStartDate: new Date('2021-08-01T00:00:00.000Z'), - leaseEndDate: undefined, - status: 0, - tenantContactIds: [], - tenants: [], - noticeGivenBy: undefined, - noticeDate: undefined, - noticeTimeTenant: '3', - preferredMoveOutDate: undefined, - terminationDate: undefined, - contractDate: new Date('2024-11-04T00:00:00.000Z'), - lastDebitDate: undefined, - approvalDate: undefined, - residentialArea: { - code: 'VAL', - caption: 'Vallby', - }, - rentInfo: undefined, - rentalProperty: undefined, - address: undefined, - }, - ], - }) - .build() - - const result1 = assignPriorityToApplicantBasedOnRentalRules( - listing, - detailedApplicant1 - ) - expect(result1.priority).toBe(3) - - const detailedApplicant2 = factory.detailedApplicant - .params({ - id: 7073, - name: 'Sökande Fiktiv', - nationalRegistrationNumber: '198912157982', - contactCode: 'P145241', - applicationDate: new Date('2024-11-07T14:44:50.566Z'), - applicationType: 'Additional', - status: 1, - listingId: 1, - queuePoints: 1962, - address: { - street: 'Fiktiggatan 1', - number: '', - postalCode: '72222', - city: 'VÄSTERÅS', - }, - currentHousingContract: { - leaseId: '306-001-01-0101/07', - leaseNumber: '07', - rentalPropertyId: '306-001-01-0101', - type: 'Bostadskontrakt ', - leaseStartDate: new Date('2024-01-01T00:00:00.000Z'), - leaseEndDate: undefined, - status: 0, - tenantContactIds: [], - tenants: [], - noticeGivenBy: undefined, - noticeDate: undefined, - noticeTimeTenant: '3', - preferredMoveOutDate: undefined, - terminationDate: undefined, - contractDate: new Date('2023-09-27T00:00:00.000Z'), - lastDebitDate: undefined, - approvalDate: new Date('2023-09-27T00:00:00.000Z'), - residentialArea: { - code: 'PET', - caption: 'Pettersberg', - }, - }, - parkingSpaceContracts: [], - }) - .build() - - const result2 = assignPriorityToApplicantBasedOnRentalRules( - listing, - detailedApplicant2 - ) - expect(result2.priority).toBe(null) - const detailedApplicant3 = factory.detailedApplicant .params({ - id: 7072, - name: 'Lindström Johan', - nationalRegistrationNumber: '199007164750', - contactCode: 'P068937', + id: 1, applicationDate: new Date('2024-11-07T14:44:40.610Z'), applicationType: 'Additional', status: 1, listingId: 1, queuePoints: 9, - address: { - street: 'Norra Allégatan', - number: '', - postalCode: '72219', - city: 'Västerås', - }, currentHousingContract: { leaseId: '705-008-04-0101/04', leaseNumber: '04', rentalPropertyId: '705-008-04-0101', type: 'Bostadskontrakt ', leaseStartDate: new Date('2013-03-01T00:00:00.000Z'), - leaseEndDate: undefined, status: 0, - tenantContactIds: [], - tenants: [], - noticeGivenBy: undefined, - noticeDate: undefined, noticeTimeTenant: '3', - preferredMoveOutDate: undefined, - terminationDate: undefined, contractDate: new Date('2013-01-23T00:00:00.000Z'), lastDebitDate: undefined, approvalDate: new Date('2013-01-23T00:00:00.000Z'), From 7a2658a8e463f3c915a0bb4f6bb18498d10917b3 Mon Sep 17 00:00:00 2001 From: driatic Date: Mon, 25 Nov 2024 17:11:07 +0100 Subject: [PATCH 4/5] fix: add logger.info --- .../lease-service/priority-list-service.ts | 39 ++++++++++--------- .../tests/priority-list-service.test.ts | 7 +--- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/services/lease-service/priority-list-service.ts b/src/services/lease-service/priority-list-service.ts index 854b6ae0..e0e79e2e 100644 --- a/src/services/lease-service/priority-list-service.ts +++ b/src/services/lease-service/priority-list-service.ts @@ -19,12 +19,15 @@ const addPriorityToApplicantsBasedOnRentalRules = ( applicants: DetailedApplicant[] ) => { const applicantsWithAssignedPriority: DetailedApplicant[] = [] + logger.info( + `Adding priority to applicants based on rental rules for listing ${listing.id}` + ) for (const applicant of applicants) { applicantsWithAssignedPriority.push( assignPriorityToApplicantBasedOnRentalRules(listing, applicant) ) } - + logger.info(`Priority assigned to applicants for ${listing.id}`) return applicantsWithAssignedPriority } @@ -65,10 +68,10 @@ const assignPriorityToApplicantBasedOnRentalRules = ( ) ) { //special residential area rental rules apply to this listing - //applicant is not allowed to rent this object, return priority:undefined - console.log( + //applicant is not allowed to rent this object, return priority:null + logger.info( applicant.name + - ' - special residential area rental rules apply to this listing. applicant is not allowed to rent this object, return priority:undefined' + ': priority null - special residential area rental rules apply to this listing. applicant is not allowed to rent this object' ) return { ...applicant, @@ -85,9 +88,9 @@ const assignPriorityToApplicantBasedOnRentalRules = ( applicant.currentHousingContract?.residentialArea?.code === listing.districtCode ) { - console.log( + logger.info( applicant.name + - ' - Applicant has no active parking space contract and is tenant in same area as listing' + ': priority 1 - Applicant has no active parking space contract and is tenant in same area as listing' ) return { @@ -103,9 +106,9 @@ const assignPriorityToApplicantBasedOnRentalRules = ( applicant.upcomingHousingContract?.residentialArea?.code === listing.districtCode ) { - console.log( + logger.info( applicant.name + - ' - Applicant has no active parking space contract and has upcoming housing contract in same area as listing' + ': priority 1 - Applicant has no active parking space contract and has upcoming housing contract in same area as listing' ) return { ...applicant, @@ -120,9 +123,9 @@ const assignPriorityToApplicantBasedOnRentalRules = ( applicant.parkingSpaceContracts?.length === 1 && applicant.applicationType === 'Replace' ) { - console.log( + logger.info( applicant.name + - ' - Applicant has 1 active contract for parking space and wishes to replace current parking space' + ': priority 1 - Applicant has 1 active contract for parking space and wishes to replace current parking space' ) return { ...applicant, @@ -137,9 +140,9 @@ const assignPriorityToApplicantBasedOnRentalRules = ( applicant.parkingSpaceContracts?.length === 1 && applicant.applicationType === 'Additional' ) { - console.log( + logger.info( applicant.name + - ' - Applicant has 1 active parking space contract and wishes to rent an additional parking space' + ': priority 2 - Applicant has 1 active parking space contract and wishes to rent an additional parking space' ) return { ...applicant, @@ -153,9 +156,9 @@ const assignPriorityToApplicantBasedOnRentalRules = ( applicant.parkingSpaceContracts.length > 1 && applicant.applicationType === 'Replace' ) { - console.log( + logger.info( applicant.name + - ' - Applicant has more than 1 active parking space contract and wishes to replace 1 parking space contract' + ': priority 2 - Applicant has more than 1 active parking space contract and wishes to replace 1 parking space contract' ) return { ...applicant, @@ -170,9 +173,9 @@ const assignPriorityToApplicantBasedOnRentalRules = ( applicant.parkingSpaceContracts && applicant.parkingSpaceContracts.length >= 2 ) { - console.log( + logger.info( applicant.name + - ' - Applicant has 2 or more active parking space and wishes to rent an additional parking space' + ': priority 3 - Applicant has 2 or more active parking space and wishes to rent an additional parking space' ) return { ...applicant, @@ -181,9 +184,9 @@ const assignPriorityToApplicantBasedOnRentalRules = ( } //Applicant is not in any of the 3 priority groups and is not eligible to rent the parking space. Ie because they don't have a housing contract - console.log( + logger.info( applicant.name + - " - Applicant is not in any of the 3 priority groups and is not eligible to rent the parking space. Ie because they don't have a housing contract" + ": priority null - Applicant is not in any of the 3 priority groups and is not eligible to rent the parking space. Ie because they don't have a housing contract" ) return { ...applicant, diff --git a/src/services/lease-service/tests/priority-list-service.test.ts b/src/services/lease-service/tests/priority-list-service.test.ts index 9bad4f34..ea41b511 100644 --- a/src/services/lease-service/tests/priority-list-service.test.ts +++ b/src/services/lease-service/tests/priority-list-service.test.ts @@ -714,7 +714,6 @@ describe('sortApplicantsBasedOnRentalRules', () => { it('should assign priority null if applicant has no upcoming housing contracts or active parking space contracts', () => { const listing = factory.listing.build({ - id: 1, rentalObjectCode: '307-706-00-0015', address: 'Loftbodsvägen 10-12', monthlyRent: 317.42, @@ -733,12 +732,11 @@ describe('sortApplicantsBasedOnRentalRules', () => { const detailedApplicant3 = factory.detailedApplicant .params({ - id: 1, applicationDate: new Date('2024-11-07T14:44:40.610Z'), applicationType: 'Additional', status: 1, - listingId: 1, - queuePoints: 9, + listingId: listing.id, + queuePoints: 100, currentHousingContract: { leaseId: '705-008-04-0101/04', leaseNumber: '04', @@ -748,7 +746,6 @@ describe('sortApplicantsBasedOnRentalRules', () => { status: 0, noticeTimeTenant: '3', contractDate: new Date('2013-01-23T00:00:00.000Z'), - lastDebitDate: undefined, approvalDate: new Date('2013-01-23T00:00:00.000Z'), residentialArea: { code: 'MAL', From b99d55fded5cf212250664968f05bce72355bc41 Mon Sep 17 00:00:00 2001 From: driatic Date: Wed, 27 Nov 2024 09:20:54 +0100 Subject: [PATCH 5/5] fix: remove redudants fields from test objects --- .../lease-service/tests/priority-list-service.test.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/services/lease-service/tests/priority-list-service.test.ts b/src/services/lease-service/tests/priority-list-service.test.ts index ea41b511..41594370 100644 --- a/src/services/lease-service/tests/priority-list-service.test.ts +++ b/src/services/lease-service/tests/priority-list-service.test.ts @@ -715,14 +715,11 @@ describe('sortApplicantsBasedOnRentalRules', () => { it('should assign priority null if applicant has no upcoming housing contracts or active parking space contracts', () => { const listing = factory.listing.build({ rentalObjectCode: '307-706-00-0015', - address: 'Loftbodsvägen 10-12', - monthlyRent: 317.42, districtCaption: 'Vallby', districtCode: 'VAL', objectTypeCaption: 'Parkeringsplats med el', objectTypeCode: 'PPLMEL', rentalObjectTypeCaption: 'Standard hyresobjektstyp', - rentalObjectTypeCode: 'STD', publishedFrom: new Date('2024-10-21T07:55:51.000Z'), publishedTo: new Date('2024-10-19T22:59:59.000Z'), vacantFrom: new Date('2022-04-30T22:00:00.000Z'), @@ -736,7 +733,6 @@ describe('sortApplicantsBasedOnRentalRules', () => { applicationType: 'Additional', status: 1, listingId: listing.id, - queuePoints: 100, currentHousingContract: { leaseId: '705-008-04-0101/04', leaseNumber: '04',