From ab90c7a733e575c9a75407be549d124bff49fd48 Mon Sep 17 00:00:00 2001 From: Jens Vannerum Date: Mon, 19 Feb 2024 13:34:29 +0100 Subject: [PATCH 1/2] 111326: return not found status code on missing identifiers --- .../objectnotfound.component.spec.ts | 16 +++++++++++++++- .../objectnotfound/objectnotfound.component.ts | 4 +++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/app/lookup-by-id/objectnotfound/objectnotfound.component.spec.ts b/src/app/lookup-by-id/objectnotfound/objectnotfound.component.spec.ts index f0139e92514..b293ead1027 100644 --- a/src/app/lookup-by-id/objectnotfound/objectnotfound.component.spec.ts +++ b/src/app/lookup-by-id/objectnotfound/objectnotfound.component.spec.ts @@ -6,6 +6,7 @@ import { ObjectNotFoundComponent } from './objectnotfound.component'; import { ActivatedRouteStub } from '../../shared/testing/active-router.stub'; import { of as observableOf } from 'rxjs'; import { ActivatedRoute } from '@angular/router'; +import { ServerResponseService } from 'src/app/core/services/server-response.service'; describe('ObjectNotFoundComponent', () => { let comp: ObjectNotFoundComponent; @@ -17,6 +18,10 @@ describe('ObjectNotFoundComponent', () => { const activatedRouteStub = Object.assign(new ActivatedRouteStub(), { params: observableOf({id: testUUID, idType: uuidType}) }); + const serverResponseServiceStub = jasmine.createSpyObj('ServerResponseService', { + setNotFound: jasmine.createSpy('setNotFound') + }); + const activatedRouteStubHandle = Object.assign(new ActivatedRouteStub(), { params: observableOf({id: handleId, idType: handlePrefix}) }); @@ -26,6 +31,7 @@ describe('ObjectNotFoundComponent', () => { imports: [ TranslateModule.forRoot() ], providers: [ + {provide: ServerResponseService, useValue: serverResponseServiceStub}, {provide: ActivatedRoute, useValue: activatedRouteStub} ], declarations: [ObjectNotFoundComponent], @@ -48,6 +54,10 @@ describe('ObjectNotFoundComponent', () => { expect(comp.idType).toEqual(uuidType); expect(comp.missingItem).toEqual('uuid: ' + testUUID); }); + + it('should call serverResponseService.setNotFound', () => { + expect(serverResponseServiceStub.setNotFound).toHaveBeenCalled(); + }); }); describe( 'legacy handle request', () => { @@ -56,6 +66,7 @@ describe('ObjectNotFoundComponent', () => { imports: [ TranslateModule.forRoot() ], providers: [ + {provide: ServerResponseService, useValue: serverResponseServiceStub}, {provide: ActivatedRoute, useValue: activatedRouteStubHandle} ], declarations: [ObjectNotFoundComponent], @@ -74,6 +85,9 @@ describe('ObjectNotFoundComponent', () => { expect(comp.idType).toEqual(handlePrefix); expect(comp.missingItem).toEqual('handle: ' + handlePrefix + '/' + handleId); }); - }); + it('should call serverResponseService.setNotFound', () => { + expect(serverResponseServiceStub.setNotFound).toHaveBeenCalled(); + }); + }); }); diff --git a/src/app/lookup-by-id/objectnotfound/objectnotfound.component.ts b/src/app/lookup-by-id/objectnotfound/objectnotfound.component.ts index bbab90f39dd..cad78f8555c 100644 --- a/src/app/lookup-by-id/objectnotfound/objectnotfound.component.ts +++ b/src/app/lookup-by-id/objectnotfound/objectnotfound.component.ts @@ -1,6 +1,7 @@ import { Component, ChangeDetectionStrategy, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; +import { ServerResponseService } from 'src/app/core/services/server-response.service'; /** * This component representing the `PageNotFound` DSpace page. @@ -25,7 +26,7 @@ export class ObjectNotFoundComponent implements OnInit { * @param {AuthService} authservice * @param {ServerResponseService} responseService */ - constructor(private route: ActivatedRoute) { + constructor(private route: ActivatedRoute, private serverResponseService: ServerResponseService) { route.params.subscribe((params) => { this.idType = params.idType; this.id = params.id; @@ -38,6 +39,7 @@ export class ObjectNotFoundComponent implements OnInit { } else { this.missingItem = 'handle: ' + this.idType + '/' + this.id; } + this.serverResponseService.setNotFound(); } } From f9c8103266f7ca392356be92107d0e9d8bb7f89c Mon Sep 17 00:00:00 2001 From: Jens Vannerum Date: Fri, 8 Mar 2024 17:14:01 +0100 Subject: [PATCH 2/2] 111326: update to new lint standards --- .../objectnotfound/objectnotfound.component.spec.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/lookup-by-id/objectnotfound/objectnotfound.component.spec.ts b/src/app/lookup-by-id/objectnotfound/objectnotfound.component.spec.ts index 540e4c08639..de79d07c0fd 100644 --- a/src/app/lookup-by-id/objectnotfound/objectnotfound.component.spec.ts +++ b/src/app/lookup-by-id/objectnotfound/objectnotfound.component.spec.ts @@ -7,10 +7,10 @@ import { import { ActivatedRoute } from '@angular/router'; import { TranslateModule } from '@ngx-translate/core'; import { of as observableOf } from 'rxjs'; +import { ServerResponseService } from 'src/app/core/services/server-response.service'; import { ActivatedRouteStub } from '../../shared/testing/active-router.stub'; import { ObjectNotFoundComponent } from './objectnotfound.component'; -import { ServerResponseService } from 'src/app/core/services/server-response.service'; describe('ObjectNotFoundComponent', () => { let comp: ObjectNotFoundComponent; @@ -23,7 +23,7 @@ describe('ObjectNotFoundComponent', () => { params: observableOf({ id: testUUID, idType: uuidType }), }); const serverResponseServiceStub = jasmine.createSpyObj('ServerResponseService', { - setNotFound: jasmine.createSpy('setNotFound') + setNotFound: jasmine.createSpy('setNotFound'), }); const activatedRouteStubHandle = Object.assign(new ActivatedRouteStub(), { @@ -35,8 +35,8 @@ describe('ObjectNotFoundComponent', () => { imports: [ TranslateModule.forRoot(), ], providers: [ - { provide: ServerResponseService, useValue: serverResponseServiceStub} , - { provide: ActivatedRoute, useValue: activatedRouteStub } + { provide: ServerResponseService, useValue: serverResponseServiceStub } , + { provide: ActivatedRoute, useValue: activatedRouteStub }, ], declarations: [ObjectNotFoundComponent], schemas: [NO_ERRORS_SCHEMA], @@ -71,7 +71,7 @@ describe('ObjectNotFoundComponent', () => { TranslateModule.forRoot(), ], providers: [ { provide: ServerResponseService, useValue: serverResponseServiceStub }, - { provide: ActivatedRoute, useValue: activatedRouteStubHandle } + { provide: ActivatedRoute, useValue: activatedRouteStubHandle }, ], declarations: [ObjectNotFoundComponent], schemas: [NO_ERRORS_SCHEMA],