[CST-3088] Removed metadata and collection params when making vocabulary requests

This commit is contained in:
Giuseppe Digilio
2020-07-16 13:13:24 +02:00
parent a283476403
commit c33a63aa90
3 changed files with 43 additions and 37 deletions

View File

@@ -8,9 +8,7 @@ import { isNotEmpty } from '../../../../shared/empty.util';
*/
export class VocabularyFindOptions extends FindListOptions {
constructor(public collection,
public metadata,
public query: string = '',
constructor(public query: string = '',
public filter?: string,
public exact?: boolean,
public entryID?: string,
@@ -21,12 +19,7 @@ export class VocabularyFindOptions extends FindListOptions {
super();
const searchParams = [];
if (isNotEmpty(metadata)) {
searchParams.push(new RequestParam('metadata', metadata))
}
if (isNotEmpty(collection)) {
searchParams.push(new RequestParam('collection', collection))
}
if (isNotEmpty(query)) {
searchParams.push(new RequestParam('query', query))
}

View File

@@ -13,7 +13,7 @@ import { VocabularyEntriesRequest } from '../../data/request.models';
import { RequestParam } from '../../cache/models/request-param.model';
import { PageInfo } from '../../shared/page-info.model';
import { PaginatedList } from '../../data/paginated-list';
import { createSuccessfulRemoteDataObject } from '../../../shared/remote-data.utils';
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
import { RequestEntry } from '../../data/request.reducer';
import { RestResponse } from '../../cache/response.models';
import { VocabularyService } from './vocabulary.service';
@@ -67,6 +67,27 @@ describe('VocabularyService', () => {
}
};
const vocabularyEntry: any = {
display: 'testValue1',
value: 'testValue1',
otherInformation: {},
type: 'vocabularyEntry'
};
const vocabularyEntry2: any = {
display: 'testValue2',
value: 'testValue2',
otherInformation: {},
type: 'vocabularyEntry'
};
const vocabularyEntry3: any = {
display: 'testValue3',
value: 'testValue3',
otherInformation: {},
type: 'vocabularyEntry'
};
const vocabularyEntryParentDetail: any = {
authority: 'authorityId2',
display: 'testParent',
@@ -148,10 +169,10 @@ describe('VocabularyService', () => {
const collectionUUID = '8b39g7ya-5a4b-438b-851f-be1d5b4a1c5a';
const entryID = 'dsfsfsdf-5a4b-438b-851f-be1d5b4a1c5a';
const searchRequestURL = `https://rest.api/rest/api/submission/vocabularies/search/byMetadataAndCollection?metadata=${metadata}&collection=${collectionUUID}`;
const entriesRequestURL = `https://rest.api/rest/api/submission/vocabularies/${vocabulary.id}/entries?metadata=${metadata}&collection=${collectionUUID}`;
const entriesByValueRequestURL = `https://rest.api/rest/api/submission/vocabularies/${vocabulary.id}/entries?metadata=${metadata}&collection=${collectionUUID}&filter=test&exact=false`;
const entryByValueRequestURL = `https://rest.api/rest/api/submission/vocabularies/${vocabulary.id}/entries?metadata=${metadata}&collection=${collectionUUID}&filter=test&exact=true`;
const entryByIDRequestURL = `https://rest.api/rest/api/submission/vocabularies/${vocabulary.id}/entries?metadata=${metadata}&collection=${collectionUUID}&entryID=${entryID}`;
const entriesRequestURL = `https://rest.api/rest/api/submission/vocabularies/${vocabulary.id}/entries`;
const entriesByValueRequestURL = `https://rest.api/rest/api/submission/vocabularies/${vocabulary.id}/entries?filter=test&exact=false`;
const entryByValueRequestURL = `https://rest.api/rest/api/submission/vocabularies/${vocabulary.id}/entries?filter=test&exact=true`;
const entryByIDRequestURL = `https://rest.api/rest/api/submission/vocabularies/${vocabulary.id}/entries?entryID=${entryID}`;
const vocabularyOptions: VocabularyOptions = {
name: vocabularyId,
metadata: metadata,
@@ -160,16 +181,19 @@ describe('VocabularyService', () => {
}
const pageInfo = new PageInfo();
const array = [vocabulary, hierarchicalVocabulary];
const arrayEntries = [vocabularyEntry, vocabularyEntry2, vocabularyEntry3];
const childrenEntries = [vocabularyEntryChildDetail, vocabularyEntryChild2Detail];
const paginatedList = new PaginatedList(pageInfo, array);
const paginatedListEntries = new PaginatedList(pageInfo, arrayEntries);
const childrenPaginatedList = new PaginatedList(pageInfo, childrenEntries);
const vocabularyRD = createSuccessfulRemoteDataObject(vocabulary);
const vocabularyEntriesRD = createSuccessfulRemoteDataObject$(paginatedListEntries);
const vocabularyEntryDetailParentRD = createSuccessfulRemoteDataObject(vocabularyEntryParentDetail);
const vocabularyEntryChildrenRD = createSuccessfulRemoteDataObject(childrenPaginatedList);
const paginatedListRD = createSuccessfulRemoteDataObject(paginatedList);
const getRequestEntry$ = (successful: boolean) => {
const getRequestEntries$ = (successful: boolean) => {
return observableOf({
response: { isSuccessful: successful, payload: vocabulary } as any
response: { isSuccessful: successful, payload: arrayEntries } as any
} as RequestEntry)
};
objectCache = {} as ObjectCacheService;
@@ -312,8 +336,8 @@ describe('VocabularyService', () => {
describe('', () => {
beforeEach(() => {
requestService = getMockRequestService(getRequestEntry$(true));
rdbService = getMockRemoteDataBuildService();
requestService = getMockRequestService(getRequestEntries$(true));
rdbService = getMockRemoteDataBuildService(undefined, vocabularyEntriesRD);
spyOn(rdbService, 'toRemoteDataObservable').and.callThrough();
service = initTestService();
});
@@ -329,10 +353,10 @@ describe('VocabularyService', () => {
});
it('should call RemoteDataBuildService to create the RemoteData Observable', () => {
service.getVocabularyEntries(vocabularyOptions, pageInfo);
scheduler.schedule(() => service.getVocabularyEntries(vocabularyOptions, pageInfo));
scheduler.flush();
expect(rdbService.toRemoteDataObservable).toHaveBeenCalled();
});
});
@@ -347,7 +371,8 @@ describe('VocabularyService', () => {
});
it('should call RemoteDataBuildService to create the RemoteData Observable', () => {
service.getVocabularyEntriesByValue('test', false, vocabularyOptions, pageInfo);
scheduler.schedule(() => service.getVocabularyEntriesByValue('test', false, vocabularyOptions, pageInfo));
scheduler.flush();
expect(rdbService.toRemoteDataObservable).toHaveBeenCalled();
@@ -365,7 +390,8 @@ describe('VocabularyService', () => {
});
it('should call RemoteDataBuildService to create the RemoteData Observable', () => {
service.getVocabularyEntryByValue('test', vocabularyOptions);
scheduler.schedule(() => service.getVocabularyEntryByValue('test', vocabularyOptions));
scheduler.flush();
expect(rdbService.toRemoteDataObservable).toHaveBeenCalled();
@@ -383,7 +409,8 @@ describe('VocabularyService', () => {
});
it('should call RemoteDataBuildService to create the RemoteData Observable', () => {
service.getVocabularyEntryByID('test', vocabularyOptions);
scheduler.schedule(() => service.getVocabularyEntryByID('test', vocabularyOptions));
scheduler.flush();
expect(rdbService.toRemoteDataObservable).toHaveBeenCalled();
@@ -495,8 +522,6 @@ describe('VocabularyService', () => {
null,
null,
null,
null,
null,
pageInfo.elementsPerPage,
pageInfo.currentPage
);
@@ -522,8 +547,6 @@ describe('VocabularyService', () => {
null,
null,
null,
null,
null,
pageInfo.elementsPerPage,
pageInfo.currentPage
);

View File

@@ -150,8 +150,6 @@ export class VocabularyService {
getVocabularyEntries(vocabularyOptions: VocabularyOptions, pageInfo: PageInfo): Observable<RemoteData<PaginatedList<VocabularyEntry>>> {
const options: VocabularyFindOptions = new VocabularyFindOptions(
vocabularyOptions.scope,
vocabularyOptions.metadata,
null,
null,
null,
@@ -179,8 +177,6 @@ export class VocabularyService {
*/
getVocabularyEntriesByValue(value: string, exact: boolean, vocabularyOptions: VocabularyOptions, pageInfo: PageInfo): Observable<RemoteData<PaginatedList<VocabularyEntry>>> {
const options: VocabularyFindOptions = new VocabularyFindOptions(
vocabularyOptions.scope,
vocabularyOptions.metadata,
null,
value,
exact,
@@ -229,8 +225,6 @@ export class VocabularyService {
getVocabularyEntryByID(ID: string, vocabularyOptions: VocabularyOptions): Observable<VocabularyEntry> {
const pageInfo = new PageInfo()
const options: VocabularyFindOptions = new VocabularyFindOptions(
vocabularyOptions.scope,
vocabularyOptions.metadata,
null,
null,
null,
@@ -335,8 +329,6 @@ export class VocabularyService {
null,
null,
null,
null,
null,
pageInfo.elementsPerPage,
pageInfo.currentPage
);
@@ -358,8 +350,6 @@ export class VocabularyService {
null,
null,
null,
null,
null,
pageInfo.elementsPerPage,
pageInfo.currentPage
);