Skip to content

Commit

Permalink
Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamS-Quartech committed Jul 8, 2024
1 parent 72f78e3 commit 389ae40
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
getRequestHandlerMocks,
produceAgency,
produceBuilding,
produceImportResult,
produceParcel,
producePropertyUnion,
produceSSO,
Expand All @@ -34,7 +35,11 @@ import { Roles } from '@/constants/roles';
import { AppDataSource } from '@/appDataSource';
import { User } from '@/typeorm/Entities/User';
import { Agency } from '@/typeorm/Entities/Agency';
import { getPropertyUnion, importProperties } from '@/controllers/properties/propertiesController';
import {
getImportResults,
getPropertyUnion,
importProperties,
} from '@/controllers/properties/propertiesController';

const {
getProperties,
Expand All @@ -61,12 +66,15 @@ const _getPropertiesForMap = jest.fn().mockImplementation(async () => [
},
]);

const _getPropertyUnion = jest.fn().mockImplementation(async () => [producePropertyUnion]);
const _getPropertyUnion = jest.fn().mockImplementation(async () => [producePropertyUnion()]);

const _getImportResults = jest.fn().mockImplementation(async () => [produceImportResult()]);

jest.mock('@/services/properties/propertiesServices', () => ({
propertiesFuzzySearch: () => _propertiesFuzzySearch(),
getPropertiesForMap: () => _getPropertiesForMap(),
getPropertiesUnion: () => _getPropertyUnion(),
getImportResults: () => _getImportResults(),
}));

const _getAgencies = jest.fn().mockImplementation(async () => [1, 2, 3]);
Expand Down Expand Up @@ -231,4 +239,19 @@ describe('UNIT - Properties', () => {
expect(mockResponse.statusValue).toBe(200);
});
});

describe('GET /properties/import/results', () => {
it('should return status 200', async () => {
mockRequest.query = { quantity: '1' };
mockRequest.user = produceSSO();
await getImportResults(mockRequest, mockResponse);
expect(mockResponse.statusValue).toBe(200);
});
it('should return status 400', async () => {
mockRequest.query = { quantity: [{}] };
mockRequest.user = produceSSO();
await getImportResults(mockRequest, mockResponse);
expect(mockResponse.statusValue).toBe(400);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Parcel } from '@/typeorm/Entities/Parcel';
import { ParcelEvaluation } from '@/typeorm/Entities/ParcelEvaluation';
import { ParcelFiscal } from '@/typeorm/Entities/ParcelFiscal';
import { PropertyClassification } from '@/typeorm/Entities/PropertyClassification';
import { User } from '@/typeorm/Entities/User';
import { MapProperties } from '@/typeorm/Entities/views/MapPropertiesView';
import { PropertyUnion } from '@/typeorm/Entities/views/PropertyUnionView';
import {
Expand All @@ -31,6 +32,7 @@ import {
produceParcelFiscal,
produceBuildingEvaluation,
produceBuildingFiscal,
produceSSO,
} from 'tests/testUtils/factories';
import { DeepPartial, EntityTarget, ObjectLiteral } from 'typeorm';
import xlsx, { WorkSheet } from 'xlsx';
Expand Down Expand Up @@ -129,6 +131,12 @@ jest.spyOn(userServices, 'getAgencies').mockImplementation(async () => [1]);
jest
.spyOn(AppDataSource.getRepository(ImportResult), 'save')
.mockImplementation(async () => produceImportResult());
jest
.spyOn(AppDataSource.getRepository(ImportResult), 'find')
.mockImplementation(async () => [produceImportResult()]);
jest
.spyOn(AppDataSource.getRepository(User), 'findOneBy')
.mockImplementation(async () => produceUser());

const _mockStartTransaction = jest.fn(async () => {});
const _mockRollbackTransaction = jest.fn(async () => {});
Expand Down Expand Up @@ -254,6 +262,19 @@ describe('UNIT - Property Services', () => {
});
});

describe('getImportResults', () => {
it('should return a list of import results', async () => {
const result = await propertyServices.getImportResults(
{
quantity: 1,
},
produceSSO(),
);
expect(Array.isArray(result)).toBe(true);
expect(result.at(0)).toHaveProperty('CompletionPercentage');
});
});

describe('importPropertiesAsJSON', () => {
it('should insert or update properties into database', async () => {
jest.spyOn(xlsx.utils, 'sheet_to_json').mockImplementationOnce(() => [
Expand Down

0 comments on commit 389ae40

Please sign in to comment.