Skip to content

Commit

Permalink
MIM-200: Add search by contactCode for /propertyinfo/:number endpoint (
Browse files Browse the repository at this point in the history
…#199)

* Add search by contactCode for /propertyinfo/:number endpoint

* Add test for contactCode case

---------

Co-authored-by: Henrik Persson <[email protected]>
  • Loading branch information
henrikhenrikpersson and Henrik Persson authored Nov 5, 2024
1 parent 43fc852 commit e37f94e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/services/ticketing-service/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import KoaRouter from '@koa/router'
import {
getContact,
getContactByContactCode,
getContactByPhoneNumber,
getLease,
getLeasesForPnr,
Expand Down Expand Up @@ -166,6 +167,25 @@ export const routes = (router: KoaRouter) => {
}
break
}
case 'contactCode': {
const contactResult = await getContactByContactCode(ctx.params.number)
if (contactResult.ok) {
const leases = await getLeasesForPnr(
contactResult.data.nationalRegistrationNumber,
undefined,
'true'
)

if (leases) {
for (const lease of leases) {
const propertyInfoWithLease =
await getRentalPropertyInfoWithLeases(lease)
responseData.push(propertyInfoWithLease)
}
}
}
break
}

default:
break
Expand Down
23 changes: 23 additions & 0 deletions src/services/ticketing-service/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,29 @@ describe('ticketing-service index', () => {
expect(getRentalPropertyInfoSpy).toHaveBeenCalledWith('705-022-04-0201')
expect(res.body.content).toBeDefined()
})

it('should handle contactCode case', async () => {
const getContactByContactCodeSpy = jest
.spyOn(tenantLeaseAdapter, 'getContactByContactCode')
.mockResolvedValue({ ok: true, data: contactMock })
const getLeaseSpy = jest
.spyOn(tenantLeaseAdapter, 'getLease')
.mockResolvedValue(leaseMock)

const getRentalPropertyInfoSpy = jest
.spyOn(propertyManagementAdapter, 'getRentalPropertyInfo')
.mockResolvedValue(rentalPropertyInfoMock)

const res = await request(app.callback()).get(
'/propertyInfo/P965339?typeOfNumber=contactCode'
)

expect(res.status).toBe(200)
expect(getContactByContactCodeSpy).toHaveBeenCalledWith('P965339')
expect(getLeaseSpy).toHaveBeenCalledWith('123', 'true')
expect(getRentalPropertyInfoSpy).toHaveBeenCalledWith('705-022-04-0201')
expect(res.body.content).toBeDefined()
})
})

describe('GET /ticketsByContactCode/:code', () => {
Expand Down

0 comments on commit e37f94e

Please sign in to comment.