Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarkowsky committed Jan 9, 2025
1 parent 351beff commit c8a28dd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ const _getPropertiesForMap = jest.fn().mockImplementation(async () => [
},
]);

const _getPropertiesForExport = jest
.fn()
.mockImplementation(async () => [produceBuilding(), produceParcel()]);

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

const _getImportResults = jest.fn().mockImplementation(async () => [produceImportResult()]);
Expand All @@ -88,6 +92,7 @@ jest.mock('@/services/properties/propertiesServices', () => ({
getPropertiesUnion: () => _getPropertyUnion(),
getImportResults: () => _getImportResults(),
findLinkedProjectsForProperty: () => _findLinkedProjectsForProperty(),
getPropertiesForExport: () => _getPropertiesForExport(),
}));

const _getAgencies = jest.fn().mockImplementation(async () => [1, 2, 3]);
Expand Down Expand Up @@ -181,10 +186,32 @@ describe('UNIT - Properties', () => {
jest
.spyOn(AppDataSource.getRepository(Agency), 'find')
.mockImplementation(async () => [produceAgency()]);
mockRequest.setPimsUser({ RoleId: Roles.GENERAL_USER });
await getPropertiesForMap(mockRequest, mockResponse);
expect(mockResponse.statusValue).toBe(200);
expect(mockResponse.sendValue.length).toBeGreaterThanOrEqual(1);
});
});

describe('GET /properties/search/geo/export', () => {
const _checkUserAgencyPermission = jest.fn().mockImplementation(async () => true);
jest.mock('@/utilities/authorizationChecks', () => ({
checkUserAgencyPermission: _checkUserAgencyPermission,
}));
beforeEach(() => {
jest.clearAllMocks();
});

it('should return 200 with a list of properties in export form', async () => {
mockRequest.setUser({ client_roles: [Roles.ADMIN] });
mockRequest.setPimsUser({ RoleId: Roles.ADMIN });
mockRequest.query = {
ExcelExport: 'true',
};
await getPropertiesForMap(mockRequest, mockResponse);
expect(mockResponse.statusValue).toBe(200);
expect(mockResponse.sendValue.length).toBeGreaterThanOrEqual(1);
expect(_checkUserAgencyPermission).toHaveBeenCalledTimes(0);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jest

const _agenciesFind = jest
.spyOn(AppDataSource.getRepository(Agency), 'find')
.mockImplementation(async () => [produceAgency()]);
.mockImplementation(async () => [produceAgency({ Id: 100 })]);

describe('UNIT - User services', () => {
beforeEach(() => {
Expand Down

0 comments on commit c8a28dd

Please sign in to comment.