fix tests

This commit is contained in:
FrancescoMolinaro
2023-12-27 13:00:55 +01:00
parent e5cf16c489
commit 5feaa1b5a6
4 changed files with 37 additions and 17 deletions

View File

@@ -21,6 +21,9 @@ import { RequestEntry } from '../data/request-entry.model';
import { CoreState } from '../core-state.model'; import { CoreState } from '../core-state.model';
import { testSearchDataImplementation } from '../data/base/search-data.spec'; import { testSearchDataImplementation } from '../data/base/search-data.spec';
import { testDeleteDataImplementation } from '../data/base/delete-data.spec'; import { testDeleteDataImplementation } from '../data/base/delete-data.spec';
import { SearchData } from '../data/base/search-data';
import { DeleteData } from '../data/base/delete-data';
import { RequestParam } from '../cache/models/request-param.model';
describe('WorkspaceitemDataService test', () => { describe('WorkspaceitemDataService test', () => {
let scheduler: TestScheduler; let scheduler: TestScheduler;
@@ -68,15 +71,12 @@ describe('WorkspaceitemDataService test', () => {
const wsiRD = createSuccessfulRemoteDataObject(wsi); const wsiRD = createSuccessfulRemoteDataObject(wsi);
const endpointURL = `https://rest.api/rest/api/submission/workspaceitems`; const endpointURL = `https://rest.api/rest/api/submission/workspaceitems`;
const searchRequestURL = `https://rest.api/rest/api/submission/workspaceitems/search/item?uuid=1234-1234`;
const searchRequestURL$ = observableOf(searchRequestURL);
const requestUUID = '8b3c613a-5a4b-438b-9686-be1d5b4a1c5a'; const requestUUID = '8b3c613a-5a4b-438b-9686-be1d5b4a1c5a';
objectCache = {} as ObjectCacheService; objectCache = {} as ObjectCacheService;
const notificationsService = {} as NotificationsService; const notificationsService = {} as NotificationsService;
const http = {} as HttpClient; const http = {} as HttpClient;
const comparator = {} as any;
const comparatorEntry = {} as any; const comparatorEntry = {} as any;
const store = {} as Store<CoreState>; const store = {} as Store<CoreState>;
const pageInfo = new PageInfo(); const pageInfo = new PageInfo();
@@ -84,18 +84,23 @@ describe('WorkspaceitemDataService test', () => {
function initTestService() { function initTestService() {
hrefOnlyDataService = getMockHrefOnlyDataService(); hrefOnlyDataService = getMockHrefOnlyDataService();
return new WorkspaceitemDataService( return new WorkspaceitemDataService(
comparatorEntry,
halService,
http,
notificationsService,
requestService, requestService,
rdbService, rdbService,
objectCache, objectCache,
halService, store
notificationsService,
); );
} }
describe('composition', () => { describe('composition', () => {
const initService = () => new WorkspaceitemDataService(null, null, null, null, null); const initSearchService = () => new WorkspaceitemDataService(null, null, null, null, null, null, null, null) as unknown as SearchData<any>;
testSearchDataImplementation(initService); const initDeleteService = () => new WorkspaceitemDataService(null, null, null, null, null, null, null, null) as unknown as DeleteData<any>;
testDeleteDataImplementation(initService);
testSearchDataImplementation(initSearchService);
testDeleteDataImplementation(initDeleteService);
}); });
describe('', () => { describe('', () => {
@@ -126,7 +131,6 @@ describe('WorkspaceitemDataService test', () => {
service = initTestService(); service = initTestService();
spyOn((service as any), 'findByHref').and.callThrough(); spyOn((service as any), 'findByHref').and.callThrough();
spyOn((service as any), 'getSearchByHref').and.returnValue(searchRequestURL$);
}); });
afterEach(() => { afterEach(() => {
@@ -137,8 +141,8 @@ describe('WorkspaceitemDataService test', () => {
it('should proxy the call to DataService.findByHref', () => { it('should proxy the call to DataService.findByHref', () => {
scheduler.schedule(() => service.findByItem('1234-1234', true, true, pageInfo)); scheduler.schedule(() => service.findByItem('1234-1234', true, true, pageInfo));
scheduler.flush(); scheduler.flush();
const searchUrl = service.getIDHref('item', [new RequestParam('uuid', encodeURIComponent('1234-1234'))]);
expect((service as any).findByHref).toHaveBeenCalledWith(searchRequestURL$, true, true); expect((service as any).findByHref).toHaveBeenCalledWith(searchUrl, true, true);
}); });
it('should return a RemoteData<WorkspaceItem> for the search', () => { it('should return a RemoteData<WorkspaceItem> for the search', () => {

View File

@@ -23,16 +23,19 @@ import {hasValue} from '../../shared/empty.util';
import { IdentifiableDataService } from '../data/base/identifiable-data.service'; import { IdentifiableDataService } from '../data/base/identifiable-data.service';
import { NoContent } from '../shared/NoContent.model'; import { NoContent } from '../shared/NoContent.model';
import { DeleteData, DeleteDataImpl } from '../data/base/delete-data'; import { DeleteData, DeleteDataImpl } from '../data/base/delete-data';
import { SearchData, SearchDataImpl } from '../data/base/search-data';
import { PaginatedList } from '../data/paginated-list.model';
/** /**
* A service that provides methods to make REST requests with workspaceitems endpoint. * A service that provides methods to make REST requests with workspaceitems endpoint.
*/ */
@Injectable() @Injectable()
@dataService(WorkspaceItem.type) @dataService(WorkspaceItem.type)
export class WorkspaceitemDataService extends IdentifiableDataService<WorkspaceItem> { export class WorkspaceitemDataService extends IdentifiableDataService<WorkspaceItem> implements DeleteData<WorkspaceItem>, SearchData<WorkspaceItem>{
protected linkPath = 'workspaceitems'; protected linkPath = 'workspaceitems';
protected searchByItemLinkPath = 'item'; protected searchByItemLinkPath = 'item';
private deleteData: DeleteData<WorkspaceItem>; private deleteData: DeleteData<WorkspaceItem>;
private searchData: SearchData<WorkspaceItem>;
constructor( constructor(
protected comparator: DSOChangeAnalyzer<WorkspaceItem>, protected comparator: DSOChangeAnalyzer<WorkspaceItem>,
@@ -45,7 +48,7 @@ export class WorkspaceitemDataService extends IdentifiableDataService<WorkspaceI
protected store: Store<CoreState>) { protected store: Store<CoreState>) {
super('workspaceitems', requestService, rdbService, objectCache, halService); super('workspaceitems', requestService, rdbService, objectCache, halService);
this.deleteData = new DeleteDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive, this.constructIdEndpoint); this.deleteData = new DeleteDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive, this.constructIdEndpoint);
this.searchData = new SearchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
} }
public delete(objectId: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> { public delete(objectId: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> {
return this.deleteData.delete(objectId, copyVirtualMetadata); return this.deleteData.delete(objectId, copyVirtualMetadata);
@@ -93,4 +96,11 @@ export class WorkspaceitemDataService extends IdentifiableDataService<WorkspaceI
return this.rdbService.buildFromRequestUUID(requestId); return this.rdbService.buildFromRequestUUID(requestId);
} }
deleteByHref(href: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> {
return this.deleteData.deleteByHref(href, copyVirtualMetadata);
}
searchBy(searchMethod: string, options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<WorkspaceItem>[]): Observable<RemoteData<PaginatedList<WorkspaceItem>>> {
return this.searchData.searchBy(searchMethod, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}
} }

View File

@@ -13,11 +13,13 @@ import { SuggestionsService } from '../suggestions.service';
describe('SuggestionsPopupComponent', () => { describe('SuggestionsPopupComponent', () => {
let component: SuggestionsPopupComponent; let component: SuggestionsPopupComponent;
let fixture: ComponentFixture<SuggestionsPopupComponent>; let fixture: ComponentFixture<SuggestionsPopupComponent>;
let notificationsService: NotificationsService;
const suggestionStateService = jasmine.createSpyObj('SuggestionTargetsStateService', { const suggestionStateService = jasmine.createSpyObj('SuggestionTargetsStateService', {
hasUserVisitedSuggestions: jasmine.createSpy('hasUserVisitedSuggestions'), hasUserVisitedSuggestions: jasmine.createSpy('hasUserVisitedSuggestions'),
getCurrentUserSuggestionTargets: jasmine.createSpy('getCurrentUserSuggestionTargets'), getCurrentUserSuggestionTargets: jasmine.createSpy('getCurrentUserSuggestionTargets'),
dispatchMarkUserSuggestionsAsVisitedAction: jasmine.createSpy('dispatchMarkUserSuggestionsAsVisitedAction') dispatchMarkUserSuggestionsAsVisitedAction: jasmine.createSpy('dispatchMarkUserSuggestionsAsVisitedAction'),
dispatchRefreshUserSuggestionsAction: jasmine.createSpy('dispatchRefreshUserSuggestionsAction')
}); });
const mockNotificationInterpolation = { count: 12, source: 'source', suggestionId: 'id', displayName: 'displayName' }; const mockNotificationInterpolation = { count: 12, source: 'source', suggestionId: 'id', displayName: 'displayName' };
@@ -60,18 +62,20 @@ describe('SuggestionsPopupComponent', () => {
describe('when there are publication suggestions', () => { describe('when there are publication suggestions', () => {
beforeEach(() => { beforeEach(() => {
suggestionStateService.hasUserVisitedSuggestions.and.returnValue(observableOf(false)); suggestionStateService.hasUserVisitedSuggestions.and.returnValue(observableOf(false));
suggestionStateService.getCurrentUserSuggestionTargets.and.returnValue(observableOf([mockSuggestionTargetsObjectOne])); suggestionStateService.getCurrentUserSuggestionTargets.and.returnValue(observableOf([mockSuggestionTargetsObjectOne]));
suggestionStateService.dispatchMarkUserSuggestionsAsVisitedAction.and.returnValue(observableOf(null)); suggestionStateService.dispatchMarkUserSuggestionsAsVisitedAction.and.returnValue(observableOf(null));
suggestionStateService.dispatchRefreshUserSuggestionsAction.and.returnValue(observableOf(null));
fixture = TestBed.createComponent(SuggestionsPopupComponent); fixture = TestBed.createComponent(SuggestionsPopupComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
notificationsService = (component as any).notificationsService;
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should show a notification when new publication suggestions are available', () => { it('should show a notification when new publication suggestions are available', () => {
expect((component as any).notificationsService.success).toHaveBeenCalled(); expect(notificationsService.success).toHaveBeenCalled();
expect(suggestionStateService.dispatchRefreshUserSuggestionsAction).toHaveBeenCalled();
expect(suggestionStateService.dispatchMarkUserSuggestionsAsVisitedAction).toHaveBeenCalled(); expect(suggestionStateService.dispatchMarkUserSuggestionsAsVisitedAction).toHaveBeenCalled();
}); });

View File

@@ -319,5 +319,7 @@ export const environment: BuildConfig = {
vocabulary: 'srsc', vocabulary: 'srsc',
enabled: true enabled: true
} }
] ],
suggestion: []
}; };