@@ -573,6 +573,12 @@ describe('Testing listing service', () => {
573573 parksAndCommunityCenters : 'parks' ,
574574 schools : 'schools' ,
575575 publicTransportation : 'public transportation' ,
576+ busStops : 'bus stops' ,
577+ hospitals : 'hospitals' ,
578+ playgrounds : 'playgrounds' ,
579+ recreationalFacilities : 'recreational facilities' ,
580+ seniorCenters : 'senior centers' ,
581+ shoppingVenues : 'shopping venues' ,
576582 } ,
577583 marketingType : undefined ,
578584 } ;
@@ -3510,6 +3516,12 @@ describe('Testing listing service', () => {
35103516 parksAndCommunityCenters : 'parks' ,
35113517 schools : 'schools' ,
35123518 publicTransportation : 'public transportation' ,
3519+ busStops : 'bus stops' ,
3520+ hospitals : 'hospitals' ,
3521+ playgrounds : 'playgrounds' ,
3522+ recreationalFacilities : 'recreational facilities' ,
3523+ seniorCenters : 'senior centers' ,
3524+ shoppingVenues : 'shopping venues' ,
35133525 } ,
35143526 } ,
35153527 jurisdictions : {
@@ -4012,6 +4024,12 @@ describe('Testing listing service', () => {
40124024 parksAndCommunityCenters : 'parks' ,
40134025 schools : 'schools' ,
40144026 publicTransportation : 'public transportation' ,
4027+ busStops : 'bus stops' ,
4028+ hospitals : 'hospitals' ,
4029+ playgrounds : 'playgrounds' ,
4030+ recreationalFacilities : 'recreational facilities' ,
4031+ seniorCenters : 'senior centers' ,
4032+ shoppingVenues : 'shopping venues' ,
40154033 } ,
40164034 } ,
40174035 jurisdictions : {
@@ -4411,6 +4429,168 @@ describe('Testing listing service', () => {
44114429 } ,
44124430 } ) ;
44134431 } ) ;
4432+
4433+ it ( 'should do a complete listing update' , async ( ) => {
4434+ prisma . listings . findUnique = jest . fn ( ) . mockResolvedValue ( {
4435+ id : 'example id' ,
4436+ name : 'example name' ,
4437+ reservedCommunityTypes : {
4438+ id : randomUUID ( ) ,
4439+ } ,
4440+ } ) ;
4441+ prisma . listings . update = jest . fn ( ) . mockResolvedValue ( {
4442+ id : 'example id' ,
4443+ name : 'example name' ,
4444+ } ) ;
4445+ prisma . listingEvents . findMany = jest . fn ( ) . mockResolvedValue ( [ ] ) ;
4446+ prisma . listingEvents . update = jest . fn ( ) . mockResolvedValue ( {
4447+ id : 'example id' ,
4448+ name : 'example name' ,
4449+ } ) ;
4450+ prisma . assets . delete = jest . fn ( ) . mockResolvedValue ( {
4451+ id : 'example id' ,
4452+ name : 'example name' ,
4453+ } ) ;
4454+ const updateMock = jest
4455+ . fn ( )
4456+ . mockResolvedValue ( { id : 'example id' , name : 'example name' } ) ;
4457+
4458+ prisma . $transaction = jest
4459+ . fn ( )
4460+ . mockResolvedValue ( [
4461+ jest . fn ( ) ,
4462+ jest . fn ( ) ,
4463+ jest . fn ( ) ,
4464+ jest . fn ( ) ,
4465+ jest . fn ( ) ,
4466+ updateMock ,
4467+ ] ) ;
4468+
4469+ const val = constructFullListingData ( randomUUID ( ) ) ;
4470+ prisma . assets . create = jest . fn ( ) . mockResolvedValue ( { id : randomUUID ( ) } ) ;
4471+ prisma . address . create = jest . fn ( ) . mockResolvedValue ( { id : randomUUID ( ) } ) ;
4472+ val . reservedCommunityTypes = null ;
4473+
4474+ await service . update ( val as ListingUpdate , user ) ;
4475+
4476+ const nestedUtilitiesUpdate = {
4477+ water : false ,
4478+ gas : true ,
4479+ trash : false ,
4480+ sewer : true ,
4481+ electricity : false ,
4482+ cable : true ,
4483+ phone : false ,
4484+ internet : true ,
4485+ } ;
4486+ const nestedFeaturesUpdate = {
4487+ elevator : true ,
4488+ wheelchairRamp : false ,
4489+ serviceAnimalsAllowed : true ,
4490+ accessibleParking : false ,
4491+ parkingOnSite : true ,
4492+ inUnitWasherDryer : false ,
4493+ laundryInBuilding : true ,
4494+ barrierFreeEntrance : false ,
4495+ rollInShower : true ,
4496+ grabBars : false ,
4497+ heatingInUnit : true ,
4498+ acInUnit : false ,
4499+ hearing : true ,
4500+ visual : false ,
4501+ mobility : true ,
4502+ barrierFreeUnitEntrance : false ,
4503+ loweredLightSwitch : true ,
4504+ barrierFreeBathroom : false ,
4505+ wideDoorways : true ,
4506+ loweredCabinets : false ,
4507+ } ;
4508+ const nestedNeighborhoodAmenities = {
4509+ groceryStores : 'stores' ,
4510+ pharmacies : 'pharmacies' ,
4511+ healthCareResources : 'health care' ,
4512+ parksAndCommunityCenters : 'parks' ,
4513+ schools : 'schools' ,
4514+ publicTransportation : 'public transportation' ,
4515+ busStops : 'bus stops' ,
4516+ hospitals : 'hospitals' ,
4517+ playgrounds : 'playgrounds' ,
4518+ recreationalFacilities : 'recreational facilities' ,
4519+ seniorCenters : 'senior centers' ,
4520+ shoppingVenues : 'shopping venues' ,
4521+ } ;
4522+
4523+ const calculatedUnitsAvailable = service . calculateUnitsAvailable (
4524+ val . reviewOrderType ,
4525+ val . units ,
4526+ val . unitGroups ,
4527+ ) ;
4528+
4529+ // Capture mock call arguments instead of using expect.anything()
4530+ expect ( prisma . listings . update ) . toHaveBeenCalledTimes ( 1 ) ;
4531+ const updateCall = ( prisma . listings . update as jest . Mock ) . mock . calls [ 0 ] [ 0 ] ;
4532+
4533+ // Test key properties
4534+ expect ( updateCall . data . unitsAvailable ) . toBe ( calculatedUnitsAvailable ) ;
4535+ expect ( updateCall . data . publishedAt ) . toBeInstanceOf ( Date ) ;
4536+ expect ( updateCall . data . contentUpdatedAt ) . toBeInstanceOf ( Date ) ;
4537+ expect ( updateCall . data . assets ) . toEqual ( [ exampleAsset ] ) ;
4538+ expect ( updateCall . data . section8Acceptance ) . toBe ( true ) ;
4539+ expect ( updateCall . data . isVerified ) . toBe ( true ) ;
4540+
4541+ // Test nested structures
4542+ expect ( updateCall . data . applicationMethods . create ) . toHaveLength ( 1 ) ;
4543+ expect ( updateCall . data . applicationMethods . create [ 0 ] . type ) . toBe (
4544+ ApplicationMethodsTypeEnum . Internal ,
4545+ ) ;
4546+ expect ( updateCall . data . listingEvents . create ) . toHaveLength ( 1 ) ;
4547+ expect ( updateCall . data . listingEvents . create [ 0 ] . type ) . toBe (
4548+ ListingEventsTypeEnum . openHouse ,
4549+ ) ;
4550+ expect ( updateCall . data . units . create ) . toHaveLength ( 1 ) ;
4551+ expect ( updateCall . data . units . create [ 0 ] . amiPercentage ) . toBe ( '1' ) ;
4552+ expect ( updateCall . data . units . create [ 0 ] . bmrProgramChart ) . toBe ( true ) ;
4553+ expect ( updateCall . data . unitGroups . create ) . toEqual ( [ ] ) ;
4554+ expect ( updateCall . data . listingUtilities . upsert . create ) . toEqual (
4555+ nestedUtilitiesUpdate ,
4556+ ) ;
4557+ expect ( updateCall . data . listingUtilities . upsert . update ) . toEqual (
4558+ nestedUtilitiesUpdate ,
4559+ ) ;
4560+ expect ( updateCall . data . listingFeatures . upsert . create ) . toEqual (
4561+ nestedFeaturesUpdate ,
4562+ ) ;
4563+ expect ( updateCall . data . listingFeatures . upsert . update ) . toEqual (
4564+ nestedFeaturesUpdate ,
4565+ ) ;
4566+ expect (
4567+ updateCall . data . listingNeighborhoodAmenities . upsert . create ,
4568+ ) . toEqual ( nestedNeighborhoodAmenities ) ;
4569+ expect (
4570+ updateCall . data . listingNeighborhoodAmenities . upsert . update ,
4571+ ) . toEqual ( nestedNeighborhoodAmenities ) ;
4572+ expect ( updateCall . data . unitsSummary . create ) . toHaveLength ( 1 ) ;
4573+ expect ( updateCall . data . unitsSummary . create [ 0 ] . monthlyRentMin ) . toBe ( 1 ) ;
4574+ expect ( updateCall . data . unitsSummary . create [ 0 ] . totalCount ) . toBe ( 13 ) ;
4575+
4576+ // Test ID types instead of exact values
4577+ expect ( typeof updateCall . where . id ) . toBe ( 'string' ) ;
4578+ expect ( typeof updateCall . data . units . create [ 0 ] . unitTypes . connect . id ) . toBe (
4579+ 'string' ,
4580+ ) ;
4581+ expect (
4582+ typeof updateCall . data . unitsSummary . create [ 0 ] . unitTypes . connect . id ,
4583+ ) . toBe ( 'string' ) ;
4584+
4585+ expect ( canOrThrowMock ) . toHaveBeenCalledWith (
4586+ user ,
4587+ 'listing' ,
4588+ permissionActions . update ,
4589+ {
4590+ id : 'example id' ,
4591+ } ,
4592+ ) ;
4593+ } ) ;
44144594 } ) ;
44154595
44164596 describe ( 'Test delete endpoint' , ( ) => {
@@ -4718,6 +4898,12 @@ describe('Testing listing service', () => {
47184898 pharmacies : null ,
47194899 publicTransportation : null ,
47204900 schools : null ,
4901+ busStops : null ,
4902+ hospitals : null ,
4903+ playgrounds : null ,
4904+ recreationalFacilities : null ,
4905+ seniorCenters : null ,
4906+ shoppingVenues : null ,
47214907 } ,
47224908 update : {
47234909 groceryStores : null ,
@@ -4726,6 +4912,12 @@ describe('Testing listing service', () => {
47264912 pharmacies : null ,
47274913 publicTransportation : null ,
47284914 schools : null ,
4915+ busStops : null ,
4916+ hospitals : null ,
4917+ playgrounds : null ,
4918+ recreationalFacilities : null ,
4919+ seniorCenters : null ,
4920+ shoppingVenues : null ,
47294921 } ,
47304922 where : {
47314923 id : undefined ,
@@ -4868,6 +5060,12 @@ describe('Testing listing service', () => {
48685060 pharmacies : null ,
48695061 publicTransportation : null ,
48705062 schools : null ,
5063+ busStops : null ,
5064+ hospitals : null ,
5065+ playgrounds : null ,
5066+ recreationalFacilities : null ,
5067+ seniorCenters : null ,
5068+ shoppingVenues : null ,
48715069 } ,
48725070 update : {
48735071 groceryStores : null ,
@@ -4876,6 +5074,12 @@ describe('Testing listing service', () => {
48765074 pharmacies : null ,
48775075 publicTransportation : null ,
48785076 schools : null ,
5077+ busStops : null ,
5078+ hospitals : null ,
5079+ playgrounds : null ,
5080+ recreationalFacilities : null ,
5081+ seniorCenters : null ,
5082+ shoppingVenues : null ,
48795083 } ,
48805084 where : {
48815085 id : undefined ,
0 commit comments