Skip to content

Commit

Permalink
Merge pull request DSpace#2816 from atmire/w2p-111326_fix-status-code…
Browse files Browse the repository at this point in the history
…-object-not-found-7.4

Return 404 Not Found status code on missing identifiers
  • Loading branch information
tdonohue authored Apr 19, 2024
2 parents a4387bb + b48db7d commit 6d582cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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';
Expand All @@ -21,6 +22,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 }),
});
Expand All @@ -31,6 +36,7 @@ describe('ObjectNotFoundComponent', () => {
TranslateModule.forRoot(),
ObjectNotFoundComponent,
], providers: [
{ provide: ServerResponseService, useValue: serverResponseServiceStub } ,
{ provide: ActivatedRoute, useValue: activatedRouteStub },
],
schemas: [NO_ERRORS_SCHEMA],
Expand All @@ -52,6 +58,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', () => {
Expand All @@ -61,6 +71,7 @@ describe('ObjectNotFoundComponent', () => {
TranslateModule.forRoot(),
ObjectNotFoundComponent,
], providers: [
{ provide: ServerResponseService, useValue: serverResponseServiceStub },
{ provide: ActivatedRoute, useValue: activatedRouteStubHandle },
],
schemas: [NO_ERRORS_SCHEMA],
Expand All @@ -78,6 +89,10 @@ describe('ObjectNotFoundComponent', () => {
expect(comp.idType).toEqual(handlePrefix);
expect(comp.missingItem).toEqual('handle: ' + handlePrefix + '/' + handleId);
});

it('should call serverResponseService.setNotFound', () => {
expect(serverResponseServiceStub.setNotFound).toHaveBeenCalled();
});
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
RouterLink,
} from '@angular/router';
import { TranslateModule } from '@ngx-translate/core';
import { ServerResponseService } from 'src/app/core/services/server-response.service';

/**
* This component representing the `PageNotFound` DSpace page.
Expand All @@ -35,7 +36,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;
Expand All @@ -48,6 +49,7 @@ export class ObjectNotFoundComponent implements OnInit {
} else {
this.missingItem = 'handle: ' + this.idType + '/' + this.id;
}
this.serverResponseService.setNotFound();
}

}

0 comments on commit 6d582cd

Please sign in to comment.