Skip to content

Commit

Permalink
111326: return not found status code on missing identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jens Vannerum committed Feb 19, 2024
1 parent ca86437 commit 61cbfb4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ 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', () => {
fdescribe('ObjectNotFoundComponent', () => {
let comp: ObjectNotFoundComponent;
let fixture: ComponentFixture<ObjectNotFoundComponent>;
const testUUID = '34cfed7c-f597-49ef-9cbe-ea351f0023c2';
Expand All @@ -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})
});
Expand All @@ -26,6 +31,7 @@ describe('ObjectNotFoundComponent', () => {
imports: [
TranslateModule.forRoot()
], providers: [
{provide: ServerResponseService, useValue: serverResponseServiceStub},
{provide: ActivatedRoute, useValue: activatedRouteStub}
],
declarations: [ObjectNotFoundComponent],
Expand All @@ -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', () => {
Expand All @@ -56,6 +66,7 @@ describe('ObjectNotFoundComponent', () => {
imports: [
TranslateModule.forRoot()
], providers: [
{provide: ServerResponseService, useValue: serverResponseServiceStub},
{provide: ActivatedRoute, useValue: activatedRouteStubHandle}
],
declarations: [ObjectNotFoundComponent],
Expand All @@ -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();
});
})

Check failure on line 92 in src/app/lookup-by-id/objectnotfound/objectnotfound.component.spec.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

Missing semicolon

Check failure on line 92 in src/app/lookup-by-id/objectnotfound/objectnotfound.component.spec.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Missing semicolon
});
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -38,6 +39,7 @@ export class ObjectNotFoundComponent implements OnInit {
} else {
this.missingItem = 'handle: ' + this.idType + '/' + this.id;
}
this.serverResponseService.setNotFound();
}

}

0 comments on commit 61cbfb4

Please sign in to comment.