From 96dfc8056ec0fb9316e0ccf565c351e4aaec9172 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Tue, 24 Oct 2023 22:50:32 +0100 Subject: [PATCH 01/12] fix promise rejections --- lib/core/src/lib/login/components/login.component.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/core/src/lib/login/components/login.component.spec.ts b/lib/core/src/lib/login/components/login.component.spec.ts index ee2450f3aa8..58bdc107591 100644 --- a/lib/core/src/lib/login/components/login.component.spec.ts +++ b/lib/core/src/lib/login/components/login.component.spec.ts @@ -469,7 +469,7 @@ describe('LoginComponent', () => { }); it('should return error with a wrong username', (done) => { - spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.reject()); + spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.reject(new Error('login error'))); component.error.subscribe(() => { fixture.detectChanges(); @@ -484,7 +484,7 @@ describe('LoginComponent', () => { }); it('should return error with a wrong password', (done) => { - spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.reject()); + spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.reject(new Error('login error'))); component.error.subscribe(() => { fixture.detectChanges(); @@ -500,7 +500,7 @@ describe('LoginComponent', () => { }); it('should return error with a wrong username and password', (done) => { - spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.reject()); + spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.reject(new Error('login error'))); component.error.subscribe(() => { fixture.detectChanges(); From 88a8a94723efe4aa97571ab9a939547be7d36943 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Tue, 24 Oct 2023 22:59:39 +0100 Subject: [PATCH 02/12] fix promise errors --- .../lib/common/services/people-content.service.spec.ts | 2 +- .../src/lib/common/services/rendition.service.ts | 7 ++++--- .../src/lib/dialogs/node-lock.dialog.spec.ts | 2 +- .../lib/directives/library-favorite.directive.spec.ts | 4 ++-- .../directives/library-membership.directive.spec.ts | 2 +- .../src/lib/directives/node-delete.directive.spec.ts | 8 ++++---- .../src/lib/directives/node-favorite.directive.spec.ts | 6 +++--- .../components/document-list.component.spec.ts | 10 +++++----- .../src/lib/webscript/webscript.component.ts | 2 +- 9 files changed, 22 insertions(+), 21 deletions(-) diff --git a/lib/content-services/src/lib/common/services/people-content.service.spec.ts b/lib/content-services/src/lib/common/services/people-content.service.spec.ts index 6c7a1956b94..d6f687975bc 100644 --- a/lib/content-services/src/lib/common/services/people-content.service.spec.ts +++ b/lib/content-services/src/lib/common/services/people-content.service.spec.ts @@ -110,7 +110,7 @@ describe('PeopleContentService', () => { }); it('should be able to throw an error if createPerson api failed', (done) => { - spyOn(peopleContentService.peopleApi, 'createPerson').and.returnValue(Promise.reject('failed to create new person')); + spyOn(peopleContentService.peopleApi, 'createPerson').and.returnValue(Promise.reject(new Error('failed to create new person'))); const logErrorSpy = spyOn(logService, 'error'); peopleContentService.createPerson(createNewPersonMock).subscribe( () => { diff --git a/lib/content-services/src/lib/common/services/rendition.service.ts b/lib/content-services/src/lib/common/services/rendition.service.ts index 68a031ac76b..3efeae0afcd 100644 --- a/lib/content-services/src/lib/common/services/rendition.service.ts +++ b/lib/content-services/src/lib/common/services/rendition.service.ts @@ -201,7 +201,7 @@ export class RenditionService { clearInterval(intervalId); return resolve(this.handleNodeRendition(nodeId, rendition.entry.content.mimeType, versionId)); } - }, () => reject()); + }, () => reject(new Error('error'))); } else { this.renditionsApi.getRendition(nodeId, renditionId).then((rendition: RenditionEntry) => { const status: string = rendition.entry.status.toString(); @@ -210,11 +210,11 @@ export class RenditionService { clearInterval(intervalId); return resolve(this.handleNodeRendition(nodeId, renditionId, versionId)); } - }, () => reject()); + }, () => reject(new Error('error'))); } } else { clearInterval(intervalId); - return reject(); + return reject(new Error('error')); } }, this.TRY_TIMEOUT); }); @@ -287,6 +287,7 @@ export class RenditionService { * These are: images, PDF files, or PDF rendition of files. * We also force PDF rendition for TEXT type objects, otherwise the default URL is to download. * TODO there are different TEXT type objects, (HTML, plaintext, xml, etc. we should determine how these are handled) + * * @param objectId object it * @param mimeType mime type */ diff --git a/lib/content-services/src/lib/dialogs/node-lock.dialog.spec.ts b/lib/content-services/src/lib/dialogs/node-lock.dialog.spec.ts index 25e66f346ef..f71202a3dd6 100644 --- a/lib/content-services/src/lib/dialogs/node-lock.dialog.spec.ts +++ b/lib/content-services/src/lib/dialogs/node-lock.dialog.spec.ts @@ -92,7 +92,7 @@ describe('NodeLockDialogComponent', () => { })); it('should call onError if submit fails', fakeAsync(() => { - spyOn(component.nodesApi, 'lockNode').and.returnValue(Promise.reject('error')); + spyOn(component.nodesApi, 'lockNode').and.returnValue(Promise.reject(new Error('error'))); spyOn(component.data, 'onError'); component.submit(); diff --git a/lib/content-services/src/lib/directives/library-favorite.directive.spec.ts b/lib/content-services/src/lib/directives/library-favorite.directive.spec.ts index 06a6553d750..a18fa371d7e 100644 --- a/lib/content-services/src/lib/directives/library-favorite.directive.spec.ts +++ b/lib/content-services/src/lib/directives/library-favorite.directive.spec.ts @@ -72,7 +72,7 @@ describe('LibraryFavoriteDirective', () => { }); it('should mark selection not favorite', async () => { - spyOn(component.directive['favoritesApi'], 'getFavoriteSite').and.returnValue(Promise.reject()); + spyOn(component.directive['favoritesApi'], 'getFavoriteSite').and.returnValue(Promise.reject(new Error('error'))); delete selection.isFavorite; @@ -84,7 +84,7 @@ describe('LibraryFavoriteDirective', () => { }); it('should call addFavorite() on click event when selection is not a favorite', async () => { - spyOn(component.directive['favoritesApi'], 'getFavoriteSite').and.returnValue(Promise.reject()); + spyOn(component.directive['favoritesApi'], 'getFavoriteSite').and.returnValue(Promise.reject(new Error('error'))); spyOn(component.directive['favoritesApi'], 'createFavorite').and.returnValue(Promise.resolve(null)); fixture.detectChanges(); diff --git a/lib/content-services/src/lib/directives/library-membership.directive.spec.ts b/lib/content-services/src/lib/directives/library-membership.directive.spec.ts index dc96e8092b1..fecc14a7162 100644 --- a/lib/content-services/src/lib/directives/library-membership.directive.spec.ts +++ b/lib/content-services/src/lib/directives/library-membership.directive.spec.ts @@ -98,7 +98,7 @@ describe('LibraryMembershipDirective', () => { })); it('should remember when a membership request is not found for selected library', fakeAsync(() => { - getMembershipSpy.and.returnValue(Promise.reject()); + getMembershipSpy.and.returnValue(Promise.reject(new Error('error'))); const selection = { entry: testSiteEntry }; const change = new SimpleChange(null, selection, true); diff --git a/lib/content-services/src/lib/directives/node-delete.directive.spec.ts b/lib/content-services/src/lib/directives/node-delete.directive.spec.ts index 63e63b4ac25..0cc6a395df5 100644 --- a/lib/content-services/src/lib/directives/node-delete.directive.spec.ts +++ b/lib/content-services/src/lib/directives/node-delete.directive.spec.ts @@ -152,7 +152,7 @@ describe('NodeDeleteDirective', () => { }); it('should notify failed node deletion', async () => { - deleteNodeSpy.and.returnValue(Promise.reject('error')); + deleteNodeSpy.and.returnValue(Promise.reject(new Error('error'))); component.selection = [{ entry: { id: '1', name: 'name1' } }]; fixture.detectChanges(); @@ -187,7 +187,7 @@ describe('NodeDeleteDirective', () => { }); it('should notify failed nodes deletion', async () => { - deleteNodeSpy.and.returnValue(Promise.reject('error')); + deleteNodeSpy.and.returnValue(Promise.reject(new Error('error'))); component.selection = [ { entry: { id: '1', name: 'name1' } }, @@ -209,7 +209,7 @@ describe('NodeDeleteDirective', () => { it('should notify partial deletion when only one node is successful', async () => { deleteNodeSpy.and.callFake((id) => { if (id === '1') { - return Promise.reject('error'); + return Promise.reject(new Error('error')); } else { return Promise.resolve(); } @@ -235,7 +235,7 @@ describe('NodeDeleteDirective', () => { it('should notify partial deletion when some nodes are successful', async () => { deleteNodeSpy.and.callFake((id) => { if (id === '1') { - return Promise.reject(null); + return Promise.reject(new Error('error')); } return Promise.resolve(); diff --git a/lib/content-services/src/lib/directives/node-favorite.directive.spec.ts b/lib/content-services/src/lib/directives/node-favorite.directive.spec.ts index 6188d3e299b..1bc0d4e7e4f 100644 --- a/lib/content-services/src/lib/directives/node-favorite.directive.spec.ts +++ b/lib/content-services/src/lib/directives/node-favorite.directive.spec.ts @@ -266,7 +266,7 @@ describe('NodeFavoriteDirective', () => { })); it('should emit error event when removeFavoriteSite() fails', fakeAsync(() => { - removeFavoriteSpy.and.returnValue(Promise.reject('error')); + removeFavoriteSpy.and.returnValue(Promise.reject(new Error('error'))); spyOn(directive.error, 'emit'); directive.favorites = [ @@ -280,7 +280,7 @@ describe('NodeFavoriteDirective', () => { })); it('should emit error event when addFavorite() fails', fakeAsync(() => { - addFavoriteSpy.and.returnValue(Promise.reject('error')); + addFavoriteSpy.and.returnValue(Promise.reject(new Error('error'))); spyOn(directive.error, 'emit'); directive.favorites = [ @@ -352,7 +352,7 @@ describe('NodeFavoriteDirective', () => { })); it('should not process node as favorite', fakeAsync(() => { - spyOn(directive['favoritesApi'], 'getFavorite').and.returnValue(Promise.reject({})); + spyOn(directive['favoritesApi'], 'getFavorite').and.returnValue(Promise.reject(new Error('error'))); const selection = [ { entry: { id: '1', name: 'name1' } } diff --git a/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts b/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts index 8ef5841fc37..932f6d7e5ea 100644 --- a/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts +++ b/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts @@ -1273,7 +1273,7 @@ describe('DocumentList', () => { }); it('should emit error when fetch trashcan fails', (done) => { - spyOn(customResourcesService.trashcanApi, 'listDeletedNodes').and.returnValue(Promise.reject('error')); + spyOn(customResourcesService.trashcanApi, 'listDeletedNodes').and.returnValue(Promise.reject(new Error('error'))); const disposableError = documentList.error.subscribe((val) => { expect(val).toBe('error'); @@ -1295,7 +1295,7 @@ describe('DocumentList', () => { }); it('should emit error when fetch shared links fails', (done) => { - spyOn(customResourcesService.sharedLinksApi, 'listSharedLinks').and.returnValue(Promise.reject('error')); + spyOn(customResourcesService.sharedLinksApi, 'listSharedLinks').and.returnValue(Promise.reject(new Error('error'))); const disposableError = documentList.error.subscribe((val) => { expect(val).toBe('error'); @@ -1316,7 +1316,7 @@ describe('DocumentList', () => { }); it('should emit error when fetch sites fails', (done) => { - spyGetSites.and.returnValue(Promise.reject('error')); + spyGetSites.and.returnValue(Promise.reject(new Error('error'))); const disposableError = documentList.error.subscribe((val) => { expect(val).toBe('error'); @@ -1338,7 +1338,7 @@ describe('DocumentList', () => { }); it('should emit error when fetch membership sites fails', (done) => { - spyOn(customResourcesService.sitesApi, 'listSiteMembershipsForPerson').and.returnValue(Promise.reject('error')); + spyOn(customResourcesService.sitesApi, 'listSiteMembershipsForPerson').and.returnValue(Promise.reject(new Error('error'))); const disposableError = documentList.error.subscribe((val) => { expect(val).toBe('error'); @@ -1359,7 +1359,7 @@ describe('DocumentList', () => { }); it('should emit error when fetch favorites fails', (done) => { - spyFavorite.and.returnValue(Promise.reject('error')); + spyFavorite.and.returnValue(Promise.reject(new Error('error'))); const disposableError = documentList.error.subscribe((val) => { expect(val).toBe('error'); diff --git a/lib/content-services/src/lib/webscript/webscript.component.ts b/lib/content-services/src/lib/webscript/webscript.component.ts index 9f426f4e6ae..e78f2836904 100644 --- a/lib/content-services/src/lib/webscript/webscript.component.ts +++ b/lib/content-services/src/lib/webscript/webscript.component.ts @@ -97,7 +97,7 @@ export class WebscriptComponent implements OnChanges { resolve(); }, (error) => { this.logService.log('Error' + error); - reject(); + reject(error); }); }); } From 13e217f51da41a8203458fc6ae93ca61a9cb43d0 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Tue, 24 Oct 2023 23:07:10 +0100 Subject: [PATCH 03/12] promise error fixes --- .eslintrc.js | 2 +- .../components/process-filters.component.spec.ts | 8 ++------ .../services/process-filter.service.spec.ts | 2 +- .../process-list/services/process.service.spec.ts | 14 +++++++------- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index ac8d4754483..5bf929e2a5c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -101,7 +101,7 @@ module.exports = { ], '@typescript-eslint/member-ordering': 'off', 'prefer-arrow/prefer-arrow-functions': 'off', - + 'prefer-promise-reject-errors': 'error', 'brace-style': 'off', '@typescript-eslint/brace-style': 'error', 'comma-dangle': 'error', diff --git a/lib/process-services/src/lib/process-list/components/process-filters.component.spec.ts b/lib/process-services/src/lib/process-list/components/process-filters.component.spec.ts index d0157dd3a93..d40f9d97706 100644 --- a/lib/process-services/src/lib/process-list/components/process-filters.component.spec.ts +++ b/lib/process-services/src/lib/process-list/components/process-filters.component.spec.ts @@ -160,9 +160,7 @@ describe('ProcessFiltersComponent', () => { }); it('should emit an error with a bad response of getProcessFilters', async () => { - const mockErrorFilterPromise = Promise.reject({ - error: 'wrong request' - }); + const mockErrorFilterPromise = Promise.reject(new Error('wrong request')); spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(mockErrorFilterPromise)); const appId = '1'; @@ -177,9 +175,7 @@ describe('ProcessFiltersComponent', () => { }); it('should emit an error with a bad response of getDeployedApplicationsByName', async () => { - const mockErrorFilterPromise = Promise.reject({ - error: 'wrong request' - }); + const mockErrorFilterPromise = Promise.reject(new Error('wrong request')); spyOn(appsProcessService, 'getDeployedApplicationsByName').and.returnValue(from(mockErrorFilterPromise)); const appId = 'fake-app'; diff --git a/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts b/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts index 538c56a938a..1e4ecc848ff 100644 --- a/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts +++ b/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts @@ -243,7 +243,7 @@ describe('Process filter', () => { }); it('should return a default error if no data is returned by the API', (done) => { - createFilter = createFilter.and.returnValue(Promise.reject(null)); + createFilter = createFilter.and.returnValue(Promise.reject(new Error('error'))); service.addProcessFilter(filter).subscribe( () => {}, (res) => { diff --git a/lib/process-services/src/lib/process-list/services/process.service.spec.ts b/lib/process-services/src/lib/process-list/services/process.service.spec.ts index fa2152b83c7..32d65efc235 100644 --- a/lib/process-services/src/lib/process-list/services/process.service.spec.ts +++ b/lib/process-services/src/lib/process-list/services/process.service.spec.ts @@ -145,7 +145,7 @@ describe('ProcessService', () => { }); it('should return a default error if no data is returned by the API', (done) => { - startNewProcessInstance = startNewProcessInstance.and.returnValue(Promise.reject(null)); + startNewProcessInstance = startNewProcessInstance.and.returnValue(Promise.reject(new Error('error'))); service.startProcess(processDefId, processName).subscribe( () => { }, @@ -191,7 +191,7 @@ describe('ProcessService', () => { }); it('should return a default error if no data is returned by the API', (done) => { - deleteProcessInstance = deleteProcessInstance.and.returnValue(Promise.reject(null)); + deleteProcessInstance = deleteProcessInstance.and.returnValue(Promise.reject(new Error('error'))); service.cancelProcess(null).subscribe( () => { }, @@ -251,7 +251,7 @@ describe('ProcessService', () => { }); it('should return a default error if no data is returned by the API', (done) => { - getProcessDefinitions = getProcessDefinitions.and.returnValue(Promise.reject(null)); + getProcessDefinitions = getProcessDefinitions.and.returnValue(Promise.reject(new Error('error'))); service.getProcessDefinitions().subscribe( () => { }, @@ -325,7 +325,7 @@ describe('ProcessService', () => { }); it('should return a default error if no data is returned by the API', (done) => { - listTasks = listTasks.and.returnValue(Promise.reject(null)); + listTasks = listTasks.and.returnValue(Promise.reject(new Error('error'))); service.getProcessTasks(processId).subscribe( () => { }, @@ -379,7 +379,7 @@ describe('ProcessService', () => { }); it('should return a default error if no data is returned by the API', (done) => { - getVariablesSpy = getVariablesSpy.and.returnValue(Promise.reject(null)); + getVariablesSpy = getVariablesSpy.and.returnValue(Promise.reject(new Error('error'))); service.getProcessInstanceVariables(null).subscribe( () => { }, @@ -418,7 +418,7 @@ describe('ProcessService', () => { }); it('should return a default error if no data is returned by the API', (done) => { - createOrUpdateProcessInstanceVariablesSpy = createOrUpdateProcessInstanceVariablesSpy.and.returnValue(Promise.reject(null)); + createOrUpdateProcessInstanceVariablesSpy = createOrUpdateProcessInstanceVariablesSpy.and.returnValue(Promise.reject(new Error('error'))); service.createOrUpdateProcessInstanceVariables('123', updatedVariables).subscribe( () => { }, @@ -444,7 +444,7 @@ describe('ProcessService', () => { }); it('should return a default error if no data is returned by the API', (done) => { - deleteProcessInstanceVariableSpy = deleteProcessInstanceVariableSpy.and.returnValue(Promise.reject(null)); + deleteProcessInstanceVariableSpy = deleteProcessInstanceVariableSpy.and.returnValue(Promise.reject(new Error('error'))); service.deleteProcessInstanceVariable('123', 'myVar').subscribe( () => { }, From 983c57335e9ff68d83cbb986f1190d779ee42715 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Tue, 24 Oct 2023 23:10:55 +0100 Subject: [PATCH 04/12] fix promise rejections --- .../services/content-cloud-node-selector.service.spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.spec.ts b/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.spec.ts index 53b996e199e..ccef6a8a966 100644 --- a/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.spec.ts +++ b/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.spec.ts @@ -99,7 +99,7 @@ describe('ContentCloudNodeSelectorService', () => { }); it('should return defined alias nodeId if the relative path does not exist', async () => { - getNodeSpy.and.returnValues(Promise.reject('Relative does not exists'), Promise.resolve(aliasNodeResponseBody)); + getNodeSpy.and.returnValues(Promise.reject(new Error('Relative does not exists')), Promise.resolve(aliasNodeResponseBody)); const aliasNodeId = await service.getNodeIdFromPath({ alias: 'mock-alias', path: 'mock-relativePath' }); expect(getNodeSpy).toHaveBeenCalledTimes(2); @@ -114,7 +114,7 @@ describe('ContentCloudNodeSelectorService', () => { }); it('should return default nodeId if the given folder does not exist', async () => { - getNodeSpy.and.returnValues(Promise.reject('Folder does not exists'), Promise.resolve(aliasNodeResponseBody)); + getNodeSpy.and.returnValues(Promise.reject(new Error('Folder does not exists')), Promise.resolve(aliasNodeResponseBody)); const aliasNodeId = await service.getNodeIdFromFolderVariableValue('mock-folder-id', '-my-'); expect(getNodeSpy).toHaveBeenCalledTimes(2); @@ -136,7 +136,7 @@ describe('ContentCloudNodeSelectorService', () => { }); it('should show a warning notification if the relative path is invalid/deleted', async () => { - getNodeSpy.and.returnValue(Promise.reject('Relative path does not exists')); + getNodeSpy.and.returnValue(Promise.reject(new Error('Relative path does not exists'))); try { expect(service.sourceNodeNotFound).toBe(false); @@ -155,7 +155,7 @@ describe('ContentCloudNodeSelectorService', () => { }); it('should show a warning notification if the defined folderVariable value is invalid/deleted', async () => { - getNodeSpy.and.returnValue(Promise.reject('Folder does not exists')); + getNodeSpy.and.returnValue(Promise.reject(new Error('Folder does not exists'))); try { expect(service.sourceNodeNotFound).toBe(false); From 406fcd5aca85757717957a524c6bddabaf96a5dd Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Tue, 24 Oct 2023 23:29:20 +0100 Subject: [PATCH 05/12] [ci:force] fix formatting --- .../src/lib/common/services/people-content.service.spec.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/content-services/src/lib/common/services/people-content.service.spec.ts b/lib/content-services/src/lib/common/services/people-content.service.spec.ts index d6f687975bc..60caec2584c 100644 --- a/lib/content-services/src/lib/common/services/people-content.service.spec.ts +++ b/lib/content-services/src/lib/common/services/people-content.service.spec.ts @@ -113,8 +113,7 @@ describe('PeopleContentService', () => { spyOn(peopleContentService.peopleApi, 'createPerson').and.returnValue(Promise.reject(new Error('failed to create new person'))); const logErrorSpy = spyOn(logService, 'error'); peopleContentService.createPerson(createNewPersonMock).subscribe( - () => { - }, + () => {}, (error) => { expect(logErrorSpy).toHaveBeenCalledWith('failed to create new person'); expect(error).toEqual('failed to create new person'); From 61a8a0068273a0861149c27a166b45c539a9ea74 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 25 Oct 2023 00:07:49 +0100 Subject: [PATCH 06/12] test fixes --- .../services/people-content.service.spec.ts | 12 +--- .../common/services/people-content.service.ts | 25 +++----- .../services/rendition.services.spec.ts | 30 ++++----- ...ontent-cloud-node-selector.service.spec.ts | 4 +- .../services/process-filter.service.spec.ts | 10 +-- .../services/process-filter.service.ts | 23 ++----- .../services/process.service.spec.ts | 64 +++++++++---------- 7 files changed, 70 insertions(+), 98 deletions(-) diff --git a/lib/content-services/src/lib/common/services/people-content.service.spec.ts b/lib/content-services/src/lib/common/services/people-content.service.spec.ts index 60caec2584c..0f0c48237f3 100644 --- a/lib/content-services/src/lib/common/services/people-content.service.spec.ts +++ b/lib/content-services/src/lib/common/services/people-content.service.spec.ts @@ -26,17 +26,14 @@ import { AlfrescoApiService, AlfrescoApiServiceMock, AuthenticationService, - CoreTestingModule, - LogService + CoreTestingModule } from '@alfresco/adf-core'; import { PeopleContentQueryRequestModel, PeopleContentService } from './people-content.service'; import { TranslateModule } from '@ngx-translate/core'; import { TestBed } from '@angular/core/testing'; describe('PeopleContentService', () => { - let peopleContentService: PeopleContentService; - let logService: LogService; let authenticationService: AuthenticationService; beforeEach(() => { @@ -52,7 +49,6 @@ describe('PeopleContentService', () => { authenticationService = TestBed.inject(AuthenticationService); peopleContentService = TestBed.inject(PeopleContentService); - logService = TestBed.inject(LogService); }); it('should be able to fetch person details based on id', async () => { @@ -111,12 +107,10 @@ describe('PeopleContentService', () => { it('should be able to throw an error if createPerson api failed', (done) => { spyOn(peopleContentService.peopleApi, 'createPerson').and.returnValue(Promise.reject(new Error('failed to create new person'))); - const logErrorSpy = spyOn(logService, 'error'); peopleContentService.createPerson(createNewPersonMock).subscribe( () => {}, - (error) => { - expect(logErrorSpy).toHaveBeenCalledWith('failed to create new person'); - expect(error).toEqual('failed to create new person'); + (error: Error) => { + expect(error.message).toEqual('failed to create new person'); done(); } ); diff --git a/lib/content-services/src/lib/common/services/people-content.service.ts b/lib/content-services/src/lib/common/services/people-content.service.ts index a973ca3bc47..95cf50b895e 100644 --- a/lib/content-services/src/lib/common/services/people-content.service.ts +++ b/lib/content-services/src/lib/common/services/people-content.service.ts @@ -16,9 +16,9 @@ */ import { Injectable } from '@angular/core'; -import { from, Observable, of, throwError } from 'rxjs'; -import { AlfrescoApiService, AuthenticationService, LogService } from '@alfresco/adf-core'; -import { catchError, map, tap } from 'rxjs/operators'; +import { from, Observable, of } from 'rxjs'; +import { AlfrescoApiService, AuthenticationService } from '@alfresco/adf-core'; +import { map, tap } from 'rxjs/operators'; import { Pagination, PeopleApi, PersonBodyCreate, PersonBodyUpdate } from '@alfresco/js-api'; import { EcmUserModel } from '../models/ecm-user.model'; import { ContentService } from './content.service'; @@ -59,7 +59,6 @@ export class PeopleContentService { constructor( private apiService: AlfrescoApiService, authenticationService: AuthenticationService, - private logService: LogService, private contentService: ContentService ) { authenticationService.onLogout.subscribe(() => { @@ -76,8 +75,8 @@ export class PeopleContentService { getPerson(personId: string): Observable { return from(this.peopleApi.getPerson(personId)) .pipe( - map((personEntry) => new EcmUserModel(personEntry.entry)), - catchError((error) => this.handleError(error))); + map((personEntry) => new EcmUserModel(personEntry.entry)) + ); } getCurrentPerson(): Observable { @@ -130,8 +129,7 @@ export class PeopleContentService { map(response => ({ pagination: response.list.pagination, entries: response.list.entries.map((person) => person.entry as EcmUserModel) - })), - catchError((err) => this.handleError(err)) + })) ); } @@ -144,8 +142,7 @@ export class PeopleContentService { */ createPerson(newPerson: PersonBodyCreate, opts?: any): Observable { return from(this.peopleApi.createPerson(newPerson, opts)).pipe( - map((res) => res?.entry as EcmUserModel), - catchError((error) => this.handleError(error)) + map((res) => res?.entry as EcmUserModel) ); } @@ -159,8 +156,7 @@ export class PeopleContentService { */ updatePerson(personId: string, details: PersonBodyUpdate, opts?: any): Observable { return from(this.peopleApi.updatePerson(personId, details, opts)).pipe( - map((res) => res?.entry as EcmUserModel), - catchError((error) => this.handleError(error)) + map((res) => res?.entry as EcmUserModel) ); } @@ -177,9 +173,4 @@ export class PeopleContentService { private buildOrderArray(sorting: PeopleContentSortingModel): string[] { return sorting?.orderBy && sorting?.direction ? [`${sorting.orderBy} ${sorting.direction.toUpperCase()}`] : []; } - - private handleError(error: any) { - this.logService.error(error); - return throwError(error || 'Server error'); - } } diff --git a/lib/content-services/src/lib/common/services/rendition.services.spec.ts b/lib/content-services/src/lib/common/services/rendition.services.spec.ts index ff7d24bfe5c..713a387a03e 100644 --- a/lib/content-services/src/lib/common/services/rendition.services.spec.ts +++ b/lib/content-services/src/lib/common/services/rendition.services.spec.ts @@ -20,22 +20,20 @@ import { AlfrescoApiService, LogService, TranslationService, ViewUtilService } f import { Rendition, RenditionEntry, RenditionPaging, RenditionsApi } from '@alfresco/js-api'; import { RenditionService } from '@alfresco/adf-content-services'; -const getRenditionEntry = (status: Rendition.StatusEnum): RenditionEntry => { - return { - entry: { - id: 'pdf', - status: status, - content: { mimeType: 'application/pdf', mimeTypeName: 'application/pdf', sizeInBytes: 10 } - } - }; -}; -const getRenditionPaging = (status: Rendition.StatusEnum): RenditionPaging => { - return { - list: { - entries: [getRenditionEntry(status)] - } - }; -}; +const getRenditionEntry = (status: Rendition.StatusEnum): RenditionEntry => ({ + entry: { + id: 'pdf', + status, + content: { mimeType: 'application/pdf', mimeTypeName: 'application/pdf', sizeInBytes: 10 } + } +}); + +const getRenditionPaging = (status: Rendition.StatusEnum): RenditionPaging => ({ + list: { + entries: [getRenditionEntry(status)] + } +}); + describe('RenditionService', () => { let renditionService: RenditionService; let renditionsApi: any; diff --git a/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.spec.ts b/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.spec.ts index ccef6a8a966..cb0e5c912d3 100644 --- a/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.spec.ts +++ b/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.spec.ts @@ -144,7 +144,7 @@ describe('ContentCloudNodeSelectorService', () => { await service.getNodeIdFromPath({ alias: 'mock-alias', path: 'mock-relativePath' }); fail('An error should have been thrown'); } catch (error) { - expect(error).toEqual('Relative path does not exists'); + expect(error.message).toEqual('Relative path does not exists'); expect(service.sourceNodeNotFound).toBe(true); } @@ -163,7 +163,7 @@ describe('ContentCloudNodeSelectorService', () => { await service.getNodeIdFromFolderVariableValue('mock-folder-id', '-my-'); fail('An error should have been thrown'); } catch (error) { - expect(error).toEqual('Folder does not exists'); + expect(error.message).toEqual('Folder does not exists'); expect(service.sourceNodeNotFound).toBe(true); } diff --git a/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts b/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts index 1e4ecc848ff..db72bc7261a 100644 --- a/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts +++ b/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts @@ -47,7 +47,7 @@ describe('Process filter', () => { let createFilter: jasmine.Spy; beforeEach(() => { - getFilters = spyOn(service['userFiltersApi'], 'getUserProcessInstanceFilters').and.returnValue( + getFilters = spyOn(service.userFiltersApi, 'getUserProcessInstanceFilters').and.returnValue( Promise.resolve(fakeProcessFiltersResponse) ); @@ -211,7 +211,7 @@ describe('Process filter', () => { describe('add filter', () => { beforeEach(() => { - createFilter = spyOn(service['userFiltersApi'], 'createUserProcessInstanceFilter').and.callFake( + createFilter = spyOn(service.userFiltersApi, 'createUserProcessInstanceFilter').and.callFake( (processFilter) => Promise.resolve(processFilter) ); }); @@ -243,11 +243,11 @@ describe('Process filter', () => { }); it('should return a default error if no data is returned by the API', (done) => { - createFilter = createFilter.and.returnValue(Promise.reject(new Error('error'))); + createFilter = createFilter.and.returnValue(Promise.reject(new Error('Server error'))); service.addProcessFilter(filter).subscribe( () => {}, - (res) => { - expect(res).toBe('Server error'); + (err) => { + expect(err.message).toBe('Server error'); done(); } ); diff --git a/lib/process-services/src/lib/process-list/services/process-filter.service.ts b/lib/process-services/src/lib/process-list/services/process-filter.service.ts index 598efe98aa4..5217e8525c7 100644 --- a/lib/process-services/src/lib/process-list/services/process-filter.service.ts +++ b/lib/process-services/src/lib/process-list/services/process-filter.service.ts @@ -17,9 +17,9 @@ import { AlfrescoApiService } from '@alfresco/adf-core'; import { Injectable } from '@angular/core'; -import { Observable, from, forkJoin, throwError } from 'rxjs'; +import { Observable, from, forkJoin } from 'rxjs'; import { FilterProcessRepresentationModel } from '../models/filter-process.model'; -import { map, catchError } from 'rxjs/operators'; +import { map } from 'rxjs/operators'; import { ResultListDataRepresentationUserProcessInstanceFilterRepresentation, UserFiltersApi @@ -57,8 +57,7 @@ export class ProcessFilterService { } }); return filters; - }), - catchError((err) => this.handleProcessError(err)) + }) ); } @@ -72,8 +71,7 @@ export class ProcessFilterService { getProcessFilterById(filterId: number, appId?: number): Observable { return from(this.callApiProcessFilters(appId)) .pipe( - map((response: any) => response.data.find((filter) => filter.id === filterId)), - catchError((err) => this.handleProcessError(err)) + map((response: any) => response.data.find((filter) => filter.id === filterId)) ); } @@ -87,8 +85,7 @@ export class ProcessFilterService { getProcessFilterByName(filterName: string, appId?: number): Observable { return from(this.callApiProcessFilters(appId)) .pipe( - map((response: any) => response.data.find((filter) => filter.name === filterName)), - catchError((err) => this.handleProcessError(err)) + map((response: any) => response.data.find((filter) => filter.name === filterName)) ); } @@ -130,9 +127,6 @@ export class ProcessFilterService { }); observer.next(filters); observer.complete(); - }, - (err: any) => { - this.handleProcessError(err); }); }); } @@ -175,8 +169,7 @@ export class ProcessFilterService { addProcessFilter(filter: FilterProcessRepresentationModel): Observable { return from(this.userFiltersApi.createUserProcessInstanceFilter(filter)) .pipe( - map((response: FilterProcessRepresentationModel) => response), - catchError((err) => this.handleProcessError(err)) + map((response: FilterProcessRepresentationModel) => response) ); } @@ -215,8 +208,4 @@ export class ProcessFilterService { index }); } - - private handleProcessError(error: any) { - return throwError(error || 'Server error'); - } } diff --git a/lib/process-services/src/lib/process-list/services/process.service.spec.ts b/lib/process-services/src/lib/process-list/services/process.service.spec.ts index 32d65efc235..807bd703a76 100644 --- a/lib/process-services/src/lib/process-list/services/process.service.spec.ts +++ b/lib/process-services/src/lib/process-list/services/process.service.spec.ts @@ -46,7 +46,7 @@ describe('ProcessService', () => { }); beforeEach(() => { - spyOn(service['processInstancesApi'], 'getProcessInstances') + spyOn(service.processInstancesApi, 'getProcessInstances') .and .returnValue(Promise.resolve({ data: [exampleProcess] })); }); @@ -74,7 +74,7 @@ describe('ProcessService', () => { const processId = 'test'; beforeEach(() => { - spyOn(service['processInstancesApi'], 'getProcessInstance') + spyOn(service.processInstancesApi, 'getProcessInstance') .and .returnValue(Promise.resolve(exampleProcess)); }); @@ -95,7 +95,7 @@ describe('ProcessService', () => { let startNewProcessInstance: jasmine.Spy; beforeEach(() => { - startNewProcessInstance = spyOn(service['processInstancesApi'], 'startNewProcessInstance') + startNewProcessInstance = spyOn(service.processInstancesApi, 'startNewProcessInstance') .and .returnValue(Promise.resolve(exampleProcess)); }); @@ -145,12 +145,12 @@ describe('ProcessService', () => { }); it('should return a default error if no data is returned by the API', (done) => { - startNewProcessInstance = startNewProcessInstance.and.returnValue(Promise.reject(new Error('error'))); + startNewProcessInstance = startNewProcessInstance.and.returnValue(Promise.reject(new Error('Server error'))); service.startProcess(processDefId, processName).subscribe( () => { }, - (res) => { - expect(res).toBe('Server error'); + (err) => { + expect(err.message).toBe('Server error'); done(); } ); @@ -163,7 +163,7 @@ describe('ProcessService', () => { let deleteProcessInstance: jasmine.Spy; beforeEach(() => { - deleteProcessInstance = spyOn(service['processInstancesApi'], 'deleteProcessInstance') + deleteProcessInstance = spyOn(service.processInstancesApi, 'deleteProcessInstance') .and .returnValue(Promise.resolve()); }); @@ -191,12 +191,12 @@ describe('ProcessService', () => { }); it('should return a default error if no data is returned by the API', (done) => { - deleteProcessInstance = deleteProcessInstance.and.returnValue(Promise.reject(new Error('error'))); + deleteProcessInstance = deleteProcessInstance.and.returnValue(Promise.reject(new Error('Server error'))); service.cancelProcess(null).subscribe( () => { }, - (res) => { - expect(res).toBe('Server error'); + (err) => { + expect(err.message).toBe('Server error'); done(); } ); @@ -208,7 +208,7 @@ describe('ProcessService', () => { let getProcessDefinitions: jasmine.Spy; beforeEach(() => { - getProcessDefinitions = spyOn(service['processDefinitionsApi'], 'getProcessDefinitions') + getProcessDefinitions = spyOn(service.processDefinitionsApi, 'getProcessDefinitions') .and .returnValue(Promise.resolve({ data: [fakeProcessDef, fakeProcessDef] })); }); @@ -251,12 +251,12 @@ describe('ProcessService', () => { }); it('should return a default error if no data is returned by the API', (done) => { - getProcessDefinitions = getProcessDefinitions.and.returnValue(Promise.reject(new Error('error'))); + getProcessDefinitions = getProcessDefinitions.and.returnValue(Promise.reject(new Error('Server error'))); service.getProcessDefinitions().subscribe( () => { }, - (res) => { - expect(res).toBe('Server error'); + (err) => { + expect(err.message).toBe('Server error'); done(); } ); @@ -269,7 +269,7 @@ describe('ProcessService', () => { let listTasks: jasmine.Spy; beforeEach(() => { - listTasks = spyOn(service['tasksApi'], 'listTasks') + listTasks = spyOn(service.tasksApi, 'listTasks') .and .returnValue(Promise.resolve(fakeTasksList)); }); @@ -325,12 +325,12 @@ describe('ProcessService', () => { }); it('should return a default error if no data is returned by the API', (done) => { - listTasks = listTasks.and.returnValue(Promise.reject(new Error('error'))); + listTasks = listTasks.and.returnValue(Promise.reject(new Error('Server error'))); service.getProcessTasks(processId).subscribe( () => { }, - (res) => { - expect(res).toBe('Server error'); + (err) => { + expect(err.message).toBe('Server error'); done(); } ); @@ -344,7 +344,7 @@ describe('ProcessService', () => { let deleteProcessInstanceVariableSpy: jasmine.Spy; beforeEach(() => { - getVariablesSpy = spyOn(service['processInstanceVariablesApi'], 'getProcessInstanceVariables').and.returnValue(Promise.resolve([{ + getVariablesSpy = spyOn(service.processInstanceVariablesApi, 'getProcessInstanceVariables').and.returnValue(Promise.resolve([{ name: 'var1', value: 'Test1' }, { @@ -352,10 +352,10 @@ describe('ProcessService', () => { value: 'Test3' }])); - createOrUpdateProcessInstanceVariablesSpy = spyOn(service['processInstanceVariablesApi'], + createOrUpdateProcessInstanceVariablesSpy = spyOn(service.processInstanceVariablesApi, 'createOrUpdateProcessInstanceVariables').and.returnValue(Promise.resolve({} as any)); - deleteProcessInstanceVariableSpy = spyOn(service['processInstanceVariablesApi'], + deleteProcessInstanceVariableSpy = spyOn(service.processInstanceVariablesApi, 'deleteProcessInstanceVariable').and.returnValue(Promise.resolve()); }); @@ -379,12 +379,12 @@ describe('ProcessService', () => { }); it('should return a default error if no data is returned by the API', (done) => { - getVariablesSpy = getVariablesSpy.and.returnValue(Promise.reject(new Error('error'))); + getVariablesSpy = getVariablesSpy.and.returnValue(Promise.reject(new Error('Server error'))); service.getProcessInstanceVariables(null).subscribe( () => { }, - (res) => { - expect(res).toBe('Server error'); + (err) => { + expect(err.message).toBe('Server error'); done(); } ); @@ -410,20 +410,20 @@ describe('ProcessService', () => { service.createOrUpdateProcessInstanceVariables('123', updatedVariables).subscribe( () => { }, - (res) => { - expect(res).toBe(mockError); + (err) => { + expect(err).toBe(mockError); done(); } ); }); it('should return a default error if no data is returned by the API', (done) => { - createOrUpdateProcessInstanceVariablesSpy = createOrUpdateProcessInstanceVariablesSpy.and.returnValue(Promise.reject(new Error('error'))); + createOrUpdateProcessInstanceVariablesSpy = createOrUpdateProcessInstanceVariablesSpy.and.returnValue(Promise.reject(new Error('Server error'))); service.createOrUpdateProcessInstanceVariables('123', updatedVariables).subscribe( () => { }, - (res) => { - expect(res).toBe('Server error'); + (err) => { + expect(err.message).toBe('Server error'); done(); } ); @@ -444,12 +444,12 @@ describe('ProcessService', () => { }); it('should return a default error if no data is returned by the API', (done) => { - deleteProcessInstanceVariableSpy = deleteProcessInstanceVariableSpy.and.returnValue(Promise.reject(new Error('error'))); + deleteProcessInstanceVariableSpy = deleteProcessInstanceVariableSpy.and.returnValue(Promise.reject(new Error('Server error'))); service.deleteProcessInstanceVariable('123', 'myVar').subscribe( () => { }, - (res) => { - expect(res).toBe('Server error'); + (err) => { + expect(err.message).toBe('Server error'); done(); } ); From e79ff65d72c94f3a282c67e1f94ebec2f714a734 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 25 Oct 2023 00:17:58 +0100 Subject: [PATCH 07/12] [ci:force] fix tests --- .../library-favorite.directive.spec.ts | 24 +++++++++---------- .../library-membership.directive.spec.ts | 8 +++---- .../directives/node-delete.directive.spec.ts | 6 ++--- .../node-favorite.directive.spec.ts | 24 +++++++++---------- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/lib/content-services/src/lib/directives/library-favorite.directive.spec.ts b/lib/content-services/src/lib/directives/library-favorite.directive.spec.ts index a18fa371d7e..9af3a8f133c 100644 --- a/lib/content-services/src/lib/directives/library-favorite.directive.spec.ts +++ b/lib/content-services/src/lib/directives/library-favorite.directive.spec.ts @@ -53,39 +53,39 @@ describe('LibraryFavoriteDirective', () => { }); it('should not check for favorite if no selection exists', () => { - spyOn(component.directive['favoritesApi'], 'getFavoriteSite'); + spyOn(component.directive.favoritesApi, 'getFavoriteSite'); fixture.detectChanges(); - expect(component.directive['favoritesApi'].getFavoriteSite).not.toHaveBeenCalled(); + expect(component.directive.favoritesApi.getFavoriteSite).not.toHaveBeenCalled(); }); it('should mark selection as favorite', async () => { - spyOn(component.directive['favoritesApi'], 'getFavoriteSite').and.returnValue(Promise.resolve(null)); + spyOn(component.directive.favoritesApi, 'getFavoriteSite').and.returnValue(Promise.resolve(null)); delete selection.isFavorite; fixture.detectChanges(); await fixture.whenStable(); - expect(component.directive['favoritesApi'].getFavoriteSite).toHaveBeenCalled(); + expect(component.directive.favoritesApi.getFavoriteSite).toHaveBeenCalled(); expect(component.directive.isFavorite()).toBe(true); }); it('should mark selection not favorite', async () => { - spyOn(component.directive['favoritesApi'], 'getFavoriteSite').and.returnValue(Promise.reject(new Error('error'))); + spyOn(component.directive.favoritesApi, 'getFavoriteSite').and.returnValue(Promise.reject(new Error('error'))); delete selection.isFavorite; fixture.detectChanges(); await fixture.whenStable(); - expect(component.directive['favoritesApi'].getFavoriteSite).toHaveBeenCalled(); + expect(component.directive.favoritesApi.getFavoriteSite).toHaveBeenCalled(); expect(component.directive.isFavorite()).toBe(false); }); it('should call addFavorite() on click event when selection is not a favorite', async () => { - spyOn(component.directive['favoritesApi'], 'getFavoriteSite').and.returnValue(Promise.reject(new Error('error'))); - spyOn(component.directive['favoritesApi'], 'createFavorite').and.returnValue(Promise.resolve(null)); + spyOn(component.directive.favoritesApi, 'getFavoriteSite').and.returnValue(Promise.reject(new Error('error'))); + spyOn(component.directive.favoritesApi, 'createFavorite').and.returnValue(Promise.resolve(null)); fixture.detectChanges(); await fixture.whenStable(); @@ -94,12 +94,12 @@ describe('LibraryFavoriteDirective', () => { fixture.nativeElement.querySelector('button').dispatchEvent(new MouseEvent('click')); fixture.detectChanges(); - expect(component.directive['favoritesApi'].createFavorite).toHaveBeenCalled(); + expect(component.directive.favoritesApi.createFavorite).toHaveBeenCalled(); }); it('should call removeFavoriteSite() on click event when selection is favorite', async () => { - spyOn(component.directive['favoritesApi'], 'getFavoriteSite').and.returnValue(Promise.resolve(null)); - spyOn(component.directive['favoritesApi'], 'deleteFavorite').and.returnValue(Promise.resolve()); + spyOn(component.directive.favoritesApi, 'getFavoriteSite').and.returnValue(Promise.resolve(null)); + spyOn(component.directive.favoritesApi, 'deleteFavorite').and.returnValue(Promise.resolve()); selection.isFavorite = true; @@ -113,6 +113,6 @@ describe('LibraryFavoriteDirective', () => { fixture.detectChanges(); await fixture.whenStable(); - expect(component.directive['favoritesApi'].deleteFavorite).toHaveBeenCalled(); + expect(component.directive.favoritesApi.deleteFavorite).toHaveBeenCalled(); }); }); diff --git a/lib/content-services/src/lib/directives/library-membership.directive.spec.ts b/lib/content-services/src/lib/directives/library-membership.directive.spec.ts index fecc14a7162..a76ed373169 100644 --- a/lib/content-services/src/lib/directives/library-membership.directive.spec.ts +++ b/lib/content-services/src/lib/directives/library-membership.directive.spec.ts @@ -70,7 +70,7 @@ describe('LibraryMembershipDirective', () => { describe('markMembershipRequest', () => { beforeEach(() => { - getMembershipSpy = spyOn(directive['sitesApi'], 'getSiteMembershipRequestForPerson').and.returnValue(Promise.resolve({ entry: requestedMembershipResponse })); + getMembershipSpy = spyOn(directive.sitesApi, 'getSiteMembershipRequestForPerson').and.returnValue(Promise.resolve({ entry: requestedMembershipResponse })); }); it('should not check membership requests if no entry is selected', fakeAsync(() => { @@ -111,9 +111,9 @@ describe('LibraryMembershipDirective', () => { describe('toggleMembershipRequest', () => { beforeEach(() => { mockSupportedVersion = false; - getMembershipSpy = spyOn(directive['sitesApi'], 'getSiteMembershipRequestForPerson').and.returnValue(Promise.resolve({ entry: requestedMembershipResponse })); - addMembershipSpy = spyOn(directive['sitesApi'], 'createSiteMembershipRequestForPerson').and.returnValue(Promise.resolve({ entry: requestedMembershipResponse })); - deleteMembershipSpy = spyOn(directive['sitesApi'], 'deleteSiteMembershipRequestForPerson').and.returnValue(Promise.resolve()); + getMembershipSpy = spyOn(directive.sitesApi, 'getSiteMembershipRequestForPerson').and.returnValue(Promise.resolve({ entry: requestedMembershipResponse })); + addMembershipSpy = spyOn(directive.sitesApi, 'createSiteMembershipRequestForPerson').and.returnValue(Promise.resolve({ entry: requestedMembershipResponse })); + deleteMembershipSpy = spyOn(directive.sitesApi, 'deleteSiteMembershipRequestForPerson').and.returnValue(Promise.resolve()); }); it('should do nothing if there is no selected library ', fakeAsync(() => { diff --git a/lib/content-services/src/lib/directives/node-delete.directive.spec.ts b/lib/content-services/src/lib/directives/node-delete.directive.spec.ts index 0cc6a395df5..84a21839c34 100644 --- a/lib/content-services/src/lib/directives/node-delete.directive.spec.ts +++ b/lib/content-services/src/lib/directives/node-delete.directive.spec.ts @@ -111,10 +111,10 @@ describe('NodeDeleteDirective', () => { element = fixture.debugElement.query(By.directive(NodeDeleteDirective)); elementWithPermanentDelete = fixtureWithPermanentComponent.debugElement.query(By.directive(NodeDeleteDirective)); - deleteNodeSpy = spyOn(component.deleteDirective['nodesApi'], 'deleteNode').and.returnValue(Promise.resolve()); + deleteNodeSpy = spyOn(component.deleteDirective.nodesApi, 'deleteNode').and.returnValue(Promise.resolve()); - deleteNodePermanentSpy = spyOn(componentWithPermanentDelete.deleteDirective['nodesApi'], 'deleteNode').and.returnValue(Promise.resolve()); - purgeDeletedNodePermanentSpy = spyOn(componentWithPermanentDelete.deleteDirective['trashcanApi'], 'deleteDeletedNode').and.returnValue(Promise.resolve()); + deleteNodePermanentSpy = spyOn(componentWithPermanentDelete.deleteDirective.nodesApi, 'deleteNode').and.returnValue(Promise.resolve()); + purgeDeletedNodePermanentSpy = spyOn(componentWithPermanentDelete.deleteDirective.trashcanApi, 'deleteDeletedNode').and.returnValue(Promise.resolve()); }); diff --git a/lib/content-services/src/lib/directives/node-favorite.directive.spec.ts b/lib/content-services/src/lib/directives/node-favorite.directive.spec.ts index 1bc0d4e7e4f..f34898ccb16 100644 --- a/lib/content-services/src/lib/directives/node-favorite.directive.spec.ts +++ b/lib/content-services/src/lib/directives/node-favorite.directive.spec.ts @@ -69,7 +69,7 @@ describe('NodeFavoriteDirective', () => { }); it('should reset favorites if selection is empty', fakeAsync(() => { - spyOn(directive['favoritesApi'], 'getFavorite').and.returnValue(Promise.resolve(null)); + spyOn(directive.favoritesApi, 'getFavorite').and.returnValue(Promise.resolve(null)); const selection = [ { entry: { id: '1', name: 'name1' } } @@ -90,11 +90,10 @@ describe('NodeFavoriteDirective', () => { }); describe('markFavoritesNodes()', () => { - let favoritesApiSpy; + let favoritesApiSpy: jasmine.Spy; beforeEach(() => { - favoritesApiSpy = spyOn(directive['favoritesApi'], 'getFavorite') - .and.returnValue(Promise.resolve(null)); + favoritesApiSpy = spyOn(directive.favoritesApi, 'getFavorite').and.returnValue(Promise.resolve(null)); }); it('should check each selected node if it is a favorite', fakeAsync(() => { @@ -108,7 +107,6 @@ describe('NodeFavoriteDirective', () => { tick(); expect(favoritesApiSpy.calls.count()).toBe(2); - })); it('should not check processed node when another is unselected', fakeAsync(() => { @@ -170,12 +168,12 @@ describe('NodeFavoriteDirective', () => { }); describe('toggleFavorite()', () => { - let removeFavoriteSpy; - let addFavoriteSpy; + let removeFavoriteSpy: jasmine.Spy; + let addFavoriteSpy: jasmine.Spy; beforeEach(() => { - removeFavoriteSpy = spyOn(directive['favoritesApi'], 'deleteFavorite').and.callThrough(); - addFavoriteSpy = spyOn(directive['favoritesApi'], 'createFavorite').and.callThrough(); + removeFavoriteSpy = spyOn(directive.favoritesApi, 'deleteFavorite').and.callThrough(); + addFavoriteSpy = spyOn(directive.favoritesApi, 'createFavorite').and.callThrough(); }); afterEach(() => { @@ -323,7 +321,7 @@ describe('NodeFavoriteDirective', () => { describe('getFavorite()', () => { it('should not hit server when using 6.x api', fakeAsync(() => { - spyOn(directive['favoritesApi'], 'getFavorite').and.callThrough(); + spyOn(directive.favoritesApi, 'getFavorite').and.callThrough(); const selection = [ { entry: { id: '1', name: 'name1', isFavorite: true } } @@ -334,11 +332,11 @@ describe('NodeFavoriteDirective', () => { tick(); expect(directive.favorites[0].entry.isFavorite).toBe(true); - expect(directive['favoritesApi'].getFavorite).not.toHaveBeenCalled(); + expect(directive.favoritesApi.getFavorite).not.toHaveBeenCalled(); })); it('should process node as favorite', fakeAsync(() => { - spyOn(directive['favoritesApi'], 'getFavorite').and.returnValue(Promise.resolve(null)); + spyOn(directive.favoritesApi, 'getFavorite').and.returnValue(Promise.resolve(null)); const selection = [ { entry: { id: '1', name: 'name1' } } @@ -352,7 +350,7 @@ describe('NodeFavoriteDirective', () => { })); it('should not process node as favorite', fakeAsync(() => { - spyOn(directive['favoritesApi'], 'getFavorite').and.returnValue(Promise.reject(new Error('error'))); + spyOn(directive.favoritesApi, 'getFavorite').and.returnValue(Promise.reject(new Error('error'))); const selection = [ { entry: { id: '1', name: 'name1' } } From 49a7f0cf17e66c0bf3393931f396d5c90cf7a33b Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 25 Oct 2023 00:28:42 +0100 Subject: [PATCH 08/12] [ci:force] fix tests --- .../node-favorite.directive.spec.ts | 10 ++++++---- .../document-list.component.spec.ts | 20 +++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/content-services/src/lib/directives/node-favorite.directive.spec.ts b/lib/content-services/src/lib/directives/node-favorite.directive.spec.ts index f34898ccb16..93be1bea47a 100644 --- a/lib/content-services/src/lib/directives/node-favorite.directive.spec.ts +++ b/lib/content-services/src/lib/directives/node-favorite.directive.spec.ts @@ -264,7 +264,8 @@ describe('NodeFavoriteDirective', () => { })); it('should emit error event when removeFavoriteSite() fails', fakeAsync(() => { - removeFavoriteSpy.and.returnValue(Promise.reject(new Error('error'))); + const error = new Error('error'); + removeFavoriteSpy.and.returnValue(Promise.reject(error)); spyOn(directive.error, 'emit'); directive.favorites = [ @@ -274,11 +275,12 @@ describe('NodeFavoriteDirective', () => { directive.toggleFavorite(); tick(); - expect(directive.error.emit).toHaveBeenCalledWith('error'); + expect(directive.error.emit).toHaveBeenCalledWith(error); })); it('should emit error event when addFavorite() fails', fakeAsync(() => { - addFavoriteSpy.and.returnValue(Promise.reject(new Error('error'))); + const error = new Error('error'); + addFavoriteSpy.and.returnValue(Promise.reject(error)); spyOn(directive.error, 'emit'); directive.favorites = [ @@ -288,7 +290,7 @@ describe('NodeFavoriteDirective', () => { directive.toggleFavorite(); tick(); - expect(directive.error.emit).toHaveBeenCalledWith('error'); + expect(directive.error.emit).toHaveBeenCalledWith(error); })); it('should set isFavorites items to false', fakeAsync(() => { diff --git a/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts b/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts index 932f6d7e5ea..9ee89ac841d 100644 --- a/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts +++ b/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts @@ -1275,8 +1275,8 @@ describe('DocumentList', () => { it('should emit error when fetch trashcan fails', (done) => { spyOn(customResourcesService.trashcanApi, 'listDeletedNodes').and.returnValue(Promise.reject(new Error('error'))); - const disposableError = documentList.error.subscribe((val) => { - expect(val).toBe('error'); + const disposableError = documentList.error.subscribe((err) => { + expect(err.message).toBe('error'); disposableError.unsubscribe(); done(); }); @@ -1297,8 +1297,8 @@ describe('DocumentList', () => { it('should emit error when fetch shared links fails', (done) => { spyOn(customResourcesService.sharedLinksApi, 'listSharedLinks').and.returnValue(Promise.reject(new Error('error'))); - const disposableError = documentList.error.subscribe((val) => { - expect(val).toBe('error'); + const disposableError = documentList.error.subscribe((err) => { + expect(err.message).toBe('error'); disposableError.unsubscribe(); done(); }); @@ -1318,8 +1318,8 @@ describe('DocumentList', () => { it('should emit error when fetch sites fails', (done) => { spyGetSites.and.returnValue(Promise.reject(new Error('error'))); - const disposableError = documentList.error.subscribe((val) => { - expect(val).toBe('error'); + const disposableError = documentList.error.subscribe((err) => { + expect(err.message).toBe('error'); disposableError.unsubscribe(); done(); }); @@ -1340,8 +1340,8 @@ describe('DocumentList', () => { it('should emit error when fetch membership sites fails', (done) => { spyOn(customResourcesService.sitesApi, 'listSiteMembershipsForPerson').and.returnValue(Promise.reject(new Error('error'))); - const disposableError = documentList.error.subscribe((val) => { - expect(val).toBe('error'); + const disposableError = documentList.error.subscribe((err) => { + expect(err.message).toBe('error'); disposableError.unsubscribe(); done(); }); @@ -1361,8 +1361,8 @@ describe('DocumentList', () => { it('should emit error when fetch favorites fails', (done) => { spyFavorite.and.returnValue(Promise.reject(new Error('error'))); - const disposableError = documentList.error.subscribe((val) => { - expect(val).toBe('error'); + const disposableError = documentList.error.subscribe((err) => { + expect(err.message).toBe('error'); disposableError.unsubscribe(); done(); }); From 74b049478799a97364945c3a291c2822f201156c Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 25 Oct 2023 11:15:57 +0100 Subject: [PATCH 09/12] fix incorrect return types --- .../services/process-filter.service.spec.ts | 4 ++-- .../services/process-filter.service.ts | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts b/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts index db72bc7261a..f480c4c601a 100644 --- a/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts +++ b/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts @@ -70,7 +70,7 @@ describe('Process filter', () => { }); it('should return the task filter by id', (done) => { - service.getProcessFilterById(333).subscribe((processFilter: FilterProcessRepresentationModel) => { + service.getProcessFilterById(333).subscribe((processFilter) => { expect(processFilter).toBeDefined(); expect(processFilter.id).toEqual(333); expect(processFilter.name).toEqual('Running'); @@ -81,7 +81,7 @@ describe('Process filter', () => { }); it('should return the task filter by name', (done) => { - service.getProcessFilterByName('Running').subscribe((res: FilterProcessRepresentationModel) => { + service.getProcessFilterByName('Running').subscribe((res) => { expect(res).toBeDefined(); expect(res.id).toEqual(333); expect(res.name).toEqual('Running'); diff --git a/lib/process-services/src/lib/process-list/services/process-filter.service.ts b/lib/process-services/src/lib/process-list/services/process-filter.service.ts index 5217e8525c7..084cbcda517 100644 --- a/lib/process-services/src/lib/process-list/services/process-filter.service.ts +++ b/lib/process-services/src/lib/process-list/services/process-filter.service.ts @@ -22,7 +22,8 @@ import { FilterProcessRepresentationModel } from '../models/filter-process.model import { map } from 'rxjs/operators'; import { ResultListDataRepresentationUserProcessInstanceFilterRepresentation, - UserFiltersApi + UserFiltersApi, + UserProcessInstanceFilterRepresentation } from '@alfresco/js-api'; @Injectable({ @@ -68,10 +69,10 @@ export class ProcessFilterService { * @param appId ID of the target app * @returns Details of the filter */ - getProcessFilterById(filterId: number, appId?: number): Observable { + getProcessFilterById(filterId: number, appId?: number): Observable { return from(this.callApiProcessFilters(appId)) .pipe( - map((response: any) => response.data.find((filter) => filter.id === filterId)) + map((response) => response.data.find((filter) => filter.id === filterId)) ); } @@ -82,10 +83,10 @@ export class ProcessFilterService { * @param appId ID of the target app * @returns Details of the filter */ - getProcessFilterByName(filterName: string, appId?: number): Observable { + getProcessFilterByName(filterName: string, appId?: number): Observable { return from(this.callApiProcessFilters(appId)) .pipe( - map((response: any) => response.data.find((filter) => filter.name === filterName)) + map((response) => response.data.find((filter) => filter.name === filterName)) ); } @@ -166,10 +167,10 @@ export class ProcessFilterService { * @param filter The filter to add * @returns The filter just added */ - addProcessFilter(filter: FilterProcessRepresentationModel): Observable { + addProcessFilter(filter: FilterProcessRepresentationModel): Observable { return from(this.userFiltersApi.createUserProcessInstanceFilter(filter)) .pipe( - map((response: FilterProcessRepresentationModel) => response) + map((response) => response) ); } From a0c9e7c6e1f8d0759eed887c528027bd41e001a2 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 25 Oct 2023 11:17:12 +0100 Subject: [PATCH 10/12] meaningful errors --- .../src/lib/common/services/rendition.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/content-services/src/lib/common/services/rendition.service.ts b/lib/content-services/src/lib/common/services/rendition.service.ts index 3efeae0afcd..07557b04fc1 100644 --- a/lib/content-services/src/lib/common/services/rendition.service.ts +++ b/lib/content-services/src/lib/common/services/rendition.service.ts @@ -201,7 +201,7 @@ export class RenditionService { clearInterval(intervalId); return resolve(this.handleNodeRendition(nodeId, rendition.entry.content.mimeType, versionId)); } - }, () => reject(new Error('error'))); + }, () => reject(new Error('Error geting version rendition'))); } else { this.renditionsApi.getRendition(nodeId, renditionId).then((rendition: RenditionEntry) => { const status: string = rendition.entry.status.toString(); @@ -210,11 +210,11 @@ export class RenditionService { clearInterval(intervalId); return resolve(this.handleNodeRendition(nodeId, renditionId, versionId)); } - }, () => reject(new Error('error'))); + }, () => reject(new Error('Error getting rendition'))); } } else { clearInterval(intervalId); - return reject(new Error('error')); + return reject(new Error('Error getting rendition')); } }, this.TRY_TIMEOUT); }); From fbd2779898e548b404889a9fb8ce32455ea6abd8 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 25 Oct 2023 11:19:19 +0100 Subject: [PATCH 11/12] remove useless pipe --- .../src/lib/process-list/services/process-filter.service.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/process-services/src/lib/process-list/services/process-filter.service.ts b/lib/process-services/src/lib/process-list/services/process-filter.service.ts index 084cbcda517..70c08a52c09 100644 --- a/lib/process-services/src/lib/process-list/services/process-filter.service.ts +++ b/lib/process-services/src/lib/process-list/services/process-filter.service.ts @@ -168,10 +168,7 @@ export class ProcessFilterService { * @returns The filter just added */ addProcessFilter(filter: FilterProcessRepresentationModel): Observable { - return from(this.userFiltersApi.createUserProcessInstanceFilter(filter)) - .pipe( - map((response) => response) - ); + return from(this.userFiltersApi.createUserProcessInstanceFilter(filter)); } /** From 54ed0e364b15bd25cc1feb59d4f1de8350de1115 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 25 Oct 2023 11:21:34 +0100 Subject: [PATCH 12/12] fix accessing private members in the test --- .../lib/process-list/services/process-filter.service.spec.ts | 4 ++-- .../src/lib/process-list/services/process-filter.service.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts b/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts index f480c4c601a..f7d74156ee2 100644 --- a/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts +++ b/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts @@ -307,8 +307,8 @@ describe('Process filter', () => { const duplicateRunningObservable = of(duplicateRunningFilter); spyOn(service, 'getRunningFilterInstance').and.returnValue(runningFilter); - spyOn(service, 'getCompletedFilterInstance').and.returnValue(completedFilter); - spyOn(service, 'getAllFilterInstance').and.returnValue(allFilter); + spyOn(service, 'getCompletedFilterInstance').and.returnValue(completedFilter); + spyOn(service, 'getAllFilterInstance').and.returnValue(allFilter); spyOn(service, 'addProcessFilter').and.returnValues( runningObservable, diff --git a/lib/process-services/src/lib/process-list/services/process-filter.service.ts b/lib/process-services/src/lib/process-list/services/process-filter.service.ts index 70c08a52c09..fd6e318425d 100644 --- a/lib/process-services/src/lib/process-list/services/process-filter.service.ts +++ b/lib/process-services/src/lib/process-list/services/process-filter.service.ts @@ -185,7 +185,7 @@ export class ProcessFilterService { } } - private getCompletedFilterInstance(appId: number, index?: number): FilterProcessRepresentationModel { + getCompletedFilterInstance(appId: number, index?: number): FilterProcessRepresentationModel { return new FilterProcessRepresentationModel({ name: 'Completed', appId, @@ -196,7 +196,7 @@ export class ProcessFilterService { }); } - private getAllFilterInstance(appId: number, index?: number): FilterProcessRepresentationModel { + getAllFilterInstance(appId: number, index?: number): FilterProcessRepresentationModel { return new FilterProcessRepresentationModel({ name: 'All', appId,