diff --git a/express-api/tests/testUtils/factories.ts b/express-api/tests/testUtils/factories.ts index 62222a228..78c2b6278 100644 --- a/express-api/tests/testUtils/factories.ts +++ b/express-api/tests/testUtils/factories.ts @@ -50,6 +50,7 @@ import { ProjectRisk } from '@/typeorm/Entities/ProjectRisk'; import { PropertyType } from '@/typeorm/Entities/PropertyType'; import { ProjectType } from '@/typeorm/Entities/ProjectType'; import { ProjectStatus } from '@/typeorm/Entities/ProjectStatus'; +import { PropertyUnion } from '@/typeorm/Entities/views/PropertyUnionView'; export class MockRes { statusValue: any; @@ -958,6 +959,27 @@ export const produceAgencyResponse = (props?: Partial) => return response; }; +export const producePropertyUnion = (props: Partial) => { + const union: PropertyUnion = { + Id: faker.number.int(), + PID: faker.number.int({ max: 999999999 }), + PIN: faker.number.int({ max: 999999999 }), + PropertyType: ['Building', 'Parcel'][faker.number.int({ min: 0, max: 1 })], + AgencyId: faker.number.int(), + Agency: faker.company.name(), + Address: faker.location.streetAddress(), + IsSensitive: false, + UpdatedOn: new Date(), + ClassificationId: faker.number.int(), + Classification: faker.company.buzzNoun(), + AdministrativeAreaId: faker.number.int(), + AdministrativeArea: faker.location.city(), + LandArea: faker.number.float({ max: 99999 }), + ...props, + }; + return union; +}; + export const produceLtsaOrder = (): ILtsaOrder => ({ order: { productType: 'title', diff --git a/express-api/tests/unit/controllers/properties/propertiesController.test.ts b/express-api/tests/unit/controllers/properties/propertiesController.test.ts index d770ff5be..219713602 100644 --- a/express-api/tests/unit/controllers/properties/propertiesController.test.ts +++ b/express-api/tests/unit/controllers/properties/propertiesController.test.ts @@ -7,12 +7,14 @@ import { produceAgency, produceBuilding, produceParcel, + producePropertyUnion, produceUser, } from '../../../testUtils/factories'; import { Roles } from '@/constants/roles'; import { AppDataSource } from '@/appDataSource'; import { User } from '@/typeorm/Entities/User'; import { Agency } from '@/typeorm/Entities/Agency'; +import { getPropertyUnion } from '@/controllers/properties/propertiesController'; const { getProperties, @@ -39,9 +41,12 @@ const _getPropertiesForMap = jest.fn().mockImplementation(async () => [ }, ]); +const _getPropertyUnion = jest.fn().mockImplementation(async () => [producePropertyUnion]); + jest.mock('@/services/properties/propertiesServices', () => ({ propertiesFuzzySearch: () => _propertiesFuzzySearch(), getPropertiesForMap: () => _getPropertiesForMap(), + getPropertiesUnion: () => _getPropertyUnion(), })); describe('UNIT - Properties', () => { @@ -181,4 +186,12 @@ describe('UNIT - Properties', () => { expect(mockResponse.jsonValue.length).toBeGreaterThanOrEqual(1); }); }); + + describe('GET /properties/', () => { + it('should return status 200', async () => { + await getPropertyUnion(mockRequest, mockResponse); + expect(mockResponse.statusValue).toBe(200); + expect(Array.isArray(mockResponse.sendValue)).toBe(true); + }); + }); }); diff --git a/express-api/tests/unit/services/properties/propertyServices.test.ts b/express-api/tests/unit/services/properties/propertyServices.test.ts index 51ec7f042..ef89c0577 100644 --- a/express-api/tests/unit/services/properties/propertyServices.test.ts +++ b/express-api/tests/unit/services/properties/propertyServices.test.ts @@ -3,7 +3,8 @@ import propertyServices from '@/services/properties/propertiesServices'; import { Building } from '@/typeorm/Entities/Building'; import { Parcel } from '@/typeorm/Entities/Parcel'; import { MapProperties } from '@/typeorm/Entities/views/MapPropertiesView'; -import { produceParcel, produceBuilding } from 'tests/testUtils/factories'; +import { PropertyUnion } from '@/typeorm/Entities/views/PropertyUnionView'; +import { produceParcel, produceBuilding, producePropertyUnion } from 'tests/testUtils/factories'; // eslint-disable-next-line @typescript-eslint/no-explicit-any const _parcelsCreateQueryBuilder: any = { @@ -45,6 +46,10 @@ jest.spyOn(AppDataSource.getRepository(MapProperties), 'find').mockImplementatio } as MapProperties, ]); +jest + .spyOn(AppDataSource.getRepository(PropertyUnion), 'find') + .mockImplementation(async () => [producePropertyUnion({})]); + describe('UNIT - Property Services', () => { beforeEach(() => { jest.clearAllMocks(); @@ -58,6 +63,30 @@ describe('UNIT - Property Services', () => { }); }); + describe('getPropertyUnion', () => { + it('should return a list of buildings and parcels', async () => { + const result = await propertyServices.getPropertiesUnion({ + pid: 'contains,123', + pin: 'contains,456', + administrativeArea: 'contains,aaa', + agency: 'startsWith,aaa', + propertyType: 'contains,Building', + sortKey: 'Agency', + sortOrder: 'DESC', + landArea: 'startsWith,1', + updatedOn: 'after,' + new Date(), + }); + expect(Array.isArray(result)); + expect(result.at(0)).toHaveProperty('PropertyType'); + expect(result.at(0)).toHaveProperty('Id'); + expect(result.at(0)).toHaveProperty('PIN'); + expect(result.at(0)).toHaveProperty('PID'); + expect(result.at(0)).toHaveProperty('Agency'); + expect(result.at(0)).toHaveProperty('Classification'); + expect(result.at(0)).toHaveProperty('AdministrativeArea'); + }); + }); + describe('getPropertiesForMap', () => { it('should return a list of map property objects', async () => { const result = await propertyServices.getPropertiesForMap({