Merge branch 'master' into w2p-58789_Metadata-Registry-UI-Part-2

Conflicts:
	src/app/+admin/admin-registries/metadata-schema/metadata-schema.component.ts
	src/app/+community-page/community-page.component.html
	src/app/app.reducer.ts
	src/app/core/auth/server-auth.service.ts
	src/app/core/core.module.ts
	src/app/core/data/item-data.service.spec.ts
	src/app/core/data/item-data.service.ts
	src/app/core/index/index.effects.ts
	src/app/core/index/index.reducer.spec.ts
	src/app/core/index/index.reducer.ts
	src/app/core/shared/operators.spec.ts
	src/app/core/shared/operators.ts
	src/app/header/header.component.spec.ts
This commit is contained in:
Kristof De Langhe
2019-01-24 13:18:20 +01:00
179 changed files with 7578 additions and 1989 deletions

View File

@@ -8,17 +8,31 @@ import { ItemDataService } from './item-data.service';
import { RequestService } from './request.service';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { ObjectCacheService } from '../cache/object-cache.service';
import { FindAllOptions } from './request.models';
import { FindAllOptions, RestRequest } from './request.models';
import { Observable } from 'rxjs/internal/Observable';
import { RestResponse } from '../cache/response.models';
describe('ItemDataService', () => {
let scheduler: TestScheduler;
let service: ItemDataService;
let bs: BrowseService;
const requestService = {} as RequestService;
const requestService = {
generateRequestId(): string {
return scopeID;
},
configure(request: RestRequest) {
// Do nothing
}
} as RequestService;
const rdbService = {} as RemoteDataBuildService;
const objectCache = {} as ObjectCacheService;
const store = {} as Store<CoreState>;
const halEndpointService = {} as HALEndpointService;
const halEndpointService = {
getEndpoint(linkPath: string): Observable<string> {
return cold('a', {a: itemEndpoint});
}
} as HALEndpointService;
const scopeID = '4af28e99-6a9c-4036-a199-e1b587046d39';
const options = Object.assign(new FindAllOptions(), {
@@ -34,10 +48,12 @@ describe('ItemDataService', () => {
const scopedEndpoint = `${itemBrowseEndpoint}?scope=${scopeID}`;
const serviceEndpoint = `https://rest.api/core/items`;
const browseError = new Error('getBrowseURL failed');
const itemEndpoint = 'https://rest.api/core/items';
const ScopedItemEndpoint = `https://rest.api/core/items/${scopeID}`;
function initMockBrowseService(isSuccessful: boolean) {
const obs = isSuccessful ?
cold('--a-', { a: itemBrowseEndpoint }) :
cold('--a-', {a: itemBrowseEndpoint}) :
cold('--#-', undefined, browseError);
return jasmine.createSpyObj('bs', {
getBrowseURLFor: obs
@@ -65,7 +81,7 @@ describe('ItemDataService', () => {
service = initTestService();
const result = service.getBrowseEndpoint(options);
const expected = cold('--b-', { b: scopedEndpoint });
const expected = cold('--b-', {b: scopedEndpoint});
expect(result).toBeObservable(expected);
});
@@ -83,4 +99,70 @@ describe('ItemDataService', () => {
});
});
});
describe('getItemWithdrawEndpoint', () => {
beforeEach(() => {
scheduler = getTestScheduler();
service = initTestService();
});
it('should return the endpoint to withdraw and reinstate items', () => {
const result = service.getItemWithdrawEndpoint(scopeID);
const expected = cold('a', {a: ScopedItemEndpoint});
expect(result).toBeObservable(expected);
});
it('should setWithDrawn', () => {
const expected = new RestResponse(true, '200');
const result = service.setWithDrawn(scopeID, true);
result.subscribe((v) => expect(v).toEqual(expected));
});
});
describe('getItemDiscoverableEndpoint', () => {
beforeEach(() => {
scheduler = getTestScheduler();
service = initTestService();
});
it('should return the endpoint to make an item private or public', () => {
const result = service.getItemDiscoverableEndpoint(scopeID);
const expected = cold('a', {a: ScopedItemEndpoint});
expect(result).toBeObservable(expected);
});
it('should setDiscoverable', () => {
const expected = new RestResponse(true, '200');
const result = service.setDiscoverable(scopeID, false);
result.subscribe((v) => expect(v).toEqual(expected));
});
});
describe('getItemDeleteEndpoint', () => {
beforeEach(() => {
scheduler = getTestScheduler();
service = initTestService();
});
it('should return the endpoint to make an item private or public', () => {
const result = service.getItemDeleteEndpoint(scopeID);
const expected = cold('a', {a: ScopedItemEndpoint});
expect(result).toBeObservable(expected);
});
it('should delete the item', () => {
const expected = new RestResponse(true, '200');
const result = service.delete(scopeID);
result.subscribe((v) => expect(v).toEqual(expected));
});
});
});

View File

@@ -14,8 +14,9 @@ import { URLCombiner } from '../url-combiner/url-combiner';
import { DataService } from './data.service';
import { RequestService } from './request.service';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { FindAllOptions } from './request.models';
import { DeleteRequest, FindAllOptions, PatchRequest, RestRequest } from './request.models';
import { ObjectCacheService } from '../cache/object-cache.service';
import { configureRequest, getResponseFromEntry } from '../shared/operators';
@Injectable()
export class ItemDataService extends DataService<NormalizedItem, Item> {
@@ -48,4 +49,87 @@ export class ItemDataService extends DataService<NormalizedItem, Item> {
distinctUntilChanged(),);
}
/**
* Get the endpoint for item withdrawal and reinstatement
* @param itemId
*/
public getItemWithdrawEndpoint(itemId: string): Observable<string> {
return this.halService.getEndpoint(this.linkPath).pipe(
map((endpoint: string) => this.getFindByIDHref(endpoint, itemId))
);
}
/**
* Get the endpoint to make item private and public
* @param itemId
*/
public getItemDiscoverableEndpoint(itemId: string): Observable<string> {
return this.halService.getEndpoint(this.linkPath).pipe(
map((endpoint: string) => this.getFindByIDHref(endpoint, itemId))
);
}
/**
* Get the endpoint to delete the item
* @param itemId
*/
public getItemDeleteEndpoint(itemId: string): Observable<string> {
return this.halService.getEndpoint(this.linkPath).pipe(
map((endpoint: string) => this.getFindByIDHref(endpoint, itemId))
);
}
/**
* Set the isWithdrawn state of an item to a specified state
* @param itemId
* @param withdrawn
*/
public setWithDrawn(itemId: string, withdrawn: boolean) {
const patchOperation = [{
op: 'replace', path: '/withdrawn', value: withdrawn
}];
return this.getItemWithdrawEndpoint(itemId).pipe(
distinctUntilChanged(),
map((endpointURL: string) =>
new PatchRequest(this.requestService.generateRequestId(), endpointURL, patchOperation)
),
configureRequest(this.requestService),
getResponseFromEntry()
);
}
/**
* Set the isDiscoverable state of an item to a specified state
* @param itemId
* @param discoverable
*/
public setDiscoverable(itemId: string, discoverable: boolean) {
const patchOperation = [{
op: 'replace', path: '/discoverable', value: discoverable
}];
return this.getItemDiscoverableEndpoint(itemId).pipe(
distinctUntilChanged(),
map((endpointURL: string) =>
new PatchRequest(this.requestService.generateRequestId(), endpointURL, patchOperation)
),
configureRequest(this.requestService),
getResponseFromEntry()
);
}
/**
* Delete the item
* @param itemId
*/
public delete(itemId: string) {
return this.getItemDeleteEndpoint(itemId).pipe(
distinctUntilChanged(),
map((endpointURL: string) =>
new DeleteRequest(this.requestService.generateRequestId(), endpointURL)
),
configureRequest(this.requestService),
getResponseFromEntry()
);
}
}