"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/app/core/data/version-history-data.service.spec.ts" between
dspace-angular-dspace-7.0.tar.gz and dspace-angular-dspace-7.1.tar.gz

About: dspace-angular is the Angular-based frontend of DSpace, a digital repository system to capture, store, index, preserve and redistribute an organization’s research material in digital formats.

version-history-data.service.spec.ts  (dspace-angular-dspace-7.0):version-history-data.service.spec.ts  (dspace-angular-dspace-7.1)
import { RequestService } from './request.service'; import { RequestService } from './request.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.serv ice'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.serv ice';
import { ObjectCacheService } from '../cache/object-cache.service'; import { ObjectCacheService } from '../cache/object-cache.service';
import { VersionHistoryDataService } from './version-history-data.service'; import { VersionHistoryDataService } from './version-history-data.service';
import { NotificationsServiceStub } from '../../shared/testing/notifications-ser vice.stub'; import { NotificationsServiceStub } from '../../shared/testing/notifications-ser vice.stub';
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-servic e.stub'; import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-servic e.stub';
import { getMockRequestService } from '../../shared/mocks/request.service.mock'; import { getMockRequestService } from '../../shared/mocks/request.service.mock';
import { VersionDataService } from './version-data.service'; import { VersionDataService } from './version-data.service';
import { fakeAsync, waitForAsync } from '@angular/core/testing';
import { VersionHistory } from '../shared/version-history.model';
import { Version } from '../shared/version.model';
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.util
s';
import { createPaginatedList } from '../../shared/testing/utils.test';
import { Item } from '../shared/item.model';
import { of } from 'rxjs';
import SpyObj = jasmine.SpyObj;
const url = 'fake-url'; const url = 'fake-url';
describe('VersionHistoryDataService', () => { describe('VersionHistoryDataService', () => {
let service: VersionHistoryDataService; let service: VersionHistoryDataService;
let requestService: RequestService; let requestService: RequestService;
let notificationsService: any; let notificationsService: any;
let rdbService: RemoteDataBuildService; let rdbService: RemoteDataBuildService;
let objectCache: ObjectCacheService; let objectCache: ObjectCacheService;
let versionService: VersionDataService; let versionService: SpyObj<VersionDataService>;
let halService: any; let halService: any;
beforeEach(() => { const versionHistoryId = 'version-history-id';
createService(); const versionHistoryDraftId = 'version-history-draft-id';
const version1Id = 'version-1-id';
const version2Id = 'version-1-id';
const item1Uuid = 'item-1-uuid';
const item2Uuid = 'item-2-uuid';
const versionHistory = Object.assign(new VersionHistory(), {
id: versionHistoryId,
draftVersion: false,
}); });
const versionHistoryDraft = Object.assign(new VersionHistory(), {
describe('getVersions', () => { id: versionHistoryDraftId,
let result; draftVersion: true,
});
beforeEach(() => { const version1 = Object.assign(new Version(), {
result = service.getVersions('1'); id: version1Id,
}); version: 1,
created: new Date(2020, 1, 1),
it('should call versionService.findAllByHref', () => { summary: 'first version',
expect(versionService.findAllByHref).toHaveBeenCalled(); versionhistory: createSuccessfulRemoteDataObject$(versionHistory),
}); _links: {
self: {
href: 'version1-url',
},
},
}); });
const version2 = Object.assign(new Version(), {
id: version2Id,
version: 2,
summary: 'second version',
created: new Date(2020, 1, 2),
versionhistory: createSuccessfulRemoteDataObject$(versionHistory),
_links: {
self: {
href: 'version2-url',
},
},
});
const versions = [version1, version2];
versionHistory.versions = createSuccessfulRemoteDataObject$(createPaginatedLis
t(versions));
const item1 = Object.assign(new Item(), {
uuid: item1Uuid,
handle: '123456789/1',
version: createSuccessfulRemoteDataObject$(version1),
_links: {
self: {
href: '/items/' + item2Uuid,
}
}
});
const item2 = Object.assign(new Item(), {
uuid: item2Uuid,
handle: '123456789/2',
version: createSuccessfulRemoteDataObject$(version2),
_links: {
self: {
href: '/items/' + item2Uuid,
}
}
});
const items = [item1, item2];
version1.item = createSuccessfulRemoteDataObject$(item1);
version2.item = createSuccessfulRemoteDataObject$(item2);
/** /**
* Create a VersionHistoryDataService used for testing * Create a VersionHistoryDataService used for testing
* @param requestEntry$ Supply a requestEntry to be returned by the REST API (optional) * @param requestEntry$ Supply a requestEntry to be returned by the REST API (optional)
*/ */
function createService(requestEntry$?) { function createService(requestEntry$?) {
requestService = getMockRequestService(requestEntry$); requestService = getMockRequestService(requestEntry$);
rdbService = jasmine.createSpyObj('rdbService', { rdbService = jasmine.createSpyObj('rdbService', {
buildList: jasmine.createSpy('buildList') buildList: jasmine.createSpy('buildList'),
buildFromRequestUUID: jasmine.createSpy('buildFromRequestUUID'),
}); });
objectCache = jasmine.createSpyObj('objectCache', { objectCache = jasmine.createSpyObj('objectCache', {
remove: jasmine.createSpy('remove') remove: jasmine.createSpy('remove')
}); });
versionService = jasmine.createSpyObj('objectCache', { versionService = jasmine.createSpyObj('objectCache', {
findAllByHref: jasmine.createSpy('findAllByHref') findByHref: jasmine.createSpy('findByHref'),
findAllByHref: jasmine.createSpy('findAllByHref'),
getHistoryFromVersion: jasmine.createSpy('getHistoryFromVersion'),
}); });
halService = new HALEndpointServiceStub(url); halService = new HALEndpointServiceStub(url);
notificationsService = new NotificationsServiceStub(); notificationsService = new NotificationsServiceStub();
service = new VersionHistoryDataService(requestService, rdbService, null, ob jectCache, halService, notificationsService, versionService, null, null); service = new VersionHistoryDataService(requestService, rdbService, null, ob jectCache, halService, notificationsService, versionService, null, null);
} }
beforeEach(() => {
createService();
});
describe('getVersions', () => {
let result;
beforeEach(() => {
result = service.getVersions('1');
});
it('should call versionService.findAllByHref', () => {
expect(versionService.findAllByHref).toHaveBeenCalled();
});
});
describe('when getVersions is called', () => {
beforeEach(waitForAsync(() => {
service.getVersions(versionHistoryId);
}));
it('findAllByHref should have been called', () => {
expect(versionService.findAllByHref).toHaveBeenCalled();
});
});
describe('when getBrowseEndpoint is called', () => {
it('should return the correct value', () => {
service.getBrowseEndpoint().subscribe((res) => {
expect(res).toBe(url + '/versionhistories');
});
});
});
describe('when getVersionsEndpoint is called', () => {
it('should return the correct value', () => {
service.getVersionsEndpoint(versionHistoryId).subscribe((res) => {
expect(res).toBe(url + '/versions');
});
});
});
describe('when cache is invalidated', () => {
it('should call setStaleByHrefSubstring', () => {
service.invalidateVersionHistoryCache(versionHistoryId);
expect(requestService.setStaleByHrefSubstring).toHaveBeenCalledWith('versi
oning/versionhistories/' + versionHistoryId);
});
});
describe('isLatest$', () => {
beforeEach(waitForAsync(() => {
spyOn(service, 'getLatestVersion$').and.returnValue(of(version2));
}));
it('should return false for version1', () => {
service.isLatest$(version1).subscribe((res) => {
expect(res).toBe(false);
});
});
it('should return true for version2', () => {
service.isLatest$(version2).subscribe((res) => {
expect(res).toBe(true);
});
});
});
describe('hasDraftVersion$', () => {
beforeEach(waitForAsync(() => {
versionService.findByHref.and.returnValue(createSuccessfulRemoteDataObject
$<Version>(version1));
}));
it('should return false if draftVersion is false', fakeAsync(() => {
versionService.getHistoryFromVersion.and.returnValue(of(versionHistory));
service.hasDraftVersion$('href').subscribe((res) => {
expect(res).toBeFalse();
});
}));
it('should return true if draftVersion is true', fakeAsync(() => {
versionService.getHistoryFromVersion.and.returnValue(of(versionHistoryDraf
t));
service.hasDraftVersion$('href').subscribe((res) => {
expect(res).toBeTrue();
});
}));
});
}); });
 End of changes. 8 change blocks. 
16 lines changed or deleted 163 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)