Skip to content

Commit ab90c7a

Browse files
author
Jens Vannerum
committed
111326: return not found status code on missing identifiers
1 parent ca86437 commit ab90c7a

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/app/lookup-by-id/objectnotfound/objectnotfound.component.spec.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ObjectNotFoundComponent } from './objectnotfound.component';
66
import { ActivatedRouteStub } from '../../shared/testing/active-router.stub';
77
import { of as observableOf } from 'rxjs';
88
import { ActivatedRoute } from '@angular/router';
9+
import { ServerResponseService } from 'src/app/core/services/server-response.service';
910

1011
describe('ObjectNotFoundComponent', () => {
1112
let comp: ObjectNotFoundComponent;
@@ -17,6 +18,10 @@ describe('ObjectNotFoundComponent', () => {
1718
const activatedRouteStub = Object.assign(new ActivatedRouteStub(), {
1819
params: observableOf({id: testUUID, idType: uuidType})
1920
});
21+
const serverResponseServiceStub = jasmine.createSpyObj('ServerResponseService', {
22+
setNotFound: jasmine.createSpy('setNotFound')
23+
});
24+
2025
const activatedRouteStubHandle = Object.assign(new ActivatedRouteStub(), {
2126
params: observableOf({id: handleId, idType: handlePrefix})
2227
});
@@ -26,6 +31,7 @@ describe('ObjectNotFoundComponent', () => {
2631
imports: [
2732
TranslateModule.forRoot()
2833
], providers: [
34+
{provide: ServerResponseService, useValue: serverResponseServiceStub},
2935
{provide: ActivatedRoute, useValue: activatedRouteStub}
3036
],
3137
declarations: [ObjectNotFoundComponent],
@@ -48,6 +54,10 @@ describe('ObjectNotFoundComponent', () => {
4854
expect(comp.idType).toEqual(uuidType);
4955
expect(comp.missingItem).toEqual('uuid: ' + testUUID);
5056
});
57+
58+
it('should call serverResponseService.setNotFound', () => {
59+
expect(serverResponseServiceStub.setNotFound).toHaveBeenCalled();
60+
});
5161
});
5262

5363
describe( 'legacy handle request', () => {
@@ -56,6 +66,7 @@ describe('ObjectNotFoundComponent', () => {
5666
imports: [
5767
TranslateModule.forRoot()
5868
], providers: [
69+
{provide: ServerResponseService, useValue: serverResponseServiceStub},
5970
{provide: ActivatedRoute, useValue: activatedRouteStubHandle}
6071
],
6172
declarations: [ObjectNotFoundComponent],
@@ -74,6 +85,9 @@ describe('ObjectNotFoundComponent', () => {
7485
expect(comp.idType).toEqual(handlePrefix);
7586
expect(comp.missingItem).toEqual('handle: ' + handlePrefix + '/' + handleId);
7687
});
77-
});
7888

89+
it('should call serverResponseService.setNotFound', () => {
90+
expect(serverResponseServiceStub.setNotFound).toHaveBeenCalled();
91+
});
92+
});
7993
});

src/app/lookup-by-id/objectnotfound/objectnotfound.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
import { Component, ChangeDetectionStrategy, OnInit } from '@angular/core';
33
import { ActivatedRoute } from '@angular/router';
4+
import { ServerResponseService } from 'src/app/core/services/server-response.service';
45

56
/**
67
* This component representing the `PageNotFound` DSpace page.
@@ -25,7 +26,7 @@ export class ObjectNotFoundComponent implements OnInit {
2526
* @param {AuthService} authservice
2627
* @param {ServerResponseService} responseService
2728
*/
28-
constructor(private route: ActivatedRoute) {
29+
constructor(private route: ActivatedRoute, private serverResponseService: ServerResponseService) {
2930
route.params.subscribe((params) => {
3031
this.idType = params.idType;
3132
this.id = params.id;
@@ -38,6 +39,7 @@ export class ObjectNotFoundComponent implements OnInit {
3839
} else {
3940
this.missingItem = 'handle: ' + this.idType + '/' + this.id;
4041
}
42+
this.serverResponseService.setNotFound();
4143
}
4244

4345
}

0 commit comments

Comments
 (0)