Skip to content

Commit

Permalink
Merge pull request #1934 from TexasDigitalLibrary/DS-1905
Browse files Browse the repository at this point in the history
DS-1905: fixes route function to match default value of websvc.opensearch.svccontext
  • Loading branch information
tdonohue authored Nov 3, 2022
2 parents b092d0b + 63011bc commit 749e1a7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
16 changes: 6 additions & 10 deletions src/app/shared/rss-feed/rss.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
import { RemoteData } from '../../core/data/remote-data';
import { GroupDataService } from '../../core/eperson/group-data.service';
Expand All @@ -23,7 +22,6 @@ import { RouterMock } from '../mocks/router.mock';

describe('RssComponent', () => {
let comp: RSSComponent;
let options: SortOptions;
let fixture: ComponentFixture<RSSComponent>;
let uuid: string;
let query: string;
Expand Down Expand Up @@ -63,7 +61,6 @@ describe('RssComponent', () => {
pageSize: 10,
currentPage: 1
}),
sort: new SortOptions('dc.title', SortDirection.ASC),
}));
groupDataService = jasmine.createSpyObj('groupsDataService', {
findListByHref: createSuccessfulRemoteDataObject$(createPaginatedList([])),
Expand All @@ -88,26 +85,25 @@ describe('RssComponent', () => {
}));

beforeEach(() => {
options = new SortOptions('dc.title', SortDirection.DESC);
uuid = '2cfcf65e-0a51-4bcb-8592-b8db7b064790';
query = 'test';
fixture = TestBed.createComponent(RSSComponent);
comp = fixture.componentInstance;
});

it('should formulate the correct url given params in url', () => {
const route = comp.formulateRoute(uuid, 'opensearch', options, query);
expect(route).toBe('/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&sort=dc.title&sort_direction=DESC&query=test');
const route = comp.formulateRoute(uuid, 'opensearch/search', query);
expect(route).toBe('/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&query=test');
});

it('should skip uuid if its null', () => {
const route = comp.formulateRoute(null, 'opensearch', options, query);
expect(route).toBe('/opensearch/search?format=atom&sort=dc.title&sort_direction=DESC&query=test');
const route = comp.formulateRoute(null, 'opensearch/search', query);
expect(route).toBe('/opensearch/search?format=atom&query=test');
});

it('should default to query * if none provided', () => {
const route = comp.formulateRoute(null, 'opensearch', options, null);
expect(route).toBe('/opensearch/search?format=atom&sort=dc.title&sort_direction=DESC&query=*');
const route = comp.formulateRoute(null, 'opensearch/search', null);
expect(route).toBe('/opensearch/search?format=atom&query=*');
});
});

14 changes: 4 additions & 10 deletions src/app/shared/rss-feed/rss.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { ConfigurationDataService } from '../../core/data/configuration-data.ser
import { getFirstCompletedRemoteData } from '../../core/shared/operators';
import { environment } from '../../../../src/environments/environment';
import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service';
import { SortOptions } from '../../core/cache/models/sort-options.model';
import { PaginationService } from '../../core/pagination/pagination.service';
import { Router } from '@angular/router';
import { map, switchMap } from 'rxjs/operators';
Expand All @@ -39,7 +38,6 @@ export class RSSComponent implements OnInit, OnDestroy {

uuid: string;
configuration$: Observable<string>;
sortOption$: Observable<SortOptions>;

subs: Subscription[] = [];

Expand Down Expand Up @@ -93,7 +91,7 @@ export class RSSComponent implements OnInit, OnDestroy {
return null;
}
this.uuid = this.groupDataService.getUUIDFromString(this.router.url);
const route = environment.rest.baseUrl + this.formulateRoute(this.uuid, openSearchUri, searchOptions.sort, searchOptions.query);
const route = environment.rest.baseUrl + this.formulateRoute(this.uuid, openSearchUri, searchOptions.query);
this.addLinks(route);
this.linkHeadService.addTag({
href: environment.rest.baseUrl + '/' + openSearchUri + '/service',
Expand All @@ -109,24 +107,20 @@ export class RSSComponent implements OnInit, OnDestroy {
* Function created a route given the different params available to opensearch
* @param uuid The uuid if a scope is present
* @param opensearch openSearch uri
* @param sort The sort options for the opensearch request
* @param query The query string that was provided in the search
* @returns The combine URL to opensearch
*/
formulateRoute(uuid: string, opensearch: string, sort: SortOptions, query: string): string {
let route = 'search?format=atom';
formulateRoute(uuid: string, opensearch: string, query: string): string {
let route = '?format=atom';
if (uuid) {
route += `&scope=${uuid}`;
}
if (sort && sort.direction && sort.field && sort.field !== 'id') {
route += `&sort=${sort.field}&sort_direction=${sort.direction}`;
}
if (query) {
route += `&query=${query}`;
} else {
route += `&query=*`;
}
route = '/' + opensearch + '/' + route;
route = '/' + opensearch + route;
return route;
}

Expand Down

0 comments on commit 749e1a7

Please sign in to comment.