Skip to content

Commit e146109

Browse files
author
Andrea Barbasso
committed
[DURACOM-263] fix redirect to submission form on new item version creation
1 parent d74e672 commit e146109

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

src/app/core/submission/workspaceitem-data.service.spec.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ import {
22
HttpClient,
33
HttpHeaders,
44
} from '@angular/common/http';
5+
import { waitForAsync } from '@angular/core/testing';
56
import { Store } from '@ngrx/store';
67
import {
78
cold,
89
getTestScheduler,
910
hot,
1011
} from 'jasmine-marbles';
11-
import { of as observableOf } from 'rxjs';
12+
import {
13+
of as observableOf,
14+
of,
15+
} from 'rxjs';
16+
import { map } from 'rxjs/operators';
1217
import { TestScheduler } from 'rxjs/testing';
1318

1419
import { getMockHrefOnlyDataService } from '../../shared/mocks/href-only-data.service.mock';
@@ -151,12 +156,17 @@ describe('WorkspaceitemDataService test', () => {
151156
});
152157

153158
describe('findByItem', () => {
154-
it('should proxy the call to UpdateDataServiceImpl.findByHref', () => {
159+
it('should proxy the call to UpdateDataServiceImpl.findByHref', waitForAsync(() => {
155160
scheduler.schedule(() => service.findByItem('1234-1234', true, true, pageInfo));
156161
scheduler.flush();
157-
const searchUrl = service.getIDHref('item', [new RequestParam('uuid', '1234-1234')]);
158-
expect((service as any).findByHref).toHaveBeenCalledWith(searchUrl, true, true);
159-
});
162+
const searchUrl$ =
163+
of('https://rest.api/rest/api/submission/workspaceitems/search/item')
164+
.pipe(map(href => service.buildHrefFromFindOptions(href, { searchParams: [new RequestParam('uuid', '1234-1234')] }, [])));
165+
searchUrl$.subscribe((url) => {
166+
expect(url).toEqual('https://rest.api/rest/api/submission/workspaceitems/search/item?uuid=1234-1234');
167+
});
168+
expect((service as any).findByHref).toHaveBeenCalled();
169+
}));
160170

161171
it('should return a RemoteData<WorkspaceItem> for the search', () => {
162172
const result = service.findByItem('1234-1234', true, true, pageInfo);

src/app/core/submission/workspaceitem-data.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import { WorkspaceItem } from './models/workspaceitem.model';
4343
@Injectable({ providedIn: 'root' })
4444
export class WorkspaceitemDataService extends IdentifiableDataService<WorkspaceItem> implements DeleteData<WorkspaceItem>, SearchData<WorkspaceItem>{
4545
protected linkPath = 'workspaceitems';
46-
protected searchByItemLinkPath = 'item';
46+
protected searchByItemLinkPath = 'workspaceitems/search/item';
4747
private deleteData: DeleteData<WorkspaceItem>;
4848
private searchData: SearchData<WorkspaceItem>;
4949

@@ -91,7 +91,8 @@ export class WorkspaceitemDataService extends IdentifiableDataService<WorkspaceI
9191
public findByItem(uuid: string, useCachedVersionIfAvailable = false, reRequestOnStale = true, options: FindListOptions = {}, ...linksToFollow: FollowLinkConfig<WorkspaceItem>[]): Observable<RemoteData<WorkspaceItem>> {
9292
const findListOptions = new FindListOptions();
9393
findListOptions.searchParams = [new RequestParam('uuid', uuid)];
94-
const href$ = this.getIDHref(this.searchByItemLinkPath, findListOptions, ...linksToFollow);
94+
const href$ = this.halService.getEndpoint(this.searchByItemLinkPath)
95+
.pipe(map((href) => this.buildHrefFromFindOptions(href, findListOptions, [], ...linksToFollow)));
9596
return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
9697
}
9798

0 commit comments

Comments
 (0)