mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
fix followLink tests
This commit is contained in:
@@ -23,6 +23,7 @@ module.exports = function (config) {
|
||||
},
|
||||
reporters: ['mocha', 'kjhtml'],
|
||||
mochaReporter: {
|
||||
ignoreSkipped: true,
|
||||
output: 'autowatch'
|
||||
},
|
||||
port: 9876,
|
||||
|
@@ -10,8 +10,8 @@
|
||||
"build:prod": "yarn run build:ssr",
|
||||
"build:ssr": "yarn run build:client-and-server-bundles && yarn run compile:server",
|
||||
"build:client-and-server-bundles": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod && ng run dspace-angular-cli:server:production --bundleDependencies all",
|
||||
"test": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng test",
|
||||
"test:headless": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng test --watch=false --browsers=ChromeHeadless --code-coverage",
|
||||
"test": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng test --sourceMap=true",
|
||||
"test:headless": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng test --watch=false --sourceMap=true --browsers=ChromeHeadless --code-coverage",
|
||||
"lint": "ng lint",
|
||||
"e2e": "ng e2e",
|
||||
"compile:server": "webpack --config webpack.server.config.js --progress --colors",
|
||||
|
@@ -4,7 +4,7 @@ import { compare, Operation } from 'fast-json-patch';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import * as uuidv4 from 'uuid/v4';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
||||
import { followLink, FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||
import { SortDirection, SortOptions } from '../cache/models/sort-options.model';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
@@ -18,6 +18,7 @@ import { ChangeAnalyzer } from './change-analyzer';
|
||||
import { DataService } from './data.service';
|
||||
import { FindListOptions } from './request.models';
|
||||
import { RequestService } from './request.service';
|
||||
import * as decorators from "../cache/builders/build-decorators";
|
||||
|
||||
const endpoint = 'https://rest.api/core';
|
||||
|
||||
@@ -53,13 +54,24 @@ class DummyChangeAnalyzer implements ChangeAnalyzer<Item> {
|
||||
describe('DataService', () => {
|
||||
let service: TestService;
|
||||
let options: FindListOptions;
|
||||
const requestService = { generateRequestId: () => uuidv4() } as RequestService;
|
||||
const halService = {} as HALEndpointService;
|
||||
const rdbService = {} as RemoteDataBuildService;
|
||||
const notificationsService = {} as NotificationsService;
|
||||
const http = {} as HttpClient;
|
||||
const comparator = new DummyChangeAnalyzer() as any;
|
||||
const objectCache = {
|
||||
let requestService;
|
||||
let halService;
|
||||
let rdbService;
|
||||
let notificationsService;
|
||||
let http;
|
||||
let comparator;
|
||||
let objectCache;
|
||||
let store;
|
||||
|
||||
function initTestService(): TestService {
|
||||
requestService = { generateRequestId: () => uuidv4() } as RequestService;
|
||||
halService = {} as HALEndpointService;
|
||||
rdbService = {} as RemoteDataBuildService;
|
||||
notificationsService = {} as NotificationsService;
|
||||
http = {} as HttpClient;
|
||||
comparator = new DummyChangeAnalyzer() as any;
|
||||
objectCache = {
|
||||
|
||||
addPatch: () => {
|
||||
/* empty */
|
||||
},
|
||||
@@ -67,9 +79,7 @@ describe('DataService', () => {
|
||||
/* empty */
|
||||
}
|
||||
} as any;
|
||||
const store = {} as Store<CoreState>;
|
||||
|
||||
function initTestService(): TestService {
|
||||
store = {} as Store<CoreState>;
|
||||
return new TestService(
|
||||
requestService,
|
||||
rdbService,
|
||||
@@ -83,7 +93,9 @@ describe('DataService', () => {
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
service = initTestService();
|
||||
})
|
||||
|
||||
describe('getFindAllHref', () => {
|
||||
|
||||
@@ -150,67 +162,33 @@ describe('DataService', () => {
|
||||
});
|
||||
|
||||
it('should include single linksToFollow as embed', () => {
|
||||
const mockFollowLinkConfig: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'bundles' as any,
|
||||
});
|
||||
const expected = `${endpoint}?embed=bundles`;
|
||||
|
||||
(service as any).getFindAllHref({}, null, mockFollowLinkConfig).subscribe((value) => {
|
||||
(service as any).getFindAllHref({}, null, followLink('bundles')).subscribe((value) => {
|
||||
expect(value).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
it('should include multiple linksToFollow as embed', () => {
|
||||
const mockFollowLinkConfig: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'bundles' as any,
|
||||
});
|
||||
const mockFollowLinkConfig2: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'owningCollection' as any,
|
||||
});
|
||||
const mockFollowLinkConfig3: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'templateItemOf' as any,
|
||||
});
|
||||
const expected = `${endpoint}?embed=bundles&embed=owningCollection&embed=templateItemOf`;
|
||||
|
||||
(service as any).getFindAllHref({}, null, mockFollowLinkConfig, mockFollowLinkConfig2, mockFollowLinkConfig3).subscribe((value) => {
|
||||
(service as any).getFindAllHref({}, null, followLink('bundles'), followLink('owningCollection'), followLink('templateItemOf')).subscribe((value) => {
|
||||
expect(value).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not include linksToFollow with shouldEmbed = false', () => {
|
||||
const mockFollowLinkConfig: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'bundles' as any,
|
||||
shouldEmbed: false,
|
||||
});
|
||||
const mockFollowLinkConfig2: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'owningCollection' as any,
|
||||
shouldEmbed: false,
|
||||
});
|
||||
const mockFollowLinkConfig3: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'templateItemOf' as any,
|
||||
});
|
||||
const expected = `${endpoint}?embed=templateItemOf`;
|
||||
|
||||
(service as any).getFindAllHref({}, null, mockFollowLinkConfig, mockFollowLinkConfig2, mockFollowLinkConfig3).subscribe((value) => {
|
||||
(service as any).getFindAllHref({}, null, followLink('bundles', undefined, false), followLink('owningCollection', undefined, false), followLink('templateItemOf')).subscribe((value) => {
|
||||
expect(value).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
it('should include nested linksToFollow 3lvl', () => {
|
||||
const mockFollowLinkConfig3: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'relationships' as any,
|
||||
});
|
||||
const mockFollowLinkConfig2: FollowLinkConfig<Collection> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'itemtemplate' as any,
|
||||
linksToFollow: mockFollowLinkConfig3,
|
||||
});
|
||||
const mockFollowLinkConfig: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'owningCollection' as any,
|
||||
linksToFollow: mockFollowLinkConfig2,
|
||||
});
|
||||
const expected = `${endpoint}?embed=owningCollection/itemtemplate/relationships`;
|
||||
|
||||
(service as any).getFindAllHref({}, null, mockFollowLinkConfig).subscribe((value) => {
|
||||
(service as any).getFindAllHref({}, null, followLink('owningCollection', undefined, true, followLink('itemtemplate', undefined, true, followLink('relationships')))).subscribe((value) => {
|
||||
expect(value).toBe(expected);
|
||||
});
|
||||
});
|
||||
@@ -226,60 +204,26 @@ describe('DataService', () => {
|
||||
});
|
||||
|
||||
it('should include single linksToFollow as embed', () => {
|
||||
const mockFollowLinkConfig: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'bundles' as any,
|
||||
});
|
||||
const expected = `${endpointMock}/${resourceIdMock}?embed=bundles`;
|
||||
const result = (service as any).getIDHref(endpointMock, resourceIdMock, mockFollowLinkConfig);
|
||||
const result = (service as any).getIDHref(endpointMock, resourceIdMock, followLink('bundles'));
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should include multiple linksToFollow as embed', () => {
|
||||
const mockFollowLinkConfig: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'bundles' as any,
|
||||
});
|
||||
const mockFollowLinkConfig2: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'owningCollection' as any,
|
||||
});
|
||||
const mockFollowLinkConfig3: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'templateItemOf' as any,
|
||||
});
|
||||
const expected = `${endpointMock}/${resourceIdMock}?embed=bundles&embed=owningCollection&embed=templateItemOf`;
|
||||
const result = (service as any).getIDHref(endpointMock, resourceIdMock, mockFollowLinkConfig, mockFollowLinkConfig2, mockFollowLinkConfig3);
|
||||
const result = (service as any).getIDHref(endpointMock, resourceIdMock, followLink('bundles'), followLink('owningCollection'), followLink('templateItemOf'));
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should not include linksToFollow with shouldEmbed = false', () => {
|
||||
const mockFollowLinkConfig: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'bundles' as any,
|
||||
shouldEmbed: false,
|
||||
});
|
||||
const mockFollowLinkConfig2: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'owningCollection' as any,
|
||||
shouldEmbed: false,
|
||||
});
|
||||
const mockFollowLinkConfig3: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'templateItemOf' as any,
|
||||
});
|
||||
const expected = `${endpointMock}/${resourceIdMock}?embed=templateItemOf`;
|
||||
const result = (service as any).getIDHref(endpointMock, resourceIdMock, mockFollowLinkConfig, mockFollowLinkConfig2, mockFollowLinkConfig3);
|
||||
const result = (service as any).getIDHref(endpointMock, resourceIdMock, followLink('bundles', undefined, false), followLink('owningCollection', undefined, false), followLink('templateItemOf'));
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should include nested linksToFollow 3lvl', () => {
|
||||
const mockFollowLinkConfig3: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'relationships' as any,
|
||||
});
|
||||
const mockFollowLinkConfig2: FollowLinkConfig<Collection> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'itemtemplate' as any,
|
||||
linksToFollow: mockFollowLinkConfig3,
|
||||
});
|
||||
const mockFollowLinkConfig: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'owningCollection' as any,
|
||||
linksToFollow: mockFollowLinkConfig2,
|
||||
});
|
||||
const expected = `${endpointMock}/${resourceIdMock}?embed=owningCollection/itemtemplate/relationships`;
|
||||
const result = (service as any).getIDHref(endpointMock, resourceIdMock, mockFollowLinkConfig);
|
||||
const result = (service as any).getIDHref(endpointMock, resourceIdMock, followLink('owningCollection', undefined, true, followLink('itemtemplate', undefined, true, followLink('relationships'))));
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
@@ -158,7 +158,7 @@ export abstract class DataService<T extends CacheableObject> {
|
||||
* @param linksToFollow links we want to embed in query string if shouldEmbed is true
|
||||
*/
|
||||
protected addEmbedParams(args: string[], ...linksToFollow: Array<FollowLinkConfig<T>>) {
|
||||
[...linksToFollow].forEach((linkToFollow: FollowLinkConfig<T>) => {
|
||||
linksToFollow.forEach((linkToFollow: FollowLinkConfig<T>) => {
|
||||
if (linkToFollow !== undefined && linkToFollow.shouldEmbed) {
|
||||
const embedString = 'embed=' + String(linkToFollow.name);
|
||||
const embedWithNestedString = this.addNestedEmbeds(embedString, ...linkToFollow.linksToFollow);
|
||||
|
@@ -3,13 +3,11 @@ import { Store } from '@ngrx/store';
|
||||
import { cold, getTestScheduler } from 'jasmine-marbles';
|
||||
import { TestScheduler } from 'rxjs/testing';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
||||
import { followLink } from '../../shared/utils/follow-link-config.model';
|
||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { CoreState } from '../core.reducers';
|
||||
import { Collection } from '../shared/collection.model';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { Item } from '../shared/item.model';
|
||||
import { DsoRedirectDataService } from './dso-redirect-data.service';
|
||||
import { FindByIDRequest, IdentifierType } from './request.models';
|
||||
import { RequestService } from './request.service';
|
||||
@@ -150,60 +148,26 @@ describe('DsoRedirectDataService', () => {
|
||||
});
|
||||
|
||||
it('should include single linksToFollow as embed', () => {
|
||||
const mockFollowLinkConfig: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'bundles' as any,
|
||||
});
|
||||
const expected = `${requestUUIDURL}&embed=bundles`;
|
||||
const result = (service as any).getIDHref(pidLink, dsoUUID, mockFollowLinkConfig);
|
||||
const result = (service as any).getIDHref(pidLink, dsoUUID, followLink('bundles'));
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should include multiple linksToFollow as embed', () => {
|
||||
const mockFollowLinkConfig: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'bundles' as any,
|
||||
});
|
||||
const mockFollowLinkConfig2: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'owningCollection' as any,
|
||||
});
|
||||
const mockFollowLinkConfig3: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'templateItemOf' as any,
|
||||
});
|
||||
const expected = `${requestUUIDURL}&embed=bundles&embed=owningCollection&embed=templateItemOf`;
|
||||
const result = (service as any).getIDHref(pidLink, dsoUUID, mockFollowLinkConfig, mockFollowLinkConfig2, mockFollowLinkConfig3);
|
||||
const result = (service as any).getIDHref(pidLink, dsoUUID, followLink('bundles'), followLink('owningCollection'), followLink('templateItemOf'));
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should not include linksToFollow with shouldEmbed = false', () => {
|
||||
const mockFollowLinkConfig: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'bundles' as any,
|
||||
shouldEmbed: false,
|
||||
});
|
||||
const mockFollowLinkConfig2: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'owningCollection' as any,
|
||||
shouldEmbed: false,
|
||||
});
|
||||
const mockFollowLinkConfig3: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'templateItemOf' as any,
|
||||
});
|
||||
const expected = `${requestUUIDURL}&embed=templateItemOf`;
|
||||
const result = (service as any).getIDHref(pidLink, dsoUUID, mockFollowLinkConfig, mockFollowLinkConfig2, mockFollowLinkConfig3);
|
||||
const result = (service as any).getIDHref(pidLink, dsoUUID, followLink('bundles', undefined, false), followLink('owningCollection', undefined, false), followLink('templateItemOf'));
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should include nested linksToFollow 3lvl', () => {
|
||||
const mockFollowLinkConfig3: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'relationships' as any,
|
||||
});
|
||||
const mockFollowLinkConfig2: FollowLinkConfig<Collection> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'itemtemplate' as any,
|
||||
linksToFollow: mockFollowLinkConfig3,
|
||||
});
|
||||
const mockFollowLinkConfig: FollowLinkConfig<Item> = Object.assign(new FollowLinkConfig(), {
|
||||
name: 'owningCollection' as any,
|
||||
linksToFollow: mockFollowLinkConfig2,
|
||||
});
|
||||
const expected = `${requestUUIDURL}&embed=owningCollection/itemtemplate/relationships`;
|
||||
const result = (service as any).getIDHref(pidLink, dsoUUID, mockFollowLinkConfig);
|
||||
const result = (service as any).getIDHref(pidLink, dsoUUID, followLink('owningCollection', undefined, true, followLink('itemtemplate', undefined, true, followLink('relationships'))));
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"sourceMap": true,
|
||||
"outDir": "./out-tsc/spec",
|
||||
"types": [
|
||||
"jasmine",
|
||||
|
Reference in New Issue
Block a user