diff --git a/karma.conf.js b/karma.conf.js index 7cb135d502..9844d65904 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -23,6 +23,7 @@ module.exports = function (config) { }, reporters: ['mocha', 'kjhtml'], mochaReporter: { + ignoreSkipped: true, output: 'autowatch' }, port: 9876, diff --git a/package.json b/package.json index 01ec3f50f5..8a35ef032e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/app/core/data/data.service.spec.ts b/src/app/core/data/data.service.spec.ts index 0346cf2519..9bfec75ff2 100644 --- a/src/app/core/data/data.service.spec.ts +++ b/src/app/core/data/data.service.spec.ts @@ -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,23 +54,32 @@ class DummyChangeAnalyzer implements ChangeAnalyzer { 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 = { - addPatch: () => { - /* empty */ - }, - getObjectBySelfLink: () => { - /* empty */ - } - } as any; - const store = {} as Store; + 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 */ + }, + getObjectBySelfLink: () => { + /* empty */ + } + } as any; + store = {} as Store; return new TestService( requestService, rdbService, @@ -83,7 +93,9 @@ describe('DataService', () => { ); } - service = initTestService(); + beforeEach(() => { + service = initTestService(); + }) describe('getFindAllHref', () => { @@ -150,67 +162,33 @@ describe('DataService', () => { }); it('should include single linksToFollow as embed', () => { - const mockFollowLinkConfig: FollowLinkConfig = 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 = Object.assign(new FollowLinkConfig(), { - name: 'bundles' as any, - }); - const mockFollowLinkConfig2: FollowLinkConfig = Object.assign(new FollowLinkConfig(), { - name: 'owningCollection' as any, - }); - const mockFollowLinkConfig3: FollowLinkConfig = 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 = Object.assign(new FollowLinkConfig(), { - name: 'bundles' as any, - shouldEmbed: false, - }); - const mockFollowLinkConfig2: FollowLinkConfig = Object.assign(new FollowLinkConfig(), { - name: 'owningCollection' as any, - shouldEmbed: false, - }); - const mockFollowLinkConfig3: FollowLinkConfig = 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 = Object.assign(new FollowLinkConfig(), { - name: 'relationships' as any, - }); - const mockFollowLinkConfig2: FollowLinkConfig = Object.assign(new FollowLinkConfig(), { - name: 'itemtemplate' as any, - linksToFollow: mockFollowLinkConfig3, - }); - const mockFollowLinkConfig: FollowLinkConfig = 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 = 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 = Object.assign(new FollowLinkConfig(), { - name: 'bundles' as any, - }); - const mockFollowLinkConfig2: FollowLinkConfig = Object.assign(new FollowLinkConfig(), { - name: 'owningCollection' as any, - }); - const mockFollowLinkConfig3: FollowLinkConfig = 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 = Object.assign(new FollowLinkConfig(), { - name: 'bundles' as any, - shouldEmbed: false, - }); - const mockFollowLinkConfig2: FollowLinkConfig = Object.assign(new FollowLinkConfig(), { - name: 'owningCollection' as any, - shouldEmbed: false, - }); - const mockFollowLinkConfig3: FollowLinkConfig = 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 = Object.assign(new FollowLinkConfig(), { - name: 'relationships' as any, - }); - const mockFollowLinkConfig2: FollowLinkConfig = Object.assign(new FollowLinkConfig(), { - name: 'itemtemplate' as any, - linksToFollow: mockFollowLinkConfig3, - }); - const mockFollowLinkConfig: FollowLinkConfig = 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); }); }); diff --git a/src/app/core/data/data.service.ts b/src/app/core/data/data.service.ts index e3edd3ec9f..3e67675290 100644 --- a/src/app/core/data/data.service.ts +++ b/src/app/core/data/data.service.ts @@ -158,7 +158,7 @@ export abstract class DataService { * @param linksToFollow links we want to embed in query string if shouldEmbed is true */ protected addEmbedParams(args: string[], ...linksToFollow: Array>) { - [...linksToFollow].forEach((linkToFollow: FollowLinkConfig) => { + linksToFollow.forEach((linkToFollow: FollowLinkConfig) => { if (linkToFollow !== undefined && linkToFollow.shouldEmbed) { const embedString = 'embed=' + String(linkToFollow.name); const embedWithNestedString = this.addNestedEmbeds(embedString, ...linkToFollow.linksToFollow); diff --git a/src/app/core/data/dso-redirect-data.service.spec.ts b/src/app/core/data/dso-redirect-data.service.spec.ts index 7c594cc554..ca62347883 100644 --- a/src/app/core/data/dso-redirect-data.service.spec.ts +++ b/src/app/core/data/dso-redirect-data.service.spec.ts @@ -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 = 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 = Object.assign(new FollowLinkConfig(), { - name: 'bundles' as any, - }); - const mockFollowLinkConfig2: FollowLinkConfig = Object.assign(new FollowLinkConfig(), { - name: 'owningCollection' as any, - }); - const mockFollowLinkConfig3: FollowLinkConfig = 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 = Object.assign(new FollowLinkConfig(), { - name: 'bundles' as any, - shouldEmbed: false, - }); - const mockFollowLinkConfig2: FollowLinkConfig = Object.assign(new FollowLinkConfig(), { - name: 'owningCollection' as any, - shouldEmbed: false, - }); - const mockFollowLinkConfig3: FollowLinkConfig = 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 = Object.assign(new FollowLinkConfig(), { - name: 'relationships' as any, - }); - const mockFollowLinkConfig2: FollowLinkConfig = Object.assign(new FollowLinkConfig(), { - name: 'itemtemplate' as any, - linksToFollow: mockFollowLinkConfig3, - }); - const mockFollowLinkConfig: FollowLinkConfig = 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); }); }); diff --git a/tsconfig.spec.json b/tsconfig.spec.json index 6400fde7d5..b593cae319 100644 --- a/tsconfig.spec.json +++ b/tsconfig.spec.json @@ -1,6 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { + "sourceMap": true, "outDir": "./out-tsc/spec", "types": [ "jasmine",