diff --git a/src/main/controllers/SummaryOfPublicationsController.ts b/src/main/controllers/SummaryOfPublicationsController.ts index 6f8b0c10e..b639ad7b2 100644 --- a/src/main/controllers/SummaryOfPublicationsController.ts +++ b/src/main/controllers/SummaryOfPublicationsController.ts @@ -2,17 +2,16 @@ import { PipRequest } from '../models/request/PipRequest'; import { Response } from 'express'; import { cloneDeep } from 'lodash'; import { LocationService } from '../service/LocationService'; -import { SummaryOfPublicationsService } from '../service/SummaryOfPublicationsService'; import { PublicationService } from '../service/PublicationService'; -const summaryOfPublicationsService = new SummaryOfPublicationsService(); const locationService = new LocationService(); const publicationService = new PublicationService(); export default class SummaryOfPublicationsController { public async get(req: PipRequest, res: Response): Promise { const locationId = req.query['locationId'] as string; - if (locationId) { + + if (locationId && !isNaN(parseInt(locationId))) { const court = await locationService.getLocationById(parseInt(locationId)); const locationName = locationService.findCourtName(court, req.lng, 'summary-of-publications'); const locationMetadata = await locationService.getLocationMetadata(parseInt(locationId)); @@ -26,10 +25,7 @@ export default class SummaryOfPublicationsController { req.lng === 'cy' ? locationMetadata.welshCautionMessage : locationMetadata.cautionMessage; } - const publications = await summaryOfPublicationsService.getPublications( - parseInt(locationId.toString()), - req.user?.['userId'] - ); + const publications = await publicationService.getPublicationsByLocation(locationId, req.user?.['userId']); const publicationsWithName = []; publications.forEach(publication => { diff --git a/src/main/controllers/admin/RemoveListSearchResultsController.ts b/src/main/controllers/admin/RemoveListSearchResultsController.ts index 1eda1d1b9..00987cf34 100644 --- a/src/main/controllers/admin/RemoveListSearchResultsController.ts +++ b/src/main/controllers/admin/RemoveListSearchResultsController.ts @@ -2,25 +2,25 @@ import { PipRequest } from '../../models/request/PipRequest'; import { Response } from 'express'; import { cloneDeep } from 'lodash'; import { LocationService } from '../../service/LocationService'; -import { SummaryOfPublicationsService } from '../../service/SummaryOfPublicationsService'; import { ManualUploadService } from '../../service/ManualUploadService'; import * as url from 'url'; import { checkIfUrl } from '../../helpers/urlHelper'; +import { PublicationService } from '../../service/PublicationService'; const courtService = new LocationService(); -const summaryOfPublicationsService = new SummaryOfPublicationsService(); +const publicationsService = new PublicationService(); const manualUploadService = new ManualUploadService(); export default class RemoveListSearchResultsController { public async get(req: PipRequest, res: Response): Promise { - const locationId = parseInt(req.query?.locationId as string); + const locationId = req.query?.locationId as string; const noOptionSelectedError = req.query?.error; - locationId + locationId && !isNaN(parseInt(locationId)) ? res.render('admin/remove-list-search-results', { ...cloneDeep(req.i18n.getDataByLanguage(req.lng)['remove-list-search-results']), - court: await courtService.getLocationById(locationId), + court: await courtService.getLocationById(parseInt(locationId)), removalList: manualUploadService.formatListRemovalValues( - await summaryOfPublicationsService.getPublications(locationId, req.user?.['userId'], true) + await publicationsService.getPublicationsByLocation(locationId, req.user?.['userId'], true) ), noOptionSelectedError: noOptionSelectedError, }) diff --git a/src/main/controllers/system-admin/BlobViewPublicationsController.ts b/src/main/controllers/system-admin/BlobViewPublicationsController.ts index 6c576d05a..46c18ac0e 100644 --- a/src/main/controllers/system-admin/BlobViewPublicationsController.ts +++ b/src/main/controllers/system-admin/BlobViewPublicationsController.ts @@ -2,9 +2,9 @@ import { PipRequest } from '../../models/request/PipRequest'; import { Response } from 'express'; import { cloneDeep } from 'lodash'; import { LocationService } from '../../service/LocationService'; -import { SummaryOfPublicationsService } from '../../service/SummaryOfPublicationsService'; +import { PublicationService } from '../../service/PublicationService'; -const summaryOfPublicationsService = new SummaryOfPublicationsService(); +const publicationService = new PublicationService(); const locationService = new LocationService(); export default class BlobViewPublicationsController { public async get(req: PipRequest, res: Response): Promise { @@ -16,25 +16,29 @@ export default class BlobViewPublicationsController { // reusing summary-of-pubs language file and service as this is essentially the same kind of page. // If the location being asked for is noMatch we do not need to request data from the API as it is not a real location - const noMatchArtefact = locationId.toString() === 'noMatch'; - if (!noMatchArtefact) { - court = await locationService.getLocationById(parseInt(locationId.toString())); - locationName = locationService.findCourtName(court, req.lng, 'summary-of-publications'); - listOfPublications = await summaryOfPublicationsService.getPublications( - parseInt(locationId.toString()), - req.user['userId'] - ); - } else { + const noMatchArtefact = locationId === 'noMatch'; + if (locationId === 'noMatch') { locationName = 'No match artefacts'; - listOfPublications = await summaryOfPublicationsService.getNoMatchPublications(req.user['userId']); + listOfPublications = await publicationService.getNoMatchPublications(req.user['userId']); + res.render('system-admin/blob-view-publications', { + ...cloneDeep(req.i18n.getDataByLanguage(req.lng)['blob-view-publications']), + listOfPublications: listOfPublications, + locationName, + noMatchArtefact, + }); + } else if (isNaN(parseInt(locationId))) { + res.render('error', req.i18n.getDataByLanguage(req.lng).error); + } else { + court = await locationService.getLocationById(parseInt(locationId)); + locationName = locationService.findCourtName(court, req.lng, 'summary-of-publications'); + listOfPublications = await publicationService.getPublicationsByLocation(locationId, req.user['userId']); + res.render('system-admin/blob-view-publications', { + ...cloneDeep(req.i18n.getDataByLanguage(req.lng)['blob-view-publications']), + listOfPublications: listOfPublications, + locationName, + noMatchArtefact, + }); } - - res.render('system-admin/blob-view-publications', { - ...cloneDeep(req.i18n.getDataByLanguage(req.lng)['blob-view-publications']), - listOfPublications: listOfPublications, - locationName, - noMatchArtefact, - }); } else { res.render('error', req.i18n.getDataByLanguage(req.lng).error); } diff --git a/src/main/resources/requests/PublicationRequests.ts b/src/main/resources/requests/PublicationRequests.ts index 145b3daab..a113b465b 100644 --- a/src/main/resources/requests/PublicationRequests.ts +++ b/src/main/resources/requests/PublicationRequests.ts @@ -90,7 +90,7 @@ export class PublicationRequests { } } - public async getPublicationsByCourt(locationId: string, userId: string, admin: boolean): Promise { + public async getPublicationsByLocation(locationId: string, userId: string, admin: boolean): Promise { try { let header; if (userId) { diff --git a/src/main/service/PublicationService.ts b/src/main/service/PublicationService.ts index 4f1fac300..2817ad04b 100644 --- a/src/main/service/PublicationService.ts +++ b/src/main/service/PublicationService.ts @@ -61,8 +61,12 @@ export class PublicationService { return this.getCaseFromArtefact(artefact[0], 'caseUrn', urn); } - public async getPublicationsByCourt(locationId: string, userId: string): Promise { - return await publicationRequests.getPublicationsByCourt(locationId, userId, false); + public async getPublicationsByLocation(locationId: string, userId: string, admin = false): Promise { + return await publicationRequests.getPublicationsByLocation(locationId, userId, admin); + } + + public async getNoMatchPublications(userId: string): Promise { + return publicationRequests.getNoMatchPublications(userId); } private getCaseFromArtefact(artefact: Artefact, term: string, value: string): SearchObject { diff --git a/src/main/service/SummaryOfPublicationsService.ts b/src/main/service/SummaryOfPublicationsService.ts deleted file mode 100644 index 2bc586fd8..000000000 --- a/src/main/service/SummaryOfPublicationsService.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { PublicationRequests } from '../resources/requests/PublicationRequests'; -import { Artefact } from '../models/Artefact'; - -const publicationRequests = new PublicationRequests(); - -export class SummaryOfPublicationsService { - public async getPublications(locationId, userId: string, admin = false): Promise { - return publicationRequests.getPublicationsByCourt(locationId, userId, admin); - } - - public async getNoMatchPublications(userId: string): Promise { - return publicationRequests.getNoMatchPublications(userId); - } -} diff --git a/src/test/a11y/tests/admin-routes.test.ts b/src/test/a11y/tests/admin-routes.test.ts index 4ef5211a1..978415fe2 100644 --- a/src/test/a11y/tests/admin-routes.test.ts +++ b/src/test/a11y/tests/admin-routes.test.ts @@ -44,7 +44,7 @@ const userData = testUserData(); sinon.stub(LocationRequests.prototype, 'getLocation').resolves(locationData[0]); sinon.stub(LocationRequests.prototype, 'getFilteredCourts').resolves(locationData); sinon.stub(LocationRequests.prototype, 'getAllLocations').resolves(locationData); -sinon.stub(PublicationRequests.prototype, 'getPublicationsByCourt').resolves(metadata); +sinon.stub(PublicationRequests.prototype, 'getPublicationsByLocation').resolves(metadata); sinon.stub(PublicationRequests.prototype, 'getIndividualPublicationMetadata').resolves(metadata[0]); sinon.stub(AccountManagementRequests.prototype, 'getPendingMediaApplications').resolves(mediaApplications); sinon.stub(AccountManagementRequests.prototype, 'getMediaApplicationById').resolves(mediaApplications[0]); diff --git a/src/test/a11y/tests/media-routes.test.ts b/src/test/a11y/tests/media-routes.test.ts index 54bb6dae4..9c6d84194 100644 --- a/src/test/a11y/tests/media-routes.test.ts +++ b/src/test/a11y/tests/media-routes.test.ts @@ -72,7 +72,7 @@ const subscriptionSearchResults = { sinon.stub(LocationRequests.prototype, 'getLocation').resolves(locationData[0]); sinon.stub(LocationRequests.prototype, 'getFilteredCourts').resolves(locationData); sinon.stub(LocationRequests.prototype, 'getAllLocations').resolves(locationData); -sinon.stub(PublicationRequests.prototype, 'getPublicationsByCourt').resolves(metadata); +sinon.stub(PublicationRequests.prototype, 'getPublicationsByLocation').resolves(metadata); sinon.stub(PublicationRequests.prototype, 'getIndividualPublicationMetadata').returns(metadata[0]); sinon.stub(PublicationService.prototype, 'getCasesByCaseName').resolves([subscriptionSearchResults]); sinon.stub(PublicationService.prototype, 'getCaseByCaseNumber').resolves(subscriptionSearchResults); diff --git a/src/test/a11y/tests/public-routes.test.ts b/src/test/a11y/tests/public-routes.test.ts index 06a348c0c..d98ef71f1 100644 --- a/src/test/a11y/tests/public-routes.test.ts +++ b/src/test/a11y/tests/public-routes.test.ts @@ -5,7 +5,6 @@ import { testArtefactMetadata, testLocationData } from '../common/testData'; import { filterRoutes, testAccessibility } from '../common/pa11yHelper'; import { app } from '../../../main/app'; import { ssoNotAuthorised } from '../../../main/helpers/consts'; -import { SummaryOfPublicationsService } from '../../../main/service/SummaryOfPublicationsService'; import { PublicationService } from '../../../main/service/PublicationService'; const publicRoutes = [ @@ -35,8 +34,8 @@ const metadata = testArtefactMetadata(); sinon.stub(LocationRequests.prototype, 'getLocation').resolves(locationData[0]); sinon.stub(LocationRequests.prototype, 'getFilteredCourts').resolves(locationData); sinon.stub(LocationRequests.prototype, 'getAllLocations').resolves(locationData); -sinon.stub(PublicationRequests.prototype, 'getPublicationsByCourt').resolves(metadata[0]); -sinon.stub(SummaryOfPublicationsService.prototype, 'getPublications').resolves(metadata); +sinon.stub(PublicationRequests.prototype, 'getPublicationsByLocation').resolves(metadata[0]); +sinon.stub(PublicationService.prototype, 'getPublicationsByLocation').resolves(metadata); sinon.stub(PublicationService.prototype, 'getListTypes').returns( new Map([ ['CROWN_WARNED_LIST', { friendlyName: 'List A' }], diff --git a/src/test/a11y/tests/system-admin-routes.test.ts b/src/test/a11y/tests/system-admin-routes.test.ts index 8d84c0644..7b3a10497 100644 --- a/src/test/a11y/tests/system-admin-routes.test.ts +++ b/src/test/a11y/tests/system-admin-routes.test.ts @@ -98,7 +98,7 @@ sinon.stub(LocationRequests.prototype, 'getLocation').resolves(locationData[0]); sinon.stub(LocationRequests.prototype, 'getLocationMetadata').resolves({ locationMetadataId: '123' }); sinon.stub(LocationRequests.prototype, 'getFilteredCourts').resolves(locationData); sinon.stub(LocationRequests.prototype, 'getAllLocations').resolves(locationData); -sinon.stub(PublicationRequests.prototype, 'getPublicationsByCourt').resolves(metadata); +sinon.stub(PublicationRequests.prototype, 'getPublicationsByLocation').resolves(metadata); sinon.stub(PublicationRequests.prototype, 'getIndividualPublicationMetadata').returns(metadata[0]); sinon.stub(PublicationRequests.prototype, 'getPubsPerLocation').returns(countPerLocation); sinon.stub(AccountManagementRequests.prototype, 'getUserByUserId').resolves(userDataThirdParty); diff --git a/src/test/routes/admin/remove-list-search-results.test.ts b/src/test/routes/admin/remove-list-search-results.test.ts index afa1189bd..676161d76 100644 --- a/src/test/routes/admin/remove-list-search-results.test.ts +++ b/src/test/routes/admin/remove-list-search-results.test.ts @@ -3,14 +3,14 @@ import { expect } from 'chai'; import request from 'supertest'; import sinon from 'sinon'; import { LocationService } from '../../../main/service/LocationService'; -import { SummaryOfPublicationsService } from '../../../main/service/SummaryOfPublicationsService'; import { ManualUploadService } from '../../../main/service/ManualUploadService'; import { request as expressRequest } from 'express'; +import { PublicationService } from '../../../main/service/PublicationService'; const URL = '/remove-list-search'; const courtServiceStub = sinon.stub(LocationService.prototype, 'getLocationById'); -sinon.stub(SummaryOfPublicationsService.prototype, 'getPublications').withArgs('2', true, true).resolves([]); +sinon.stub(PublicationService.prototype, 'getPublicationsByLocation').withArgs('2').resolves([]); sinon.stub(ManualUploadService.prototype, 'formatListRemovalValues').withArgs([]).returns([]); courtServiceStub.withArgs('2').resolves(true); courtServiceStub.withArgs('888').resolves(false); diff --git a/src/test/routes/summary-of-publications.test.ts b/src/test/routes/summary-of-publications.test.ts index 994e4343f..5040b91a0 100644 --- a/src/test/routes/summary-of-publications.test.ts +++ b/src/test/routes/summary-of-publications.test.ts @@ -3,12 +3,11 @@ import { app } from '../../main/app'; import request from 'supertest'; import { PublicationService } from '../../main/service/PublicationService'; import sinon from 'sinon'; -import { SummaryOfPublicationsService } from '../../main/service/SummaryOfPublicationsService'; const mockJSON = '{"data":"false"}'; const mockArray = '[{"listType": "List_A"}]'; sinon.stub(PublicationService.prototype, 'getIndividualPublicationJson').resolves(mockJSON); -sinon.stub(SummaryOfPublicationsService.prototype, 'getPublications').resolves(JSON.parse(mockArray)); +sinon.stub(PublicationService.prototype, 'getPublicationsByLocation').resolves(JSON.parse(mockArray)); sinon .stub(PublicationService.prototype, 'getListTypes') .returns(new Map([['List_A', { friendlyName: 'List name A' }]])); diff --git a/src/test/unit/controllers/SummaryOfPublicationsController.test.ts b/src/test/unit/controllers/SummaryOfPublicationsController.test.ts index d1112d979..ed7fce966 100644 --- a/src/test/unit/controllers/SummaryOfPublicationsController.test.ts +++ b/src/test/unit/controllers/SummaryOfPublicationsController.test.ts @@ -5,12 +5,12 @@ import sinon from 'sinon'; import fs from 'fs'; import path from 'path'; import { LocationService } from '../../../main/service/LocationService'; -import { SummaryOfPublicationsService } from '../../../main/service/SummaryOfPublicationsService'; import { PublicationService } from '../../../main/service/PublicationService'; const publicationController = new SummaryOfPublicationsController(); const i18n = { 'list-option': {}, + error: { title: 'error' }, }; const court = { name: 'New Court', email: 'test@test.com', contactNo: '0123456789' }; @@ -28,7 +28,7 @@ const additionalLocationInfo = { sinon .stub(LocationService.prototype, 'getLocationById') .resolves(JSON.parse('{"name":"New Court", "email": "test@test.com", "contactNo": "0123456789"}')); -sinon.stub(SummaryOfPublicationsService.prototype, 'getPublications').resolves(metadata); +sinon.stub(PublicationService.prototype, 'getPublicationsByLocation').resolves(metadata); const additionalLocationInfoStub = sinon.stub(LocationService.prototype, 'getLocationMetadata'); additionalLocationInfoStub.withArgs(1).returns(null); @@ -139,6 +139,22 @@ describe('Get publications', () => { responseMock.verify(); }); + it('should render the error page if location ID is no a number', async () => { + const response = { + render: () => { + return ''; + }, + } as unknown as Response; + const request = mockRequest(i18n); + request.query = { locationId: 'Test2' }; + request.user = { userId: 1 }; + const responseMock = sinon.mock(response); + responseMock + .expects('render') + .once() + .withArgs('error', { ...i18n.error }); + }); + it('should render the error screen if there is no locationId passed as a param', async () => { const response = { render: () => { @@ -148,6 +164,9 @@ describe('Get publications', () => { const request = mockRequest(i18n); request.user = { userId: 1 }; const responseMock = sinon.mock(response); - responseMock.expects('render').once().withArgs('error'); + responseMock + .expects('render') + .once() + .withArgs('error', { ...i18n.error }); }); }); diff --git a/src/test/unit/controllers/admin/RemoveListSearchResultsController.test.ts b/src/test/unit/controllers/admin/RemoveListSearchResultsController.test.ts index cc4008cda..9514c1b89 100644 --- a/src/test/unit/controllers/admin/RemoveListSearchResultsController.test.ts +++ b/src/test/unit/controllers/admin/RemoveListSearchResultsController.test.ts @@ -1,6 +1,5 @@ import sinon from 'sinon'; import { LocationService } from '../../../../main/service/LocationService'; -import { SummaryOfPublicationsService } from '../../../../main/service/SummaryOfPublicationsService'; import { ManualUploadService } from '../../../../main/service/ManualUploadService'; import { Response } from 'express'; import { mockRequest } from '../../mocks/mockRequest'; @@ -62,7 +61,7 @@ const removeListFormData = { courtLists: ['valid-artefact', 'valid-artefact'], l sinon.stub(PublicationService.prototype, 'getIndividualPublicationMetadata').resolves(mockArtefactsArray); sinon.stub(ManualUploadService.prototype, 'formatListRemovalValues').returns(mockArtefactsArray); sinon.stub(LocationService.prototype, 'getLocationById').resolves(mockCourt); -sinon.stub(SummaryOfPublicationsService.prototype, 'getPublications').withArgs('5', true, true).resolves([]); +sinon.stub(PublicationService.prototype, 'getPublicationsByLocation').withArgs('5').resolves([]); const removeListSearchResultsController = new RemoveListSearchResultsController(); @@ -84,7 +83,7 @@ describe('Remove List Summary Controller', () => { await responseMock.verify(); }); - it('should render error page', async () => { + it('should render error page if no lopcation ID', async () => { const request = mockRequest(i18n); const responseMock = sinon.mock(response); request.query = {}; @@ -95,6 +94,19 @@ describe('Remove List Summary Controller', () => { await removeListSearchResultsController.get(request, response); await responseMock.verify(); }); + + it('should render error page if location ID not an integer', async () => { + const responseMock = sinon.mock(response); + const request = mockRequest(i18n); + request.query = { locationId: 'Test5' }; + + responseMock + .expects('render') + .once() + .withArgs('error', { ...i18n.error }); + await removeListSearchResultsController.get(request, response); + await responseMock.verify(); + }); }); describe('POST request', () => { diff --git a/src/test/unit/controllers/system-admin/BlobViewPublicationsController.test.ts b/src/test/unit/controllers/system-admin/BlobViewPublicationsController.test.ts index 190b4ca5b..4ec4a508f 100644 --- a/src/test/unit/controllers/system-admin/BlobViewPublicationsController.test.ts +++ b/src/test/unit/controllers/system-admin/BlobViewPublicationsController.test.ts @@ -3,13 +3,14 @@ import { mockRequest } from '../../mocks/mockRequest'; import sinon from 'sinon'; import { LocationService } from '../../../../main/service/LocationService'; import BlobViewPublicationsController from '../../../../main/controllers/system-admin/BlobViewPublicationsController'; -import { SummaryOfPublicationsService } from '../../../../main/service/SummaryOfPublicationsService'; import fs from 'fs'; import path from 'path'; +import { PublicationService } from '../../../../main/service/PublicationService'; const blobViewController = new BlobViewPublicationsController(); const i18n = { 'blob-view-publications': {}, + error: { title: 'error' }, }; const rawSJPData = fs.readFileSync(path.resolve(__dirname, '../../mocks/trimmedSJPCases.json'), 'utf-8'); const sjpCases = JSON.parse(rawSJPData).results; @@ -21,7 +22,7 @@ describe('Get publications', () => { .withArgs(1) .resolves(JSON.parse('{"name":"New Court"}')); - sinon.stub(SummaryOfPublicationsService.prototype, 'getPublications').withArgs(1).resolves(sjpCases); + sinon.stub(PublicationService.prototype, 'getPublicationsByLocation').withArgs(1).resolves(sjpCases); const response = { render: () => { @@ -44,8 +45,28 @@ describe('Get publications', () => { responseMock.verify; }); + it('should render error page if location ID is not an integer', async () => { + const response = { + render: () => { + return ''; + }, + } as unknown as Response; + const request = mockRequest(i18n); + request.query = { locationId: 'Test1' }; + request.user = { id: 1 }; + + const responseMock = sinon.mock(response); + + responseMock + .expects('render') + .once() + .withArgs('error', { ...i18n.error }); + await blobViewController.get(request, response); + responseMock.verify; + }); + it('should render No Match artefacts if location ID equals noMatch', async () => { - sinon.stub(SummaryOfPublicationsService.prototype, 'getNoMatchPublications').resolves(sjpCases); + sinon.stub(PublicationService.prototype, 'getNoMatchPublications').resolves(sjpCases); const response = { render: () => { diff --git a/src/test/unit/requests/publicationRequests.test.ts b/src/test/unit/requests/publicationRequests.test.ts index a648212bc..47e93de3a 100644 --- a/src/test/unit/requests/publicationRequests.test.ts +++ b/src/test/unit/requests/publicationRequests.test.ts @@ -134,25 +134,21 @@ describe('Get by case value', () => { }); }); -describe('Get publication by court id', () => { +describe('Get publications by location ID', () => { dataManagementStub.withArgs('/publication/locationId/valid').resolves(successResponse); dataManagementStub.withArgs('/publication/locationId/invalid').rejects(errorResponse); dataManagementStub.withArgs('/publication/locationId/error').rejects(errorMessage); it('should return data on successful get', async () => { - expect(await pubRequests.getPublicationsByCourt(valid, userId, false)).toBe(successResponse.data); + expect(await pubRequests.getPublicationsByLocation(valid, userId, false)).toBe(successResponse.data); }); it('should handle error response from returned service returning empty array', async () => { - expect(await pubRequests.getPublicationsByCourt(invalid, userId, false)).toStrictEqual([]); + expect(await pubRequests.getPublicationsByLocation(invalid, userId, false)).toStrictEqual([]); }); it('should handle error request from returned service returning empty array', async () => { - expect(await pubRequests.getPublicationsByCourt('test', userId, false)).toStrictEqual([]); - }); - - it('should handle error request from returned service returning empty array', async () => { - expect(await pubRequests.getPublicationsByCourt('error', userId, false)).toStrictEqual([]); + expect(await pubRequests.getPublicationsByLocation('error', userId, false)).toStrictEqual([]); }); }); @@ -219,9 +215,9 @@ describe('get individual publication file', () => { }); it('should send an error to the log if error message exists and error request does not exist', async () => { - dataManagementStub.withArgs('/publication/search/y').rejects(errorMessage); - const message = await publicationRequests.getPublicationsByCourt('y', userId, false); - expect(message).toStrictEqual([]); + dataManagementStub.withArgs('/publication/noErrRequest/payload').rejects(errorMessage); + const message = await publicationRequests.getIndividualPublicationFile('y', userId); + expect(message).toBe(null); }); }); diff --git a/src/test/unit/service/PublicationService.test.ts b/src/test/unit/service/PublicationService.test.ts index 788b88d55..8e6f4a075 100644 --- a/src/test/unit/service/PublicationService.test.ts +++ b/src/test/unit/service/PublicationService.test.ts @@ -107,9 +107,10 @@ stub.withArgs().returns(dailyCauseListData); const stubMetaData = sinon.stub(publicationRequests, 'getIndividualPublicationMetadata'); stubMetaData.returns(metaData); -const stubCourtPubs = sinon.stub(publicationRequests, 'getPublicationsByCourt'); -stubCourtPubs.withArgs('1', userId, false).resolves(returnedArtefact); -stubCourtPubs.withArgs('2', userId, false).resolves([]); +const stubPublicationsByLocation = sinon.stub(publicationRequests, 'getPublicationsByLocation'); +stubPublicationsByLocation.withArgs('1').resolves(returnedArtefact); +stubPublicationsByLocation.withArgs('2').resolves([]); + sinon.stub(publicationRequests, 'getPubsPerLocation').returns(countPerLocation); const validCourtName = 'PRESTON'; const invalidCourtName = 'TEST'; @@ -119,6 +120,8 @@ const stubPublicationDeletion = sinon.stub(PublicationRequests.prototype, 'delet stubPublicationDeletion.withArgs(1, adminUserId).returns('success'); stubPublicationDeletion.withArgs(2, adminUserId).returns(null); +sinon.stub(PublicationRequests.prototype, 'getNoMatchPublications').resolves('{"item":"listOfPubs"}'); + describe('Publication service', () => { it('should return array of Search Objects based on partial case name', async () => { const results = await publicationService.getCasesByCaseName(partialCaseNameValue, userId); @@ -221,17 +224,23 @@ describe('Publication service', () => { }); }); - describe('getPublicationsByCourt Publication Service', () => { + describe('getPublicationsByLocation', () => { it('should return artefact for a valid call', async () => { - const data = await publicationService.getPublicationsByCourt('1', userId); + const data = await publicationService.getPublicationsByLocation('1', userId); expect(data).to.deep.equal(returnedArtefact); }); it('should return empty list for a invalid call', async () => { - const data = await publicationService.getPublicationsByCourt('2', userId); + const data = await publicationService.getPublicationsByLocation('2', userId); expect(data).to.deep.equal([]); }); }); + describe('getNoMatchPublications', () => { + it('should return a list of noMatch publications', async () => { + expect(await publicationService.getNoMatchPublications('123-456')).to.equal('{"item":"listOfPubs"}'); + }); + }); + describe('Count of locationIds->pubs endpoint', () => { it('should return a list of locationIds alongside the relevant number of publications', async () => { const data = await publicationService.getCountsOfPubsPerLocation('123-456'); diff --git a/src/test/unit/service/SummaryOfPublicationsService.test.ts b/src/test/unit/service/SummaryOfPublicationsService.test.ts deleted file mode 100644 index 8fa061ee9..000000000 --- a/src/test/unit/service/SummaryOfPublicationsService.test.ts +++ /dev/null @@ -1,37 +0,0 @@ -import sinon from 'sinon'; -import { expect } from 'chai'; -import { PublicationService } from '../../../main/service/PublicationService'; -import { PublicationRequests } from '../../../main/resources/requests/PublicationRequests'; -import { SummaryOfPublicationsService } from '../../../main/service/SummaryOfPublicationsService'; - -const userId = '123'; -const sopService = new SummaryOfPublicationsService(); -const pubService = new PublicationService(); -const pubStub = sinon.stub(PublicationRequests.prototype, 'getPublicationsByCourt'); -const pubNoMatchStub = sinon.stub(PublicationRequests.prototype, 'getNoMatchPublications'); -const fileStub = sinon.stub(PublicationRequests.prototype, 'getIndividualPublicationFile'); -const metaStub = sinon.stub(PublicationRequests.prototype, 'getIndividualPublicationMetadata'); -const jsonStub = sinon.stub(PublicationRequests.prototype, 'getIndividualPublicationJson'); - -describe('Summary Of Publications Service', () => { - it('should return a list of publications', async () => { - pubStub.withArgs(0).resolves('{"item":"listOfPubs"}'); - expect(await sopService.getPublications(0, userId)).to.equal('{"item":"listOfPubs"}'); - }); - it('should return metadata', async () => { - metaStub.withArgs(0).resolves('{"item":"listOfMetadata"}'); - expect(await pubService.getIndividualPublicationMetadata(0, userId)).to.equal('{"item":"listOfMetadata"}'); - }); - it('should return file', async () => { - fileStub.withArgs(0).resolves('{"item":"file"}'); - expect(await pubService.getIndividualPublicationFile(0, userId)).to.equal('{"item":"file"}'); - }); - it('should return json', async () => { - jsonStub.withArgs(0).resolves('{"item":"json"}'); - expect(await pubService.getIndividualPublicationJson(0, userId)).to.equal('{"item":"json"}'); - }); - it('should return a list of noMatch publications', async () => { - pubNoMatchStub.resolves('{"item":"listOfPubs"}'); - expect(await sopService.getNoMatchPublications('123-456')).to.equal('{"item":"listOfPubs"}'); - }); -}); diff --git a/src/test/unit/views/admin/remove-list-search-results.test.ts b/src/test/unit/views/admin/remove-list-search-results.test.ts index 0b4014865..22bb7ee62 100644 --- a/src/test/unit/views/admin/remove-list-search-results.test.ts +++ b/src/test/unit/views/admin/remove-list-search-results.test.ts @@ -1,11 +1,11 @@ import { LocationService } from '../../../../main/service/LocationService'; -import { SummaryOfPublicationsService } from '../../../../main/service/SummaryOfPublicationsService'; import { ManualUploadService } from '../../../../main/service/ManualUploadService'; import sinon from 'sinon'; import request from 'supertest'; import { app } from '../../../../main/app'; import { expect } from 'chai'; import { request as expressRequest } from 'express'; +import { PublicationService } from '../../../../main/service/PublicationService'; const PAGE_URL = '/remove-list-search-results?locationId=5'; const mockCourt = { @@ -43,10 +43,7 @@ const languageRowValues = ['English', 'Welsh']; const sensitivityValues = ['Public', 'Classified', 'Classified']; const checkboxType = 'input type="checkbox"'; sinon.stub(LocationService.prototype, 'getLocationById').resolves(mockCourt); -sinon - .stub(SummaryOfPublicationsService.prototype, 'getPublications') - .withArgs('5', true, true) - .resolves(mockPublications); +sinon.stub(PublicationService.prototype, 'getPublicationsByLocation').withArgs('5').resolves(mockPublications); sinon.stub(ManualUploadService.prototype, 'formatListRemovalValues').returns(mockPublications); expressRequest['user'] = { roles: 'SYSTEM_ADMIN' }; diff --git a/src/test/unit/views/summary-of-publications.test.ts b/src/test/unit/views/summary-of-publications.test.ts index 37eca5f24..4fd543559 100644 --- a/src/test/unit/views/summary-of-publications.test.ts +++ b/src/test/unit/views/summary-of-publications.test.ts @@ -3,7 +3,7 @@ import request from 'supertest'; import { app } from '../../../main/app'; import { expect } from 'chai'; import { LocationService } from '../../../main/service/LocationService'; -import { SummaryOfPublicationsService } from '../../../main/service/SummaryOfPublicationsService'; +import { PublicationService } from '../../../main/service/PublicationService'; const locationIdWithTelephoneAndEmail = 10; const locationIdWithTelephoneOnly = 11; @@ -26,12 +26,12 @@ courtStub.withArgs(locationIdWithNoListMessageOverride).resolves(JSON.parse('{"n courtStub.withArgs(locationIdWithCautionMessageOverride).resolves(JSON.parse('{"name":"New Court"}')); courtStub.withArgs(locationIdWithHtmlMessageOverride).resolves(JSON.parse('{"name":"New Court"}')); -const publicationStub = sinon.stub(SummaryOfPublicationsService.prototype, 'getPublications'); -publicationStub.withArgs(locationIdWithTelephoneAndEmail).resolves([]); -publicationStub.withArgs(locationIdWithTelephoneOnly).resolves([]); -publicationStub.withArgs(locationIdWithEmailOnly).resolves([]); -publicationStub.withArgs(locationIdWithoutContact).resolves([]); -publicationStub.withArgs(locationIdWithPublications).resolves([ +const publicationStub = sinon.stub(PublicationService.prototype, 'getPublicationsByLocation'); +publicationStub.withArgs(locationIdWithTelephoneAndEmail.toString()).resolves([]); +publicationStub.withArgs(locationIdWithTelephoneOnly.toString()).resolves([]); +publicationStub.withArgs(locationIdWithEmailOnly.toString()).resolves([]); +publicationStub.withArgs(locationIdWithoutContact.toString()).resolves([]); +publicationStub.withArgs(locationIdWithPublications.toString()).resolves([ { artefactId: '1', listType: 'CIVIL_DAILY_CAUSE_LIST', contentDate: '2025-01-20T00:00:00Z', language: 'WELSH' }, { artefactId: '2', listType: 'CIVIL_DAILY_CAUSE_LIST', contentDate: '2025-01-20T00:00:00Z', language: 'ENGLISH' }, { artefactId: '3', listType: 'CST_WEEKLY_HEARING_LIST', contentDate: '2025-01-20T00:00:00Z', language: 'ENGLISH' }, @@ -41,12 +41,12 @@ publicationStub.withArgs(locationIdWithPublications).resolves([ { artefactId: '7', listType: 'AST_DAILY_HEARING_LIST', contentDate: '2025-01-18T00:00:00Z', language: 'ENGLISH' }, { artefactId: '8', listType: 'AST_DAILY_HEARING_LIST', contentDate: '2025-01-19T00:00:00Z', language: 'WELSH' }, ]); -publicationStub.withArgs(locationIdWithNoListMessageOverride).resolves([]); -publicationStub.withArgs(locationIdWithCautionMessageOverride).resolves([ +publicationStub.withArgs(locationIdWithNoListMessageOverride.toString()).resolves([]); +publicationStub.withArgs(locationIdWithCautionMessageOverride.toString()).resolves([ { artefactId: '1', listType: 'CIVIL_DAILY_CAUSE_LIST', contentDate: '2025-01-20T00:00:00Z', language: 'ENGLISH' }, { artefactId: '2', listType: 'CST_WEEKLY_HEARING_LIST', contentDate: '2025-01-20T00:00:00Z', language: 'ENGLISH' }, ]); -publicationStub.withArgs(locationIdWithHtmlMessageOverride).resolves([]); +publicationStub.withArgs(locationIdWithHtmlMessageOverride.toString()).resolves([]); const locationMetadataResponse = { locationMetadataId: '123-456', diff --git a/src/test/unit/views/system-admin/blob-view-publications.test.ts b/src/test/unit/views/system-admin/blob-view-publications.test.ts index 53050f4b5..352e759e9 100644 --- a/src/test/unit/views/system-admin/blob-view-publications.test.ts +++ b/src/test/unit/views/system-admin/blob-view-publications.test.ts @@ -3,16 +3,22 @@ import request from 'supertest'; import { expect } from 'chai'; import { app } from '../../../../main/app'; import { LocationService } from '../../../../main/service/LocationService'; -import { SummaryOfPublicationsService } from '../../../../main/service/SummaryOfPublicationsService'; +import { PublicationService } from '../../../../main/service/PublicationService'; const publicationsMock = [ { artefactId: '1', listType: 'TYPE1', locationId: '1', publicationDate: '2024-06-01', contentDate: '2024-06-01' }, - { artefactId: '2', listType: 'TYPE2', locationId: '1', publicationDate: '2024-06-02', contentDate: '2024-06-02' } + { artefactId: '2', listType: 'TYPE2', locationId: '1', publicationDate: '2024-06-02', contentDate: '2024-06-02' }, ]; -sinon.stub(SummaryOfPublicationsService.prototype, 'getPublications').resolves(publicationsMock); -sinon.stub(SummaryOfPublicationsService.prototype, 'getNoMatchPublications').resolves([ - { artefactId: '3', listType: 'TYPE3', locationId: '2', publicationDate: '2024-06-03', contentDate: '2024-06-03' } +sinon.stub(PublicationService.prototype, 'getPublicationsByLocation').resolves(publicationsMock); +sinon.stub(PublicationService.prototype, 'getNoMatchPublications').resolves([ + { + artefactId: '3', + listType: 'TYPE3', + locationId: '2', + publicationDate: '2024-06-03', + contentDate: '2024-06-03', + }, ]); sinon.stub(LocationService.prototype, 'getLocationById').resolves({ locationId: 1, name: 'Alpha Court' }); sinon.stub(LocationService.prototype, 'findCourtName').returns('Alpha Court');