Merge pull request #2816 from atmire/w2p-111326_fix-status-code-object-not-found-7.4

Return 404 Not Found status code on missing identifiers
This commit is contained in:
Tim Donohue
2024-04-19 12:07:21 -05:00
committed by GitHub
2 changed files with 18 additions and 1 deletions

View File

@@ -7,6 +7,7 @@ import {
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { of as observableOf } from 'rxjs'; 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 { ActivatedRouteStub } from '../../shared/testing/active-router.stub';
import { ObjectNotFoundComponent } from './objectnotfound.component'; import { ObjectNotFoundComponent } from './objectnotfound.component';
@@ -21,6 +22,10 @@ describe('ObjectNotFoundComponent', () => {
const activatedRouteStub = Object.assign(new ActivatedRouteStub(), { const activatedRouteStub = Object.assign(new ActivatedRouteStub(), {
params: observableOf({ id: testUUID, idType: uuidType }), params: observableOf({ id: testUUID, idType: uuidType }),
}); });
const serverResponseServiceStub = jasmine.createSpyObj('ServerResponseService', {
setNotFound: jasmine.createSpy('setNotFound'),
});
const activatedRouteStubHandle = Object.assign(new ActivatedRouteStub(), { const activatedRouteStubHandle = Object.assign(new ActivatedRouteStub(), {
params: observableOf({ id: handleId, idType: handlePrefix }), params: observableOf({ id: handleId, idType: handlePrefix }),
}); });
@@ -31,6 +36,7 @@ describe('ObjectNotFoundComponent', () => {
TranslateModule.forRoot(), TranslateModule.forRoot(),
ObjectNotFoundComponent, ObjectNotFoundComponent,
], providers: [ ], providers: [
{ provide: ServerResponseService, useValue: serverResponseServiceStub } ,
{ provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: ActivatedRoute, useValue: activatedRouteStub },
], ],
schemas: [NO_ERRORS_SCHEMA], schemas: [NO_ERRORS_SCHEMA],
@@ -52,6 +58,10 @@ describe('ObjectNotFoundComponent', () => {
expect(comp.idType).toEqual(uuidType); expect(comp.idType).toEqual(uuidType);
expect(comp.missingItem).toEqual('uuid: ' + testUUID); expect(comp.missingItem).toEqual('uuid: ' + testUUID);
}); });
it('should call serverResponseService.setNotFound', () => {
expect(serverResponseServiceStub.setNotFound).toHaveBeenCalled();
});
}); });
describe( 'legacy handle request', () => { describe( 'legacy handle request', () => {
@@ -61,6 +71,7 @@ describe('ObjectNotFoundComponent', () => {
TranslateModule.forRoot(), TranslateModule.forRoot(),
ObjectNotFoundComponent, ObjectNotFoundComponent,
], providers: [ ], providers: [
{ provide: ServerResponseService, useValue: serverResponseServiceStub },
{ provide: ActivatedRoute, useValue: activatedRouteStubHandle }, { provide: ActivatedRoute, useValue: activatedRouteStubHandle },
], ],
schemas: [NO_ERRORS_SCHEMA], schemas: [NO_ERRORS_SCHEMA],
@@ -78,6 +89,10 @@ describe('ObjectNotFoundComponent', () => {
expect(comp.idType).toEqual(handlePrefix); expect(comp.idType).toEqual(handlePrefix);
expect(comp.missingItem).toEqual('handle: ' + handlePrefix + '/' + handleId); expect(comp.missingItem).toEqual('handle: ' + handlePrefix + '/' + handleId);
}); });
it('should call serverResponseService.setNotFound', () => {
expect(serverResponseServiceStub.setNotFound).toHaveBeenCalled();
});
}); });
}); });

View File

@@ -9,6 +9,7 @@ import {
RouterLink, RouterLink,
} from '@angular/router'; } from '@angular/router';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { ServerResponseService } from 'src/app/core/services/server-response.service';
/** /**
* This component representing the `PageNotFound` DSpace page. * This component representing the `PageNotFound` DSpace page.
@@ -35,7 +36,7 @@ export class ObjectNotFoundComponent implements OnInit {
* @param {AuthService} authservice * @param {AuthService} authservice
* @param {ServerResponseService} responseService * @param {ServerResponseService} responseService
*/ */
constructor(private route: ActivatedRoute) { constructor(private route: ActivatedRoute, private serverResponseService: ServerResponseService) {
route.params.subscribe((params) => { route.params.subscribe((params) => {
this.idType = params.idType; this.idType = params.idType;
this.id = params.id; this.id = params.id;
@@ -48,6 +49,7 @@ export class ObjectNotFoundComponent implements OnInit {
} else { } else {
this.missingItem = 'handle: ' + this.idType + '/' + this.id; this.missingItem = 'handle: ' + this.idType + '/' + this.id;
} }
this.serverResponseService.setNotFound();
} }
} }