Skip to content

Commit 2d52c5f

Browse files
henrikhenrikperssonHenrik Persson
andauthored
MIM-413: Get leases by contact code instead of pnr when getting maintenance units (#261)
* Get leases by contact code instead of pnr when getting maintenance units * Remove call to getContactByContactCode --------- Co-authored-by: Henrik Persson <henrik.persson@iteam.com>
1 parent a6e7cdc commit 2d52c5f

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

src/services/property-management-service/index.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -683,18 +683,8 @@ export const routes = (router: KoaRouter) => {
683683
router.get('(.*)/maintenanceUnits/contactCode/:contactCode', async (ctx) => {
684684
const metadata = generateRouteMetadata(ctx)
685685
try {
686-
const contactResult = await leasingAdapter.getContactByContactCode(
687-
ctx.params.contactCode
688-
)
689-
if (!contactResult.ok) {
690-
ctx.status = 404
691-
ctx.body = { reason: 'Contact not found', ...metadata }
692-
logger.info('Contact not found')
693-
return
694-
}
695-
696-
const leases = await leasingAdapter.getLeasesForPnr(
697-
contactResult.data.nationalRegistrationNumber,
686+
const leases = await leasingAdapter.getLeasesForContactCode(
687+
ctx.params.contactCode,
698688
false,
699689
false
700690
)

src/services/property-management-service/tests/index.test.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,11 @@ describe('rental-property-service index', () => {
124124
...maintenanceUnitInfo,
125125
type: index % 2 === 0 ? 'Tvättstuga' : 'Miljöbod',
126126
}))
127-
const contactMock = factory.contact.build()
128127
const leaseMock = factory.lease.build()
129128

130129
it('should return all maintenance units', async () => {
131-
const getContactSpy = jest
132-
.spyOn(leasingAdapter, 'getContactByContactCode')
133-
.mockResolvedValue({ ok: true, data: contactMock })
134-
const getLeasesForPnrSpy = jest
135-
.spyOn(leasingAdapter, 'getLeasesForPnr')
130+
const getLeasesForContactCodeSpy = jest
131+
.spyOn(leasingAdapter, 'getLeasesForContactCode')
136132
.mockResolvedValue([leaseMock])
137133
const getMaintenanceUnitsForRentalPropertySpy = jest
138134
.spyOn(
@@ -147,14 +143,32 @@ describe('rental-property-service index', () => {
147143

148144
expect(res.status).toBe(200)
149145
expect(res.body.content).toEqual(maintenanceUnitInfoMock)
150-
expect(getContactSpy).toHaveBeenCalledWith('P965339')
151-
expect(getLeasesForPnrSpy).toHaveBeenCalledWith(
152-
'199404084924',
146+
expect(getLeasesForContactCodeSpy).toHaveBeenCalledWith(
147+
'P965339',
153148
false,
154149
false
155150
)
156151
expect(getMaintenanceUnitsForRentalPropertySpy).toHaveBeenCalledWith(
157-
'705-022-04-0201'
152+
leaseMock.rentalPropertyId
153+
)
154+
})
155+
156+
it('should return an empty list if there are no leases', async () => {
157+
const getLeasesForContactCodeSpy = jest
158+
.spyOn(leasingAdapter, 'getLeasesForContactCode')
159+
.mockResolvedValue([])
160+
161+
const res = await request(app.callback()).get(
162+
'/api/maintenanceUnits/contactCode/P965339'
163+
)
164+
165+
expect(res.status).toBe(200)
166+
expect(res.body.content).toEqual([])
167+
expect(res.body.reason).toBe('No maintenance units found')
168+
expect(getLeasesForContactCodeSpy).toHaveBeenCalledWith(
169+
'P965339',
170+
false,
171+
false
158172
)
159173
})
160174
})

0 commit comments

Comments
 (0)