Skip to content

Commit efc488a

Browse files
[DURACOM-426] fix tests
1 parent 995ff87 commit efc488a

32 files changed

Lines changed: 231 additions & 105 deletions

src/app/core/json-patch/builder/json-patch-operations-builder.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import {
2424
NewPatchReplaceOperationAction,
2525
} from '../json-patch-operations.actions';
2626
import { JsonPatchOperationPathObject } from './json-patch-operation-path-combiner';
27-
import { Metadata } from "@dspace/core/shared/metadata.utils";
28-
import { ConfidenceType } from "@dspace/core/shared/confidence-type";
2927

3028
/**
3129
* Provides methods to dispatch JsonPatch Operations Actions

src/app/core/shared/form/models/form-field-metadata-value.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
MetadataValueInterface,
1111
VIRTUAL_METADATA_PREFIX,
1212
} from '../../metadata.models';
13+
import { Metadata } from '../../metadata.utils';
1314
import { PLACEHOLDER_PARENT_METADATA } from '../ds-dynamic-form-constants';
14-
import { Metadata } from "../../metadata.utils";
1515

1616
export interface OtherInformation {
1717
[name: string]: string;

src/app/core/submission/vocabularies/models/vocabulary-entry-detail.model.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
import { link, typedObject } from '@dspace/core/cache/builders/build-decorators';
1+
import {
2+
link,
3+
typedObject,
4+
} from '@dspace/core/cache/builders/build-decorators';
5+
import { PaginatedList } from '@dspace/core/data/paginated-list.model';
6+
import { RemoteData } from '@dspace/core/data/remote-data';
27
import { HALLink } from '@dspace/core/shared/hal-link.model';
38
import {
49
autoserialize,
510
deserialize,
611
inheritSerialization,
712
} from 'cerialize';
13+
import { Observable } from 'rxjs';
814

915
import { VOCABULARY_ENTRY_DETAIL } from './vocabularies.resource-type';
1016
import { VocabularyEntry } from './vocabulary-entry.model';
11-
import { Observable } from "rxjs";
12-
import { RemoteData } from "@dspace/core/data/remote-data";
13-
import { PaginatedList } from "@dspace/core/data/paginated-list.model";
1417

1518
/**
1619
* Model class for a VocabularyEntryDetail

src/app/core/submission/vocabularies/models/vocabulary-entry.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { typedObject } from '@dspace/core/cache/builders/build-decorators';
22
import { GenericConstructor } from '@dspace/core/shared/generic-constructor';
33
import { HALLink } from '@dspace/core/shared/hal-link.model';
4+
import { Metadata } from '@dspace/core/shared/metadata.utils';
45
import { excludeFromEquals } from '@dspace/core/utilities/equals.decorators';
56
import { isNotEmpty } from '@dspace/shared/utils/empty.util';
67
import {
@@ -12,7 +13,6 @@ import { PLACEHOLDER_PARENT_METADATA } from '../../../shared/form/ds-dynamic-for
1213
import { OtherInformation } from '../../../shared/form/models/form-field-metadata-value.model';
1314
import { ListableObject } from '../../../shared/object-collection/listable-object.model';
1415
import { VOCABULARY_ENTRY } from './vocabularies.resource-type';
15-
import { Metadata } from "@dspace/core/shared/metadata.utils";
1616

1717
/**
1818
* Model class for a VocabularyEntry

src/app/core/submission/vocabularies/models/vocabulary.model.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
VOCABULARY_ENTRY,
1919
} from './vocabularies.resource-type';
2020
import { VocabularyEntry } from './vocabulary-entry.model';
21-
import { isNotEmpty } from "@dspace/shared/utils/empty.util";
2221

2322
export interface VocabularyExternalSourceMap {
2423
[metadata: string]: string;
@@ -66,14 +65,7 @@ export class Vocabulary implements CacheableObject {
6665
* this vocabulary
6766
*/
6867
@autoserialize
69-
entity: string;
70-
71-
/**
72-
* If available represent that this vocabulary can be use to create a new entity
73-
*/
74-
@autoserialize
75-
externalSource: VocabularyExternalSourceMap;
76-
68+
entity: string;
7769

7870
/**
7971
* A boolean variable that indicates whether the functionality of
@@ -100,13 +92,4 @@ export class Vocabulary implements CacheableObject {
10092
self: HALLink,
10193
entries: HALLink
10294
};
103-
104-
public getExternalSourceByMetadata(metadata): string {
105-
let sourceIdentifier = null;
106-
if (isNotEmpty(this.externalSource) && this.externalSource.hasOwnProperty(metadata)) {
107-
sourceIdentifier = this.externalSource[metadata];
108-
}
109-
110-
return sourceIdentifier;
111-
}
11295
}

src/app/core/submission/vocabularies/vocabulary.data.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import {
1616
FindAllDataImpl,
1717
} from '../../data/base/find-all-data';
1818
import { IdentifiableDataService } from '../../data/base/identifiable-data.service';
19-
import { SearchData, SearchDataImpl } from '../../data/base/search-data';
19+
import {
20+
SearchData,
21+
SearchDataImpl,
22+
} from '../../data/base/search-data';
2023
import { FindListOptions } from '../../data/find-list-options.model';
2124
import { PaginatedList } from '../../data/paginated-list.model';
2225
import { RemoteData } from '../../data/remote-data';

src/app/core/submission/vocabularies/vocabulary.service.spec.ts

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,33 @@ describe('VocabularyService', () => {
100100
type: 'vocabularyEntry',
101101
};
102102

103+
const entryDetailRequestURL = `https://rest.api/rest/api/submission/vocabularyEntryDetails/${hierarchicalVocabulary.id}:testValue`;
104+
const entryDetailParentRequestURL = `https://rest.api/rest/api/submission/vocabularyEntryDetails/${hierarchicalVocabulary.id}:testValue/parent`;
105+
const entryDetailChildrenRequestURL = `https://rest.api/rest/api/submission/vocabularyEntryDetails/${hierarchicalVocabulary.id}:testValue/children`;
106+
107+
const vocabularyEntryDetail: any = {
108+
authority: 'authorityId',
109+
display: 'test',
110+
value: 'test',
111+
otherInformation: {
112+
id: 'authorityId',
113+
hasChildren: 'true',
114+
note: 'Familjeforskning',
115+
},
116+
type: 'vocabularyEntryDetail',
117+
_links: {
118+
self: {
119+
href: entryDetailRequestURL,
120+
},
121+
parent: {
122+
href: entryDetailParentRequestURL,
123+
},
124+
children: {
125+
href: entryDetailChildrenRequestURL,
126+
},
127+
},
128+
};
129+
103130
const vocabularyEntryParentDetail: any = {
104131
authority: 'authorityId2',
105132
display: 'testParent',
@@ -172,9 +199,7 @@ describe('VocabularyService', () => {
172199
const endpointURL = `https://rest.api/rest/api/submission/vocabularies`;
173200
const requestURL = `https://rest.api/rest/api/submission/vocabularies/${vocabulary.id}`;
174201
const entryDetailEndpointURL = `https://rest.api/rest/api/submission/vocabularyEntryDetails`;
175-
const entryDetailRequestURL = `https://rest.api/rest/api/submission/vocabularyEntryDetails/${hierarchicalVocabulary.id}:testValue`;
176-
const entryDetailParentRequestURL = `https://rest.api/rest/api/submission/vocabularyEntryDetails/${hierarchicalVocabulary.id}:testValue/parent`;
177-
const entryDetailChildrenRequestURL = `https://rest.api/rest/api/submission/vocabularyEntryDetails/${hierarchicalVocabulary.id}:testValue/children`;
202+
178203
const requestUUID = '8b3c613a-5a4b-438b-9686-be1d5b4a1c5a';
179204
const vocabularyId = 'types';
180205
const metadata = 'dc.type';
@@ -187,6 +212,8 @@ describe('VocabularyService', () => {
187212
const entryByIDRequestURL = `https://rest.api/rest/api/submission/vocabularies/${vocabulary.id}/entries?entryID=${entryID}`;
188213
const vocabularyOptions: VocabularyOptions = {
189214
name: vocabularyId,
215+
metadata: metadata,
216+
scope: collectionUUID,
190217
closed: false,
191218
};
192219
const pageInfo = new PageInfo();
@@ -199,6 +226,7 @@ describe('VocabularyService', () => {
199226
const vocabularyRD = createSuccessfulRemoteDataObject(vocabulary);
200227
const vocabularyRD$ = createSuccessfulRemoteDataObject$(vocabulary);
201228
const vocabularyEntriesRD = createSuccessfulRemoteDataObject$(paginatedListEntries);
229+
const vocabularyEntryDetailRD$ = createSuccessfulRemoteDataObject$(vocabularyEntryDetail);
202230
const vocabularyEntryDetailParentRD = createSuccessfulRemoteDataObject(vocabularyEntryParentDetail);
203231
const vocabularyEntryChildrenRD = createSuccessfulRemoteDataObject(childrenPaginatedList);
204232
const paginatedListRD = createSuccessfulRemoteDataObject(paginatedList);
@@ -244,6 +272,7 @@ describe('VocabularyService', () => {
244272
removeByHrefSubstring: {},
245273
getByHref: of(responseCacheEntry),
246274
getByUUID: of(responseCacheEntry),
275+
setStaleByHrefSubstring: jasmine.createSpy('setStaleByHrefSubstring'),
247276
});
248277
rdbService = jasmine.createSpyObj('rdbService', {
249278
buildSingle: hot('a|', {
@@ -252,6 +281,7 @@ describe('VocabularyService', () => {
252281
buildList: hot('a|', {
253282
a: paginatedListRD,
254283
}),
284+
setStaleByHrefSubstring: jasmine.createSpy('setStaleByHrefSubstring'),
255285
});
256286

257287
service = initTestService();
@@ -335,6 +365,24 @@ describe('VocabularyService', () => {
335365
expect(result).toBeObservable(expected);
336366
});
337367
});
368+
369+
describe('searchVocabularyByMetadataAndCollection', () => {
370+
it('should proxy the call to vocabularyDataService.findVocabularyByHref', () => {
371+
scheduler.schedule(() => service.searchVocabularyByMetadataAndCollection(vocabularyOptions).subscribe());
372+
scheduler.flush();
373+
374+
expect((service as any).vocabularyDataService.findByHref).toHaveBeenCalledWith(searchRequestURL);
375+
});
376+
377+
it('should return a RemoteData<Vocabulary> for the search', () => {
378+
const result = service.searchVocabularyByMetadataAndCollection(vocabularyOptions);
379+
const expected = cold('a|', {
380+
a: vocabularyRD,
381+
});
382+
expect(result).toBeObservable(expected);
383+
});
384+
385+
});
338386
});
339387

340388
describe('vocabulary entries', () => {
@@ -429,6 +477,7 @@ describe('VocabularyService', () => {
429477
removeByHrefSubstring: {},
430478
getByHref: of(responseCacheEntry),
431479
getByUUID: of(responseCacheEntry),
480+
setStaleByHrefSubstring: jasmine.createSpy('setStaleByHrefSubstring'),
432481
});
433482
rdbService = jasmine.createSpyObj('rdbService', {
434483
buildSingle: hot('a|', {
@@ -490,6 +539,10 @@ describe('VocabularyService', () => {
490539
});
491540

492541
describe('getEntryDetailParent', () => {
542+
beforeEach(() => {
543+
(service as any).vocabularyEntryDetailDataService.findById.and.returnValue(vocabularyEntryDetailRD$);
544+
});
545+
493546
it('should proxy the call to vocabularyDataService.getEntryDetailParent', () => {
494547
scheduler.schedule(() => service.getEntryDetailParent('testValue', hierarchicalVocabulary.id).subscribe());
495548
scheduler.flush();
@@ -507,12 +560,18 @@ describe('VocabularyService', () => {
507560
});
508561

509562
describe('getEntryDetailChildren', () => {
563+
beforeEach(() => {
564+
(service as any).vocabularyEntryDetailDataService.findById.and.returnValue(vocabularyEntryDetailRD$);
565+
});
566+
510567
it('should proxy the call to vocabularyDataService.getEntryDetailChildren', () => {
511568
const options: VocabularyFindOptions = new VocabularyFindOptions(
512569
null,
513570
null,
514571
null,
515572
null,
573+
null,
574+
null,
516575
pageInfo.elementsPerPage,
517576
pageInfo.currentPage,
518577
);
@@ -538,6 +597,8 @@ describe('VocabularyService', () => {
538597
null,
539598
null,
540599
null,
600+
null,
601+
null,
541602
pageInfo.elementsPerPage,
542603
pageInfo.currentPage,
543604
);
@@ -562,7 +623,7 @@ describe('VocabularyService', () => {
562623
it('should remove requests on the data service\'s endpoint', (done) => {
563624
service.clearSearchTopRequests();
564625

565-
expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith(`search/${(service as any).searchTopMethod}`);
626+
expect(requestService.setStaleByHrefSubstring).toHaveBeenCalledWith(`search/${(service as any).searchTopMethod}`);
566627
done();
567628
});
568629
});

src/app/core/submission/vocabularies/vocabulary.service.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { Injectable } from '@angular/core';
2-
import { hasValue, isNotEmpty } from '@dspace/shared/utils/empty.util';
3-
import { Observable, of } from 'rxjs';
2+
import { createFailedRemoteDataObject } from '@dspace/core/utilities/remote-data.utils';
3+
import {
4+
hasValue,
5+
isNotEmpty,
6+
} from '@dspace/shared/utils/empty.util';
7+
import {
8+
Observable,
9+
of,
10+
} from 'rxjs';
411
import {
512
first,
613
map,
@@ -30,7 +37,6 @@ import { VocabularyFindOptions } from './models/vocabulary-find-options.model';
3037
import { VocabularyOptions } from './models/vocabulary-options.model';
3138
import { VocabularyDataService } from './vocabulary.data.service';
3239
import { VocabularyEntryDetailsDataService } from './vocabulary-entry-details.data.service';
33-
import { createFailedRemoteDataObject } from "@dspace/core/utilities/remote-data.utils";
3440

3541
/**
3642
* A service responsible for fetching/sending data from/to the REST API on the vocabularies endpoint

src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-authority-field/dso-edit-metadata-authority-field.component.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from '@angular/core/testing';
66
import { By } from '@angular/platform-browser';
77
import { ItemDataService } from '@dspace/core/data/item-data.service';
8+
import { APP_DATA_SERVICES_MAP } from '@dspace/core/data-services-map-type';
89
import { MetadataField } from '@dspace/core/metadata/metadata-field.model';
910
import { MetadataSchema } from '@dspace/core/metadata/metadata-schema.model';
1011
import { NotificationsService } from '@dspace/core/notification-system/notifications.service';
@@ -15,15 +16,19 @@ import { Item } from '@dspace/core/shared/item.model';
1516
import { MetadataValue } from '@dspace/core/shared/metadata.models';
1617
import { Vocabulary } from '@dspace/core/submission/vocabularies/models/vocabulary.model';
1718
import { VocabularyService } from '@dspace/core/submission/vocabularies/vocabulary.service';
19+
import { SubmissionServiceStub } from '@dspace/core/testing/submission-service.stub';
1820
import { createPaginatedList } from '@dspace/core/testing/utils.test';
1921
import { VocabularyServiceStub } from '@dspace/core/testing/vocabulary-service.stub';
2022
import { createSuccessfulRemoteDataObject$ } from '@dspace/core/utilities/remote-data.utils';
23+
import { provideMockStore } from '@ngrx/store/testing';
2124
import { TranslateModule } from '@ngx-translate/core';
2225

2326
import { RegistryService } from '../../../../admin/admin-registries/registry/registry.service';
2427
import { DynamicOneboxModel } from '../../../../shared/form/builder/ds-dynamic-form-ui/models/onebox/dynamic-onebox.model';
2528
import { DsDynamicScrollableDropdownComponent } from '../../../../shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component';
2629
import { DynamicScrollableDropdownModel } from '../../../../shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.model';
30+
import { FormBuilderService } from '../../../../shared/form/builder/form-builder.service';
31+
import { SubmissionService } from '../../../../submission/submission.service';
2732
import { DsoEditMetadataValue } from '../../dso-edit-metadata-form';
2833
import { DsoEditMetadataAuthorityFieldComponent } from './dso-edit-metadata-authority-field.component';
2934

@@ -57,6 +62,8 @@ describe('DsoEditMetadataAuthorityFieldComponent', () => {
5762
scrollable: true,
5863
hierarchical: false,
5964
preloadLevel: 0,
65+
entity: 'Person',
66+
multiValueOnGenerator: false,
6067
type: 'vocabulary',
6168
_links: {
6269
self: {
@@ -75,6 +82,8 @@ describe('DsoEditMetadataAuthorityFieldComponent', () => {
7582
hierarchical: true,
7683
preloadLevel: 2,
7784
type: 'vocabulary',
85+
entity: 'Publication',
86+
multiValueOnGenerator: false,
7887
_links: {
7988
self: {
8089
href: 'self',
@@ -91,6 +100,8 @@ describe('DsoEditMetadataAuthorityFieldComponent', () => {
91100
scrollable: false,
92101
hierarchical: false,
93102
preloadLevel: 0,
103+
entity: 'Person',
104+
multiValueOnGenerator: false,
94105
type: 'vocabulary',
95106
_links: {
96107
self: {
@@ -153,6 +164,10 @@ describe('DsoEditMetadataAuthorityFieldComponent', () => {
153164
{ provide: ItemDataService, useValue: itemService },
154165
{ provide: RegistryService, useValue: registryService },
155166
{ provide: NotificationsService, useValue: notificationsService },
167+
{ provide: FormBuilderService },
168+
{ provide: SubmissionService, useClass: SubmissionServiceStub },
169+
{ provide: APP_DATA_SERVICES_MAP, useValue: {} },
170+
provideMockStore({ initialState: { core: { index: { } } } }),
156171
],
157172
}).overrideComponent(DsoEditMetadataAuthorityFieldComponent, {
158173
remove: {

src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ describe('DsDynamicFormControlContainerComponent test suite', () => {
105105

106106
const vocabularyOptions: VocabularyOptions = {
107107
name: 'type_programme',
108+
metadata: null,
109+
scope: null,
108110
closed: false,
109111
};
110112
const formModel = [

0 commit comments

Comments
 (0)