AAE-35340 Replace deprecated toPromise() usages with firstValueFrom / lastValueFrom (#11161)

This commit is contained in:
Amedeo Lepore
2025-09-03 14:37:13 +02:00
committed by GitHub
parent 93c872b65d
commit 51c55674b4
27 changed files with 178 additions and 191 deletions

View File

@@ -21,7 +21,7 @@ import { PeopleContentQueryRequestModel, PeopleContentService } from './people-c
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { PersonPaging } from '@alfresco/js-api'; import { PersonPaging } from '@alfresco/js-api';
import { HttpClientTestingModule } from '@angular/common/http/testing'; import { HttpClientTestingModule } from '@angular/common/http/testing';
import { EMPTY, of } from 'rxjs'; import { EMPTY, firstValueFrom, of } from 'rxjs';
import { AlfrescoApiService } from '../../services'; import { AlfrescoApiService } from '../../services';
import { AlfrescoApiServiceMock } from '../../mock'; import { AlfrescoApiServiceMock } from '../../mock';
@@ -83,14 +83,14 @@ describe('PeopleContentService', () => {
it('should be able to fetch person details based on id', async () => { it('should be able to fetch person details based on id', async () => {
spyOn(peopleContentService.peopleApi, 'getPerson').and.returnValue(Promise.resolve({ entry: fakeEcmUser } as any)); spyOn(peopleContentService.peopleApi, 'getPerson').and.returnValue(Promise.resolve({ entry: fakeEcmUser } as any));
const person = await peopleContentService.getPerson('fake-id').toPromise(); const person = await firstValueFrom(peopleContentService.getPerson('fake-id'));
expect(person.id).toEqual('fake-id'); expect(person.id).toEqual('fake-id');
expect(person.email).toEqual('fakeEcm@ecmUser.com'); expect(person.email).toEqual('fakeEcm@ecmUser.com');
}); });
it('should be able to list people', async () => { it('should be able to list people', async () => {
spyOn(peopleContentService.peopleApi, 'listPeople').and.returnValue(Promise.resolve(fakeEcmUserList)); spyOn(peopleContentService.peopleApi, 'listPeople').and.returnValue(Promise.resolve(fakeEcmUserList));
const response = await peopleContentService.listPeople().toPromise(); const response = await firstValueFrom(peopleContentService.listPeople());
const people = response.entries; const people = response.entries;
const pagination = response.pagination; const pagination = response.pagination;
@@ -112,7 +112,7 @@ describe('PeopleContentService', () => {
}; };
const expectedValue = { skipCount: 10, maxItems: 20, orderBy: ['firstName ASC'] } as any; const expectedValue = { skipCount: 10, maxItems: 20, orderBy: ['firstName ASC'] } as any;
await peopleContentService.listPeople(requestQueryParams).toPromise(); await firstValueFrom(peopleContentService.listPeople(requestQueryParams));
expect(listPeopleSpy).toHaveBeenCalledWith(expectedValue); expect(listPeopleSpy).toHaveBeenCalledWith(expectedValue);
}); });
@@ -122,14 +122,14 @@ describe('PeopleContentService', () => {
const requestQueryParams: PeopleContentQueryRequestModel = { skipCount: 10, maxItems: 20, sorting: undefined }; const requestQueryParams: PeopleContentQueryRequestModel = { skipCount: 10, maxItems: 20, sorting: undefined };
const expectedValue = { skipCount: 10, maxItems: 20 }; const expectedValue = { skipCount: 10, maxItems: 20 };
await peopleContentService.listPeople(requestQueryParams).toPromise(); await firstValueFrom(peopleContentService.listPeople(requestQueryParams));
expect(listPeopleSpy).toHaveBeenCalledWith(expectedValue); expect(listPeopleSpy).toHaveBeenCalledWith(expectedValue);
}); });
it('should be able to create new person', async () => { it('should be able to create new person', async () => {
spyOn(peopleContentService.peopleApi, 'createPerson').and.returnValue(Promise.resolve({ entry: fakeEcmUser } as any)); spyOn(peopleContentService.peopleApi, 'createPerson').and.returnValue(Promise.resolve({ entry: fakeEcmUser } as any));
const newUser = await peopleContentService.createPerson(createNewPersonMock).toPromise(); const newUser = await firstValueFrom(peopleContentService.createPerson(createNewPersonMock));
expect(newUser.id).toEqual('fake-id'); expect(newUser.id).toEqual('fake-id');
expect(newUser.email).toEqual('fakeEcm@ecmUser.com'); expect(newUser.email).toEqual('fakeEcm@ecmUser.com');
}); });
@@ -150,12 +150,12 @@ describe('PeopleContentService', () => {
Promise.resolve({ entry: fakeEcmAdminUser } as any) Promise.resolve({ entry: fakeEcmAdminUser } as any)
); );
const user = await peopleContentService.getCurrentUserInfo().toPromise(); const user = await firstValueFrom(peopleContentService.getCurrentUserInfo());
expect(user.id).toEqual('fake-id'); expect(user.id).toEqual('fake-id');
expect(peopleContentService.isCurrentUserAdmin()).toBe(true); expect(peopleContentService.isCurrentUserAdmin()).toBe(true);
expect(getCurrentPersonSpy.calls.count()).toEqual(1); expect(getCurrentPersonSpy.calls.count()).toEqual(1);
await peopleContentService.getCurrentUserInfo().toPromise(); await firstValueFrom(peopleContentService.getCurrentUserInfo());
expect(peopleContentService.isCurrentUserAdmin()).toBe(true); expect(peopleContentService.isCurrentUserAdmin()).toBe(true);
expect(getCurrentPersonSpy.calls.count()).toEqual(1); expect(getCurrentPersonSpy.calls.count()).toEqual(1);
@@ -165,13 +165,13 @@ describe('PeopleContentService', () => {
const getCurrentPersonSpy = spyOn(peopleContentService.peopleApi, 'getPerson').and.returnValue( const getCurrentPersonSpy = spyOn(peopleContentService.peopleApi, 'getPerson').and.returnValue(
Promise.resolve({ entry: fakeEcmAdminUser } as any) Promise.resolve({ entry: fakeEcmAdminUser } as any)
); );
await peopleContentService.getCurrentUserInfo().toPromise(); await firstValueFrom(peopleContentService.getCurrentUserInfo());
getCurrentPersonSpy.and.returnValue(Promise.resolve({ entry: fakeEcmUser2 } as any)); getCurrentPersonSpy.and.returnValue(Promise.resolve({ entry: fakeEcmUser2 } as any));
await peopleContentService.getPerson('fake-id').toPromise(); await firstValueFrom(peopleContentService.getPerson('fake-id'));
expect(getCurrentPersonSpy.calls.count()).toEqual(2); expect(getCurrentPersonSpy.calls.count()).toEqual(2);
const currentUser = await peopleContentService.getCurrentUserInfo().toPromise(); const currentUser = await firstValueFrom(peopleContentService.getCurrentUserInfo());
expect(peopleContentService.isCurrentUserAdmin()).toBe(true); expect(peopleContentService.isCurrentUserAdmin()).toBe(true);
expect(currentUser.id).toEqual(fakeEcmAdminUser.id); expect(currentUser.id).toEqual(fakeEcmAdminUser.id);
expect(currentUser.id).not.toEqual(fakeEcmUser2.id); expect(currentUser.id).not.toEqual(fakeEcmUser2.id);

View File

@@ -32,7 +32,7 @@ import { MatChipHarness } from '@angular/material/chips/testing';
import { MatDialogModule } from '@angular/material/dialog'; import { MatDialogModule } from '@angular/material/dialog';
import { MatExpansionPanel } from '@angular/material/expansion'; import { MatExpansionPanel } from '@angular/material/expansion';
import { MatSnackBarModule } from '@angular/material/snack-bar'; import { MatSnackBarModule } from '@angular/material/snack-bar';
import { EMPTY, of, throwError } from 'rxjs'; import { EMPTY, firstValueFrom, of, throwError } from 'rxjs';
import { CategoriesManagementComponent, CategoriesManagementMode } from '../../../category'; import { CategoriesManagementComponent, CategoriesManagementMode } from '../../../category';
import { TagsCreatorComponent, TagsCreatorMode } from '../../../tag'; import { TagsCreatorComponent, TagsCreatorMode } from '../../../tag';
import { ContentTestingModule } from '../../../testing/content.testing.module'; import { ContentTestingModule } from '../../../testing/content.testing.module';
@@ -1144,7 +1144,7 @@ describe('ContentMetadataComponent', () => {
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) }); component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
fixture.detectChanges(); fixture.detectChanges();
await component.groupedProperties$.toPromise(); await firstValueFrom(component.groupedProperties$);
fixture.detectChanges(); fixture.detectChanges();
const verProp = queryDom('Versionable'); const verProp = queryDom('Versionable');
@@ -1164,7 +1164,7 @@ describe('ContentMetadataComponent', () => {
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) }); component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
fixture.detectChanges(); fixture.detectChanges();
await component.groupedProperties$.toPromise(); await firstValueFrom(component.groupedProperties$);
fixture.detectChanges(); fixture.detectChanges();
const verProps = fixture.debugElement.queryAll(By.css('[data-automation-id="adf-metadata-group-Versionable"]')); const verProps = fixture.debugElement.queryAll(By.css('[data-automation-id="adf-metadata-group-Versionable"]'));
@@ -1184,7 +1184,7 @@ describe('ContentMetadataComponent', () => {
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) }); component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
fixture.detectChanges(); fixture.detectChanges();
await component.groupedProperties$.toPromise(); await firstValueFrom(component.groupedProperties$);
fixture.detectChanges(); fixture.detectChanges();
const verProp = queryDom('Versionable'); const verProp = queryDom('Versionable');
@@ -1205,7 +1205,7 @@ describe('ContentMetadataComponent', () => {
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) }); component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
fixture.detectChanges(); fixture.detectChanges();
await component.groupedProperties$.toPromise(); await firstValueFrom(component.groupedProperties$);
fixture.detectChanges(); fixture.detectChanges();
const verProp = queryDom('Versionable'); const verProp = queryDom('Versionable');
@@ -1225,7 +1225,7 @@ describe('ContentMetadataComponent', () => {
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) }); component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
fixture.detectChanges(); fixture.detectChanges();
await component.groupedProperties$.toPromise(); await firstValueFrom(component.groupedProperties$);
fixture.detectChanges(); fixture.detectChanges();
const verProp = queryDom('Versionable'); const verProp = queryDom('Versionable');
@@ -1249,7 +1249,7 @@ describe('ContentMetadataComponent', () => {
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) }); component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
fixture.detectChanges(); fixture.detectChanges();
await component.groupedProperties$.toPromise(); await firstValueFrom(component.groupedProperties$);
fixture.detectChanges(); fixture.detectChanges();
const exifProp = queryDom('Exif'); const exifProp = queryDom('Exif');
@@ -1283,7 +1283,7 @@ describe('ContentMetadataComponent', () => {
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) }); component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
fixture.detectChanges(); fixture.detectChanges();
await component.groupedProperties$.toPromise(); await firstValueFrom(component.groupedProperties$);
fixture.detectChanges(); fixture.detectChanges();
const exifProps = fixture.debugElement.queryAll(By.css('[data-automation-id="adf-metadata-group-Exif"]')); const exifProps = fixture.debugElement.queryAll(By.css('[data-automation-id="adf-metadata-group-Exif"]'));

View File

@@ -18,7 +18,7 @@
import { AppConfigService } from '@alfresco/adf-core'; import { AppConfigService } from '@alfresco/adf-core';
import { ClassesApi, Node } from '@alfresco/js-api'; import { ClassesApi, Node } from '@alfresco/js-api';
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { of } from 'rxjs'; import { firstValueFrom, of } from 'rxjs';
import { ContentTestingModule } from '../../testing/content.testing.module'; import { ContentTestingModule } from '../../testing/content.testing.module';
import { OrganisedPropertyGroup } from '../interfaces/content-metadata.interfaces'; import { OrganisedPropertyGroup } from '../interfaces/content-metadata.interfaces';
import { PropertyGroup } from '../interfaces/property-group.interface'; import { PropertyGroup } from '../interfaces/property-group.interface';
@@ -253,7 +253,7 @@ describe('ContentMetaDataService', () => {
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(exifResponse)); spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(exifResponse));
const groupedProperties = await service.getGroupedProperties(fakeNode).toPromise(); const groupedProperties = await firstValueFrom(service.getGroupedProperties(fakeNode));
expect(groupedProperties.length).toEqual(1); expect(groupedProperties.length).toEqual(1);
expect(groupedProperties[0].title).toEqual('Exif'); expect(groupedProperties[0].title).toEqual('Exif');
@@ -267,7 +267,7 @@ describe('ContentMetaDataService', () => {
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(exifResponse)); spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(exifResponse));
const groupedProperties = await service.getGroupedProperties(fakeNode).toPromise(); const groupedProperties = await firstValueFrom(service.getGroupedProperties(fakeNode));
expect(groupedProperties.length).toEqual(1); expect(groupedProperties.length).toEqual(1);
expect(groupedProperties[0].title).toEqual('Exif'); expect(groupedProperties[0].title).toEqual('Exif');
@@ -284,7 +284,7 @@ describe('ContentMetaDataService', () => {
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(verResponse)); spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(verResponse));
const groupedProperties = await service.getGroupedProperties(fakeContentNode).toPromise(); const groupedProperties = await firstValueFrom(service.getGroupedProperties(fakeContentNode));
expect(groupedProperties.length).toEqual(1); expect(groupedProperties.length).toEqual(1);
expect(groupedProperties[0].title).toEqual('Versionable'); expect(groupedProperties[0].title).toEqual('Versionable');
@@ -301,7 +301,7 @@ describe('ContentMetaDataService', () => {
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(verResponse)); spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(verResponse));
const groupedProperties = await service.getGroupedProperties(fakeContentNode).toPromise(); const groupedProperties = await firstValueFrom(service.getGroupedProperties(fakeContentNode));
expect(groupedProperties.length).toEqual(2); expect(groupedProperties.length).toEqual(2);
expect(groupedProperties[0].title).toEqual('Versionable'); expect(groupedProperties[0].title).toEqual('Versionable');
@@ -319,7 +319,7 @@ describe('ContentMetaDataService', () => {
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(verResponse)); spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(verResponse));
const groupedProperties = await service.getGroupedProperties(fakeContentNode).toPromise(); const groupedProperties = await firstValueFrom(service.getGroupedProperties(fakeContentNode));
expect(groupedProperties.length).toEqual(0); expect(groupedProperties.length).toEqual(0);
expect(classesApi.getClass).toHaveBeenCalledTimes(1 + fakeContentNode.aspectNames.length); expect(classesApi.getClass).toHaveBeenCalledTimes(1 + fakeContentNode.aspectNames.length);
@@ -335,7 +335,7 @@ describe('ContentMetaDataService', () => {
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(verResponse)); spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(verResponse));
const groupedProperties = await service.getGroupedProperties(fakeContentNode).toPromise(); const groupedProperties = await firstValueFrom(service.getGroupedProperties(fakeContentNode));
expect(groupedProperties.length).toEqual(1); expect(groupedProperties.length).toEqual(1);
expect(groupedProperties[0].title).toEqual('Versionable'); expect(groupedProperties[0].title).toEqual('Versionable');
@@ -351,7 +351,7 @@ describe('ContentMetaDataService', () => {
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(verResponse)); spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(verResponse));
const groupedProperties = await service.getGroupedProperties(fakeContentNode).toPromise(); const groupedProperties = await firstValueFrom(service.getGroupedProperties(fakeContentNode));
expect(groupedProperties.length).toEqual(0); expect(groupedProperties.length).toEqual(0);
expect(classesApi.getClass).toHaveBeenCalledTimes(1 + fakeContentNode.aspectNames.length); expect(classesApi.getClass).toHaveBeenCalledTimes(1 + fakeContentNode.aspectNames.length);
@@ -367,7 +367,7 @@ describe('ContentMetaDataService', () => {
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(exifResponse)); spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(exifResponse));
const groupedProperties = await service.getGroupedProperties(fakeNode).toPromise(); const groupedProperties = await firstValueFrom(service.getGroupedProperties(fakeNode));
expect(groupedProperties.length).toEqual(1); expect(groupedProperties.length).toEqual(1);
expect(groupedProperties[0].title).toEqual('Exif'); expect(groupedProperties[0].title).toEqual('Exif');
@@ -387,7 +387,7 @@ describe('ContentMetaDataService', () => {
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(exifResponse)); spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(exifResponse));
const groupedProperties = await service.getGroupedProperties(fakeNode).toPromise(); const groupedProperties = await firstValueFrom(service.getGroupedProperties(fakeNode));
expect(groupedProperties.length).toEqual(2); expect(groupedProperties.length).toEqual(2);
expect(groupedProperties[0].title).toEqual('Exif'); expect(groupedProperties[0].title).toEqual('Exif');

View File

@@ -18,7 +18,7 @@
import { Component, EventEmitter, Output } from '@angular/core'; import { Component, EventEmitter, Output } from '@angular/core';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog'; import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { BehaviorSubject, of, Subject } from 'rxjs'; import { BehaviorSubject, firstValueFrom, of, Subject } from 'rxjs';
import { mockFile, mockNewVersionUploaderData, mockNode } from '../mock'; import { mockFile, mockNewVersionUploaderData, mockNode } from '../mock';
import { ContentTestingModule } from '../testing/content.testing.module'; import { ContentTestingModule } from '../testing/content.testing.module';
import { import {
@@ -114,7 +114,7 @@ describe('NewVersionUploaderService', () => {
}); });
it('should open dialog with default configuration', fakeAsync(() => { it('should open dialog with default configuration', fakeAsync(() => {
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).toPromise(); firstValueFrom(service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData));
tick(); tick();
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig); expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig);
})); }));
@@ -124,7 +124,7 @@ describe('NewVersionUploaderService', () => {
panelClass: 'adf-custom-class', panelClass: 'adf-custom-class',
width: '500px' width: '500px'
}; };
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration).toPromise(); firstValueFrom(service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration));
tick(); tick();
expectedConfig.panelClass = 'adf-custom-class'; expectedConfig.panelClass = 'adf-custom-class';
expectedConfig.width = '500px'; expectedConfig.width = '500px';
@@ -135,7 +135,7 @@ describe('NewVersionUploaderService', () => {
const mockDialogConfiguration: MatDialogConfig = { const mockDialogConfiguration: MatDialogConfig = {
height: '600px' height: '600px'
}; };
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration).toPromise(); firstValueFrom(service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration));
tick(); tick();
expectedConfig.height = '600px'; expectedConfig.height = '600px';
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig); expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig);
@@ -143,7 +143,7 @@ describe('NewVersionUploaderService', () => {
it('should not override dialog configuration, if dialog configuration is empty', fakeAsync(() => { it('should not override dialog configuration, if dialog configuration is empty', fakeAsync(() => {
const mockDialogConfiguration: MatDialogConfig = {}; const mockDialogConfiguration: MatDialogConfig = {};
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration).toPromise(); firstValueFrom(service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration));
tick(); tick();
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig); expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig);
})); }));
@@ -156,7 +156,7 @@ describe('NewVersionUploaderService', () => {
showComments: true, showComments: true,
allowDownload: true allowDownload: true
}; };
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogDataWithVersionsOnly).toPromise(); firstValueFrom(service.openUploadNewVersionDialog(mockNewVersionUploaderDialogDataWithVersionsOnly));
tick(); tick();
expectedConfig.data.showVersionsOnly = true; expectedConfig.data.showVersionsOnly = true;
expectedConfig.panelClass = ['adf-new-version-uploader-dialog', 'adf-new-version-uploader-dialog-list']; expectedConfig.panelClass = ['adf-new-version-uploader-dialog', 'adf-new-version-uploader-dialog-list'];

View File

@@ -21,6 +21,7 @@ import { fakeAuthorityClearanceApiResponse } from './mock/security-authorities.m
import { fakeGroupsApiResponse, createNewSecurityGroupMock } from './mock/security-groups.mock'; import { fakeGroupsApiResponse, createNewSecurityGroupMock } from './mock/security-groups.mock';
import { fakeMarksApiResponse, createNewSecurityMarkMock } from './mock/security-marks.mock'; import { fakeMarksApiResponse, createNewSecurityMarkMock } from './mock/security-marks.mock';
import { SecurityGroupBody, SecurityMarkBody, SecurityMarkEntry } from '@alfresco/js-api'; import { SecurityGroupBody, SecurityMarkBody, SecurityMarkEntry } from '@alfresco/js-api';
import { firstValueFrom } from 'rxjs';
describe('SecurityControlsService', () => { describe('SecurityControlsService', () => {
let service: SecurityControlsService; let service: SecurityControlsService;
@@ -78,7 +79,7 @@ describe('SecurityControlsService', () => {
} }
}) })
); );
const response = await service.createSecurityGroup(createNewSecurityGroupMock).toPromise(); const response = await firstValueFrom(service.createSecurityGroup(createNewSecurityGroupMock));
securityGroupId = response.entry.id; securityGroupId = response.entry.id;
expect(response.entry.groupName).toEqual('TestGroup'); expect(response.entry.groupName).toEqual('TestGroup');
@@ -176,7 +177,7 @@ describe('SecurityControlsService', () => {
it('should delete a security group', async () => { it('should delete a security group', async () => {
spyOn(service.groupsApi, 'deleteSecurityGroup').and.returnValue(Promise.resolve()); spyOn(service.groupsApi, 'deleteSecurityGroup').and.returnValue(Promise.resolve());
await service.deleteSecurityGroup(securityGroupId).toPromise(); await firstValueFrom(service.deleteSecurityGroup(securityGroupId));
expect(service.groupsApi.deleteSecurityGroup).toHaveBeenCalled(); expect(service.groupsApi.deleteSecurityGroup).toHaveBeenCalled();
}); });
@@ -185,7 +186,7 @@ describe('SecurityControlsService', () => {
Promise.resolve(fakeAuthorityClearanceApiResponse) Promise.resolve(fakeAuthorityClearanceApiResponse)
); );
const clearancePromise = service.getClearancesForAuthority('test-id', 0, 10); const clearancePromise = service.getClearancesForAuthority('test-id', 0, 10);
const clearance = await clearancePromise.toPromise(); const clearance = await firstValueFrom(clearancePromise);
expect(getClearancesForAuthoritySpy).toHaveBeenCalledWith('test-id', { expect(getClearancesForAuthoritySpy).toHaveBeenCalledWith('test-id', {
skipCount: 0, skipCount: 0,
@@ -210,15 +211,15 @@ describe('SecurityControlsService', () => {
} }
}) })
); );
const response = (await service const response = (await firstValueFrom(
.updateClearancesForAuthority('test-id', [ service.updateClearancesForAuthority('test-id', [
{ {
groupId: 'test-group-id', groupId: 'test-group-id',
op: 'test-op', op: 'test-op',
id: 'test-id' id: 'test-id'
} }
]) ])
.toPromise()) as SecurityMarkEntry; )) as SecurityMarkEntry;
expect(response.entry.id).toEqual('test-id'); expect(response.entry.id).toEqual('test-id');
expect(response.entry.groupId).toEqual('test-groupId'); expect(response.entry.groupId).toEqual('test-groupId');

View File

@@ -19,7 +19,7 @@ import { AppConfigService, UserPreferencesService } from '@alfresco/adf-core';
import { TagService } from './tag.service'; import { TagService } from './tag.service';
import { fakeAsync, TestBed, tick } from '@angular/core/testing'; import { fakeAsync, TestBed, tick } from '@angular/core/testing';
import { ContentTestingModule } from '../../testing/content.testing.module'; import { ContentTestingModule } from '../../testing/content.testing.module';
import { throwError } from 'rxjs'; import { firstValueFrom, throwError } from 'rxjs';
import { Pagination, Tag, TagBody, TagEntry, TagPaging, TagPagingList } from '@alfresco/js-api'; import { Pagination, Tag, TagBody, TagEntry, TagPaging, TagPagingList } from '@alfresco/js-api';
describe('TagService', () => { describe('TagService', () => {
@@ -75,7 +75,7 @@ describe('TagService', () => {
let lastValue: any; let lastValue: any;
service.refresh.subscribe((res) => (lastValue = res)); service.refresh.subscribe((res) => (lastValue = res));
await service.addTag('fake-node-id', 'fake-tag').toPromise(); await firstValueFrom(service.addTag('fake-node-id', 'fake-tag'));
expect(lastValue).toBe(tagEntry); expect(lastValue).toBe(tagEntry);
}); });
@@ -83,7 +83,7 @@ describe('TagService', () => {
let lastValue = false; let lastValue = false;
service.refresh.subscribe(() => (lastValue = true)); service.refresh.subscribe(() => (lastValue = true));
await service.deleteTag('fake-tag-id').toPromise(); await firstValueFrom(service.deleteTag('fake-tag-id'));
expect(lastValue).toBeTrue(); expect(lastValue).toBeTrue();
}); });
@@ -110,7 +110,7 @@ describe('TagService', () => {
spyOn(service.refresh, 'emit'); spyOn(service.refresh, 'emit');
spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.resolve(tag)); spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.resolve(tag));
await service.createTags([]).toPromise(); await firstValueFrom(service.createTags([]));
expect(service.refresh.emit).toHaveBeenCalledWith(tag); expect(service.refresh.emit).toHaveBeenCalledWith(tag);
}); });
}); });
@@ -248,7 +248,7 @@ describe('TagService', () => {
it('should emit refresh when tag updated successfully', async () => { it('should emit refresh when tag updated successfully', async () => {
spyOn(service.refresh, 'emit'); spyOn(service.refresh, 'emit');
spyOn(service.tagsApi, 'updateTag').and.returnValue(Promise.resolve(updatedTag)); spyOn(service.tagsApi, 'updateTag').and.returnValue(Promise.resolve(updatedTag));
await service.updateTag(tag.entry.id, tagBody).toPromise(); await firstValueFrom(service.updateTag(tag.entry.id, tagBody));
expect(service.refresh.emit).toHaveBeenCalledWith(updatedTag); expect(service.refresh.emit).toHaveBeenCalledWith(updatedTag);
}); });
}); });

View File

@@ -19,7 +19,7 @@ import { SHOULD_ADD_AUTH_TOKEN } from '@alfresco/adf-core/auth';
import { Emitters as JsApiEmitters, HttpClient as JsApiHttpClient } from '@alfresco/js-api'; import { Emitters as JsApiEmitters, HttpClient as JsApiHttpClient } from '@alfresco/js-api';
import { HttpClient, HttpContext, HttpErrorResponse, HttpEvent, HttpHeaders, HttpParams, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpContext, HttpErrorResponse, HttpEvent, HttpHeaders, HttpParams, HttpResponse } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable, of, Subject, throwError } from 'rxjs'; import { lastValueFrom, Observable, of, Subject, throwError } from 'rxjs';
import { catchError, map, takeUntil } from 'rxjs/operators'; import { catchError, map, takeUntil } from 'rxjs/operators';
import { import {
convertObjectToFormData, convertObjectToFormData,
@@ -196,8 +196,8 @@ export class AdfHttpClient implements JsApiHttpClient {
const abort$ = new Subject<void>(); const abort$ = new Subject<void>();
const { eventEmitter, apiClientEmitter } = emitters; const { eventEmitter, apiClientEmitter } = emitters;
const promise = request$ const promise = lastValueFrom(
.pipe( request$.pipe(
map((res) => { map((res) => {
if (isHttpUploadProgressEvent(res)) { if (isHttpUploadProgressEvent(res)) {
const percent = Math.round((res.loaded / res.total) * 100); const percent = Math.round((res.loaded / res.total) * 100);
@@ -243,7 +243,7 @@ export class AdfHttpClient implements JsApiHttpClient {
}), }),
takeUntil(abort$) takeUntil(abort$)
) )
.toPromise(); );
(promise as any).abort = function () { (promise as any).abort = function () {
eventEmitter.emit('abort'); eventEmitter.emit('abort');

View File

@@ -27,7 +27,7 @@ import {
IdentityJoinGroupRequestModel IdentityJoinGroupRequestModel
} from '../interfaces/identity-user.service.interface'; } from '../interfaces/identity-user.service.interface';
import { mockIdentityGroups } from './identity-group.mock'; import { mockIdentityGroups } from './identity-group.mock';
import { Observable, of } from 'rxjs'; import { firstValueFrom, Observable, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators'; import { map, switchMap } from 'rxjs/operators';
import { mockAssignedRoles, mockAvailableRoles, mockEffectiveRoles, mockIdentityUser1, mockIdentityUsers } from './identity-user.mock'; import { mockAssignedRoles, mockAvailableRoles, mockEffectiveRoles, mockIdentityUser1, mockIdentityUsers } from './identity-user.mock';
@@ -127,7 +127,7 @@ export class IdentityUserServiceMock implements IdentityUserServiceInterface {
async getUsersByRolesWithCurrentUser(roleNames: string[]): Promise<IdentityUserModel[]> { async getUsersByRolesWithCurrentUser(roleNames: string[]): Promise<IdentityUserModel[]> {
const filteredUsers: IdentityUserModel[] = []; const filteredUsers: IdentityUserModel[] = [];
if (roleNames && roleNames.length > 0) { if (roleNames && roleNames.length > 0) {
const users = await this.getUsers().toPromise(); const users = await firstValueFrom(this.getUsers());
for (let i = 0; i < users.length; i++) { for (let i = 0; i < users.length; i++) {
const hasAnyRole = await this.userHasAnyRole(users[i].id, roleNames); const hasAnyRole = await this.userHasAnyRole(users[i].id, roleNames);
@@ -144,7 +144,7 @@ export class IdentityUserServiceMock implements IdentityUserServiceInterface {
const filteredUsers: IdentityUserModel[] = []; const filteredUsers: IdentityUserModel[] = [];
if (roleNames && roleNames.length > 0) { if (roleNames && roleNames.length > 0) {
const currentUser = this.getCurrentUserInfo(); const currentUser = this.getCurrentUserInfo();
let users = await this.getUsers().toPromise(); let users = await firstValueFrom(this.getUsers());
users = users.filter(({ username }) => username !== currentUser.username); users = users.filter(({ username }) => username !== currentUser.username);
@@ -160,7 +160,7 @@ export class IdentityUserServiceMock implements IdentityUserServiceInterface {
} }
private async userHasAnyRole(userId: string, roleNames: string[]): Promise<boolean> { private async userHasAnyRole(userId: string, roleNames: string[]): Promise<boolean> {
const userRoles = await this.getUserRoles(userId).toPromise(); const userRoles = await firstValueFrom(this.getUserRoles(userId));
const hasAnyRole = roleNames.some((roleName) => { const hasAnyRole = roleNames.some((roleName) => {
const filteredRoles = userRoles.filter((userRole) => userRole.name.toLocaleLowerCase() === roleName.toLocaleLowerCase()); const filteredRoles = userRoles.filter((userRole) => userRole.name.toLocaleLowerCase() === roleName.toLocaleLowerCase());

View File

@@ -17,7 +17,7 @@
import { HttpClientTestingModule } from '@angular/common/http/testing'; import { HttpClientTestingModule } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { EMPTY } from 'rxjs'; import { of } from 'rxjs';
import { AppConfigService } from '../../app-config/app-config.service'; import { AppConfigService } from '../../app-config/app-config.service';
import { AUTH_MODULE_CONFIG } from './auth-config'; import { AUTH_MODULE_CONFIG } from './auth-config';
import { AuthConfigService } from './auth-config.service'; import { AuthConfigService } from './auth-config.service';
@@ -102,7 +102,7 @@ describe('AuthConfigService', () => {
spyOn<any>(service, 'getLocationOrigin').and.returnValue('http://localhost:3000'); spyOn<any>(service, 'getLocationOrigin').and.returnValue('http://localhost:3000');
appConfigService = TestBed.inject(AppConfigService); appConfigService = TestBed.inject(AppConfigService);
appConfigService.onLoad = EMPTY; appConfigService.onLoad = of(true);
}); });
describe('load auth config using hash', () => { describe('load auth config using hash', () => {

View File

@@ -21,6 +21,7 @@ import { take } from 'rxjs/operators';
import { AppConfigService } from '../../app-config/app-config.service'; import { AppConfigService } from '../../app-config/app-config.service';
import { AUTH_MODULE_CONFIG, AuthModuleConfig } from './auth-config'; import { AUTH_MODULE_CONFIG, AuthModuleConfig } from './auth-config';
import { OauthConfigModel } from '../models/oauth-config.model'; import { OauthConfigModel } from '../models/oauth-config.model';
import { firstValueFrom } from 'rxjs';
/** /**
* Create auth configuration factory * Create auth configuration factory
@@ -36,7 +37,10 @@ export function authConfigFactory(authConfigService: AuthConfigService): Promise
providedIn: 'root' providedIn: 'root'
}) })
export class AuthConfigService { export class AuthConfigService {
constructor(private appConfigService: AppConfigService, @Inject(AUTH_MODULE_CONFIG) private readonly authModuleConfig: AuthModuleConfig) {} constructor(
private appConfigService: AppConfigService,
@Inject(AUTH_MODULE_CONFIG) private readonly authModuleConfig: AuthModuleConfig
) {}
private _authConfig!: AuthConfig; private _authConfig!: AuthConfig;
get authConfig(): AuthConfig { get authConfig(): AuthConfig {
@@ -44,7 +48,7 @@ export class AuthConfigService {
} }
loadConfig(): Promise<AuthConfig> { loadConfig(): Promise<AuthConfig> {
return this.appConfigService.onLoad.pipe(take(1)).toPromise().then(this.loadAppConfig.bind(this)); return firstValueFrom(this.appConfigService.onLoad.pipe(take(1))).then(this.loadAppConfig.bind(this));
} }
loadAppConfig(): AuthConfig { loadAppConfig(): AuthConfig {

View File

@@ -214,7 +214,7 @@ describe('OidcAuthenticationService shouldPerformSsoLogin', () => {
}; };
configureTestingModule({ provide: AuthService, useValue: mockAuthServiceValue }); configureTestingModule({ provide: AuthService, useValue: mockAuthServiceValue });
const shouldPerformSsoLogin = await service.shouldPerformSsoLogin$.toPromise(); const shouldPerformSsoLogin = await firstValueFrom(service.shouldPerformSsoLogin$);
expect(shouldPerformSsoLogin).toBeTrue(); expect(shouldPerformSsoLogin).toBeTrue();
}); });
@@ -225,7 +225,7 @@ describe('OidcAuthenticationService shouldPerformSsoLogin', () => {
}; };
configureTestingModule({ provide: AuthService, useValue: mockAuthServiceValue }); configureTestingModule({ provide: AuthService, useValue: mockAuthServiceValue });
const shouldPerformSsoLogin = await service.shouldPerformSsoLogin$.toPromise(); const shouldPerformSsoLogin = await firstValueFrom(service.shouldPerformSsoLogin$);
expect(shouldPerformSsoLogin).toBeFalse(); expect(shouldPerformSsoLogin).toBeFalse();
}); });
@@ -236,7 +236,7 @@ describe('OidcAuthenticationService shouldPerformSsoLogin', () => {
}; };
configureTestingModule({ provide: AuthService, useValue: mockAuthServiceValue }); configureTestingModule({ provide: AuthService, useValue: mockAuthServiceValue });
const shouldPerformSsoLogin = await service.shouldPerformSsoLogin$.toPromise(); const shouldPerformSsoLogin = await firstValueFrom(service.shouldPerformSsoLogin$);
expect(shouldPerformSsoLogin).toBeFalse(); expect(shouldPerformSsoLogin).toBeFalse();
}); });
@@ -247,7 +247,7 @@ describe('OidcAuthenticationService shouldPerformSsoLogin', () => {
}; };
configureTestingModule({ provide: AuthService, useValue: mockAuthServiceValue }); configureTestingModule({ provide: AuthService, useValue: mockAuthServiceValue });
const shouldPerformSsoLogin = await service.shouldPerformSsoLogin$.toPromise(); const shouldPerformSsoLogin = await firstValueFrom(service.shouldPerformSsoLogin$);
expect(shouldPerformSsoLogin).toBeFalse(); expect(shouldPerformSsoLogin).toBeFalse();
}); });
}); });

View File

@@ -28,7 +28,7 @@ import {
OAuthSuccessEvent, OAuthSuccessEvent,
OAuthInfoEvent OAuthInfoEvent
} from 'angular-oauth2-oidc'; } from 'angular-oauth2-oidc';
import { of, Subject, timeout } from 'rxjs'; import { firstValueFrom, of, Subject, timeout } from 'rxjs';
import { RedirectAuthService } from './redirect-auth.service'; import { RedirectAuthService } from './redirect-auth.service';
import { AUTH_MODULE_CONFIG } from './auth-config'; import { AUTH_MODULE_CONFIG } from './auth-config';
import { RetryLoginService } from './retry-login.service'; import { RetryLoginService } from './retry-login.service';
@@ -389,8 +389,8 @@ describe('RedirectAuthService', () => {
it('should NOT logout user if the refresh token failed first time', fakeAsync(async () => { it('should NOT logout user if the refresh token failed first time', fakeAsync(async () => {
const expectedFakeErrorEvent = new OAuthErrorEvent('token_refresh_error', { reason: 'error' }, {}); const expectedFakeErrorEvent = new OAuthErrorEvent('token_refresh_error', { reason: 'error' }, {});
const firstEventOccurPromise = service.firstOauthErrorEventOccur$.toPromise(); const firstEventOccurPromise = firstValueFrom(service.firstOauthErrorEventOccur$);
const secondTokenRefreshErrorEventPromise = service.secondTokenRefreshErrorEventOccur$.pipe(timeout(1000)).toPromise(); const secondTokenRefreshErrorEventPromise = firstValueFrom(service.secondTokenRefreshErrorEventOccur$.pipe(timeout(1000)));
oauthEvents$.next(new OAuthErrorEvent('token_refresh_error', { reason: 'error' }, {})); oauthEvents$.next(new OAuthErrorEvent('token_refresh_error', { reason: 'error' }, {}));

View File

@@ -16,7 +16,7 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs'; import { firstValueFrom, Observable, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators'; import { map, switchMap } from 'rxjs/operators';
import { AppConfigService } from '../../app-config/app-config.service'; import { AppConfigService } from '../../app-config/app-config.service';
import { IdentityGroupModel } from '../models/identity-group.model'; import { IdentityGroupModel } from '../models/identity-group.model';
@@ -36,7 +36,11 @@ import { OAuth2Service } from './oauth2.service';
providedIn: 'root' providedIn: 'root'
}) })
export class IdentityUserService implements IdentityUserServiceInterface { export class IdentityUserService implements IdentityUserServiceInterface {
constructor(private jwtHelperService: JwtHelperService, private oAuth2Service: OAuth2Service, private appConfigService: AppConfigService) {} constructor(
private jwtHelperService: JwtHelperService,
private oAuth2Service: OAuth2Service,
private appConfigService: AppConfigService
) {}
private get identityHost(): string { private get identityHost(): string {
return `${this.appConfigService.get('identityHost')}`; return `${this.appConfigService.get('identityHost')}`;
@@ -239,7 +243,7 @@ export class IdentityUserService implements IdentityUserServiceInterface {
async getUsersByRolesWithCurrentUser(roleNames: string[]): Promise<IdentityUserModel[]> { async getUsersByRolesWithCurrentUser(roleNames: string[]): Promise<IdentityUserModel[]> {
const filteredUsers: IdentityUserModel[] = []; const filteredUsers: IdentityUserModel[] = [];
if (roleNames && roleNames.length > 0) { if (roleNames && roleNames.length > 0) {
const users = await this.getUsers().toPromise(); const users = await firstValueFrom(this.getUsers());
for (let i = 0; i < users.length; i++) { for (let i = 0; i < users.length; i++) {
const hasAnyRole = await this.userHasAnyRole(users[i].id, roleNames); const hasAnyRole = await this.userHasAnyRole(users[i].id, roleNames);
@@ -262,7 +266,7 @@ export class IdentityUserService implements IdentityUserServiceInterface {
const filteredUsers: IdentityUserModel[] = []; const filteredUsers: IdentityUserModel[] = [];
if (roleNames && roleNames.length > 0) { if (roleNames && roleNames.length > 0) {
const currentUser = this.getCurrentUserInfo(); const currentUser = this.getCurrentUserInfo();
let users = await this.getUsers().toPromise(); let users = await firstValueFrom(this.getUsers());
users = users.filter(({ username }) => username !== currentUser.username); users = users.filter(({ username }) => username !== currentUser.username);
@@ -278,7 +282,7 @@ export class IdentityUserService implements IdentityUserServiceInterface {
} }
private async userHasAnyRole(userId: string, roleNames: string[]): Promise<boolean> { private async userHasAnyRole(userId: string, roleNames: string[]): Promise<boolean> {
const userRoles = await this.getUserRoles(userId).toPromise(); const userRoles = await firstValueFrom(this.getUserRoles(userId));
const hasAnyRole = roleNames.some((roleName) => { const hasAnyRole = roleNames.some((roleName) => {
const filteredRoles = userRoles.filter((userRole) => userRole.name.toLocaleLowerCase() === roleName.toLocaleLowerCase()); const filteredRoles = userRoles.filter((userRole) => userRole.name.toLocaleLowerCase() === roleName.toLocaleLowerCase());
@@ -337,7 +341,7 @@ export class IdentityUserService implements IdentityUserServiceInterface {
hasMoreItems: false, hasMoreItems: false,
totalItems: totalCount totalItems: totalCount
} }
} as IdentityUserQueryResponse) }) as IdentityUserQueryResponse
) )
) )
) )

View File

@@ -19,6 +19,7 @@ import { HttpClientTestingModule, HttpTestingController } from '@angular/common/
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { AppConfigService } from '../../app-config/app-config.service'; import { AppConfigService } from '../../app-config/app-config.service';
import { TimeSyncService } from './time-sync.service'; import { TimeSyncService } from './time-sync.service';
import { firstValueFrom } from 'rxjs';
describe('TimeSyncService', () => { describe('TimeSyncService', () => {
let service: TimeSyncService; let service: TimeSyncService;
@@ -30,10 +31,7 @@ describe('TimeSyncService', () => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [HttpClientTestingModule], imports: [HttpClientTestingModule],
providers: [ providers: [TimeSyncService, { provide: AppConfigService, useValue: appConfigSpy }]
TimeSyncService,
{ provide: AppConfigService, useValue: appConfigSpy }
]
}); });
service = TestBed.inject(TimeSyncService); service = TestBed.inject(TimeSyncService);
@@ -45,7 +43,6 @@ describe('TimeSyncService', () => {
}); });
describe('checkTimeSync', () => { describe('checkTimeSync', () => {
it('should check time sync and return outOfSync as false when time is within allowed skew', () => { it('should check time sync and return outOfSync as false when time is within allowed skew', () => {
appConfigSpy.get.and.returnValue('http://fake-server-time-url'); appConfigSpy.get.and.returnValue('http://fake-server-time-url');
@@ -58,15 +55,11 @@ describe('TimeSyncService', () => {
const serverTime = 1728911640000; // (GMT): Monday, October 14, 2024 1:14:00 PM const serverTime = 1728911640000; // (GMT): Monday, October 14, 2024 1:14:00 PM
spyOn(Date, 'now').and.returnValues( spyOn(Date, 'now').and.returnValues(timeBeforeCallingServerTimeEndpoint, timeResponseReceivedFromServerTimeEndpoint, localCurrentTime);
timeBeforeCallingServerTimeEndpoint,
timeResponseReceivedFromServerTimeEndpoint,
localCurrentTime
);
// difference between localCurrentTime and serverTime is 60 seconds plus the round trip time of 1 second // difference between localCurrentTime and serverTime is 60 seconds plus the round trip time of 1 second
const allowedClockSkewInSec = 61; const allowedClockSkewInSec = 61;
service.checkTimeSync(allowedClockSkewInSec).subscribe(sync => { service.checkTimeSync(allowedClockSkewInSec).subscribe((sync) => {
expect(sync.outOfSync).toBeFalse(); expect(sync.outOfSync).toBeFalse();
expect(sync.localDateTimeISO).toEqual('2024-10-14T13:13:00.000Z'); expect(sync.localDateTimeISO).toEqual('2024-10-14T13:13:00.000Z');
expect(sync.serverDateTimeISO).toEqual('2024-10-14T13:14:00.500Z'); expect(sync.serverDateTimeISO).toEqual('2024-10-14T13:14:00.500Z');
@@ -89,16 +82,12 @@ describe('TimeSyncService', () => {
const serverTime = 1728911640000; // (GMT): Monday, October 14, 2024 1:14:00 PM const serverTime = 1728911640000; // (GMT): Monday, October 14, 2024 1:14:00 PM
spyOn(Date, 'now').and.returnValues( spyOn(Date, 'now').and.returnValues(timeBeforeCallingServerTimeEndpoint, timeResponseReceivedFromServerTimeEndpoint, localCurrentTime);
timeBeforeCallingServerTimeEndpoint,
timeResponseReceivedFromServerTimeEndpoint,
localCurrentTime
);
// difference between localCurrentTime and serverTime is 60 seconds plus the round trip time of 1 second // difference between localCurrentTime and serverTime is 60 seconds plus the round trip time of 1 second
// setting allowedClockSkewInSec to 60 seconds will make the local time out of sync // setting allowedClockSkewInSec to 60 seconds will make the local time out of sync
const allowedClockSkewInSec = 60; const allowedClockSkewInSec = 60;
service.checkTimeSync(allowedClockSkewInSec).subscribe(sync => { service.checkTimeSync(allowedClockSkewInSec).subscribe((sync) => {
expect(sync.outOfSync).toBeTrue(); expect(sync.outOfSync).toBeTrue();
expect(sync.localDateTimeISO).toEqual('2024-10-14T13:13:00.000Z'); expect(sync.localDateTimeISO).toEqual('2024-10-14T13:13:00.000Z');
expect(sync.serverDateTimeISO).toEqual('2024-10-14T13:14:00.500Z'); expect(sync.serverDateTimeISO).toEqual('2024-10-14T13:14:00.500Z');
@@ -113,12 +102,11 @@ describe('TimeSyncService', () => {
appConfigSpy.get.and.returnValue(''); appConfigSpy.get.and.returnValue('');
try { try {
await service.checkTimeSync(60).toPromise(); await firstValueFrom(service.checkTimeSync(60));
fail('Expected to throw an error'); fail('Expected to throw an error');
} catch (error) { } catch (error) {
expect(error.message).toBe('serverTimeUrl is not configured.'); expect(error.message).toBe('serverTimeUrl is not configured.');
} }
}); });
it('should throw an error if the server time endpoint returns an error', () => { it('should throw an error if the server time endpoint returns an error', () => {
@@ -130,7 +118,7 @@ describe('TimeSyncService', () => {
next: () => { next: () => {
fail('Expected to throw an error'); fail('Expected to throw an error');
}, },
error: error => { error: (error) => {
expect(error.message).toBe('Error: Failed to get server time'); expect(error.message).toBe('Error: Failed to get server time');
} }
}); });
@@ -139,12 +127,10 @@ describe('TimeSyncService', () => {
expect(req.request.method).toBe('GET'); expect(req.request.method).toBe('GET');
req.error(new ProgressEvent('')); req.error(new ProgressEvent(''));
}); });
}); });
describe('isLocalTimeOutOfSync', () => { describe('isLocalTimeOutOfSync', () => {
it('should return clock is out of sync', () => { it('should return clock is out of sync', () => {
appConfigSpy.get.and.returnValue('http://fake-server-time-url'); appConfigSpy.get.and.returnValue('http://fake-server-time-url');
const expectedServerTimeUrl = 'http://fake-server-time-url'; const expectedServerTimeUrl = 'http://fake-server-time-url';
@@ -156,16 +142,12 @@ describe('TimeSyncService', () => {
const serverTime = 1728911640000; // (GMT): Monday, October 14, 2024 1:14:00 PM const serverTime = 1728911640000; // (GMT): Monday, October 14, 2024 1:14:00 PM
spyOn(Date, 'now').and.returnValues( spyOn(Date, 'now').and.returnValues(timeBeforeCallingServerTimeEndpoint, timeResponseReceivedFromServerTimeEndpoint, localCurrentTime);
timeBeforeCallingServerTimeEndpoint,
timeResponseReceivedFromServerTimeEndpoint,
localCurrentTime
);
// difference between localCurrentTime and serverTime is 60 seconds plus the round trip time of 1 second // difference between localCurrentTime and serverTime is 60 seconds plus the round trip time of 1 second
// setting allowedClockSkewInSec to 60 seconds will make the local time out of sync // setting allowedClockSkewInSec to 60 seconds will make the local time out of sync
const allowedClockSkewInSec = 60; const allowedClockSkewInSec = 60;
service.isLocalTimeOutOfSync(allowedClockSkewInSec).subscribe(isOutOfSync => { service.isLocalTimeOutOfSync(allowedClockSkewInSec).subscribe((isOutOfSync) => {
expect(isOutOfSync).toBeTrue(); expect(isOutOfSync).toBeTrue();
}); });
@@ -186,15 +168,11 @@ describe('TimeSyncService', () => {
const serverTime = 1728911640000; // (GMT): Monday, October 14, 2024 1:14:00 PM const serverTime = 1728911640000; // (GMT): Monday, October 14, 2024 1:14:00 PM
spyOn(Date, 'now').and.returnValues( spyOn(Date, 'now').and.returnValues(timeBeforeCallingServerTimeEndpoint, timeResponseReceivedFromServerTimeEndpoint, localCurrentTime);
timeBeforeCallingServerTimeEndpoint,
timeResponseReceivedFromServerTimeEndpoint,
localCurrentTime
);
// difference between localCurrentTime and serverTime is 60 seconds plus the round trip time of 1 second // difference between localCurrentTime and serverTime is 60 seconds plus the round trip time of 1 second
const allowedClockSkewInSec = 61; const allowedClockSkewInSec = 61;
service.isLocalTimeOutOfSync(allowedClockSkewInSec).subscribe(isOutOfSync => { service.isLocalTimeOutOfSync(allowedClockSkewInSec).subscribe((isOutOfSync) => {
expect(isOutOfSync).toBeFalse(); expect(isOutOfSync).toBeFalse();
}); });
@@ -203,6 +181,4 @@ describe('TimeSyncService', () => {
req.flush(serverTime); req.flush(serverTime);
}); });
}); });
}); });

View File

@@ -35,6 +35,7 @@ import { UnitTestingUtils } from '../../../testing/unit-testing-utils';
import { HarnessLoader } from '@angular/cdk/testing'; import { HarnessLoader } from '@angular/cdk/testing';
import { ConfigurableFocusTrapFactory } from '@angular/cdk/a11y'; import { ConfigurableFocusTrapFactory } from '@angular/cdk/a11y';
import { provideRouter } from '@angular/router'; import { provideRouter } from '@angular/router';
import { firstValueFrom } from 'rxjs';
@Component({ @Component({
selector: 'adf-custom-column-template-component', selector: 'adf-custom-column-template-component',
@@ -1353,7 +1354,7 @@ describe('DataTable', () => {
expect(rows[1].isSelected).toBeFalsy(); expect(rows[1].isSelected).toBeFalsy();
dataTable.resetSelection(); dataTable.resetSelection();
const rowClickPromise = dataTable.rowClick.pipe(take(1)).toPromise(); const rowClickPromise = firstValueFrom(dataTable.rowClick.pipe(take(1)));
testingUtils.clickByCSS('[data-automation-id="datatable-row-0"] > div'); testingUtils.clickByCSS('[data-automation-id="datatable-row-0"] > div');
fixture.detectChanges(); fixture.detectChanges();
await rowClickPromise; await rowClickPromise;
@@ -1363,7 +1364,7 @@ describe('DataTable', () => {
expect(rows2[1].isSelected).toBeFalsy(); expect(rows2[1].isSelected).toBeFalsy();
dataTable.resetSelection(); dataTable.resetSelection();
const cellClickPromise = dataTable.rowClick.pipe(take(1)).toPromise(); const cellClickPromise = firstValueFrom(dataTable.rowClick.pipe(take(1)));
testingUtils.clickByCSS('[data-automation-id="datatable-row-1"] > div'); testingUtils.clickByCSS('[data-automation-id="datatable-row-1"] > div');
fixture.detectChanges(); fixture.detectChanges();
await cellClickPromise; await cellClickPromise;

View File

@@ -46,7 +46,7 @@ import { MatDialog } from '@angular/material/dialog';
import { MatDialogHarness } from '@angular/material/dialog/testing'; import { MatDialogHarness } from '@angular/material/dialog/testing';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { TranslateLoader, TranslateService, provideTranslateService } from '@ngx-translate/core'; import { TranslateLoader, TranslateService, provideTranslateService } from '@ngx-translate/core';
import { Observable, of, throwError } from 'rxjs'; import { firstValueFrom, Observable, of, throwError } from 'rxjs';
import { import {
cloudFormMock, cloudFormMock,
conditionalUploadWidgetsMock, conditionalUploadWidgetsMock,
@@ -1616,7 +1616,7 @@ describe('Multilingual Form', () => {
formComponent.ngOnChanges({ appName: new SimpleChange(null, appName, true) }); formComponent.ngOnChanges({ appName: new SimpleChange(null, appName, true) });
expect(formCloudService.getForm).toHaveBeenCalledWith(appName, formId, 1); expect(formCloudService.getForm).toHaveBeenCalledWith(appName, formId, 1);
await translateService.use('fr').toPromise(); await firstValueFrom(translateService.use('fr'));
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
@@ -1626,7 +1626,7 @@ describe('Multilingual Form', () => {
expect(getLabelValue('dateField')).toEqual('Champ de date (D-M-YYYY)'); expect(getLabelValue('dateField')).toEqual('Champ de date (D-M-YYYY)');
expect(getLabelValue('amountField')).toEqual('Champ Montant'); expect(getLabelValue('amountField')).toEqual('Champ Montant');
await translateService.use('en').toPromise(); await firstValueFrom(translateService.use('en'));
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();

View File

@@ -20,7 +20,7 @@ import { NotificationService } from '@alfresco/adf-core';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { ContentNodeSelectorComponent, ContentNodeSelectorComponentData, NodeAction, AlfrescoApiService } from '@alfresco/adf-content-services'; import { ContentNodeSelectorComponent, ContentNodeSelectorComponentData, NodeAction, AlfrescoApiService } from '@alfresco/adf-content-services';
import { Node, NodeEntry, NodesApi } from '@alfresco/js-api'; import { Node, NodeEntry, NodesApi } from '@alfresco/js-api';
import { from, Observable, Subject, throwError } from 'rxjs'; import { firstValueFrom, from, Observable, Subject, throwError } from 'rxjs';
import { catchError, map, mapTo } from 'rxjs/operators'; import { catchError, map, mapTo } from 'rxjs/operators';
import { DestinationFolderPathModel } from '../models/form-cloud-representation.model'; import { DestinationFolderPathModel } from '../models/form-cloud-representation.model';
@@ -36,7 +36,11 @@ export class ContentCloudNodeSelectorService {
sourceNodeNotFound = false; sourceNodeNotFound = false;
constructor(private apiService: AlfrescoApiService, private notificationService: NotificationService, private dialog: MatDialog) {} constructor(
private apiService: AlfrescoApiService,
private notificationService: NotificationService,
private dialog: MatDialog
) {}
openUploadFileDialog( openUploadFileDialog(
currentFolderId?: string, currentFolderId?: string,
@@ -65,25 +69,25 @@ export class ContentCloudNodeSelectorService {
async getNodeIdFromPath(destinationFolderPath: DestinationFolderPathModel): Promise<string> { async getNodeIdFromPath(destinationFolderPath: DestinationFolderPathModel): Promise<string> {
if (destinationFolderPath.alias && destinationFolderPath.path) { if (destinationFolderPath.alias && destinationFolderPath.path) {
try { try {
return await this.getNodeId(destinationFolderPath.alias, destinationFolderPath.path).toPromise(); return await firstValueFrom(this.getNodeId(destinationFolderPath.alias, destinationFolderPath.path));
} catch { } catch {
/*empty*/ /*empty*/
} }
} }
return this.getNodeId(destinationFolderPath.alias).toPromise(); return firstValueFrom(this.getNodeId(destinationFolderPath.alias));
} }
async getNodeIdFromFolderVariableValue(variableValue: string, defaultAlias?: string): Promise<string> { async getNodeIdFromFolderVariableValue(variableValue: string, defaultAlias?: string): Promise<string> {
const isExistingNode = await this.isExistingNode(variableValue); const isExistingNode = await this.isExistingNode(variableValue);
return isExistingNode ? variableValue : this.getNodeId(defaultAlias).toPromise(); return isExistingNode ? variableValue : firstValueFrom(this.getNodeId(defaultAlias));
} }
async isExistingNode(nodeId: string): Promise<boolean> { async isExistingNode(nodeId: string): Promise<boolean> {
let isExistingNode = false; let isExistingNode = false;
if (nodeId) { if (nodeId) {
try { try {
isExistingNode = await this.getNodeId(nodeId).pipe(mapTo(true)).toPromise(); isExistingNode = await firstValueFrom(this.getNodeId(nodeId).pipe(mapTo(true)));
} catch { } catch {
/*empty*/ /*empty*/
} }

View File

@@ -31,7 +31,7 @@ import {
} from '@angular/core'; } from '@angular/core';
import { ReactiveFormsModule, UntypedFormControl } from '@angular/forms'; import { ReactiveFormsModule, UntypedFormControl } from '@angular/forms';
import { animate, state, style, transition, trigger } from '@angular/animations'; import { animate, state, style, transition, trigger } from '@angular/animations';
import { BehaviorSubject, Observable } from 'rxjs'; import { BehaviorSubject, firstValueFrom, Observable } from 'rxjs';
import { debounceTime, distinctUntilChanged, filter, mergeMap, switchMap, tap } from 'rxjs/operators'; import { debounceTime, distinctUntilChanged, filter, mergeMap, switchMap, tap } from 'rxjs/operators';
import { ComponentSelectionMode } from '../../types'; import { ComponentSelectionMode } from '../../types';
import { IdentityGroupModel } from '../models/identity-group.model'; import { IdentityGroupModel } from '../models/identity-group.model';
@@ -248,7 +248,7 @@ export class GroupCloudComponent implements OnInit, OnChanges {
} }
private async searchGroup(name: string): Promise<IdentityGroupModel> { private async searchGroup(name: string): Promise<IdentityGroupModel> {
return (await this.identityGroupService.search(name).toPromise())[0]; return (await firstValueFrom(this.identityGroupService.search(name)))[0];
} }
private getPreselectedGroups(): IdentityGroupModel[] { private getPreselectedGroups(): IdentityGroupModel[] {

View File

@@ -31,7 +31,7 @@ import {
ViewChild, ViewChild,
ViewEncapsulation ViewEncapsulation
} from '@angular/core'; } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs'; import { BehaviorSubject, firstValueFrom, Observable } from 'rxjs';
import { debounceTime, distinctUntilChanged, filter, mergeMap, switchMap, tap } from 'rxjs/operators'; import { debounceTime, distinctUntilChanged, filter, mergeMap, switchMap, tap } from 'rxjs/operators';
import { FullNamePipe, InitialUsernamePipe } from '@alfresco/adf-core'; import { FullNamePipe, InitialUsernamePipe } from '@alfresco/adf-core';
import { animate, state, style, transition, trigger } from '@angular/animations'; import { animate, state, style, transition, trigger } from '@angular/animations';
@@ -368,9 +368,13 @@ export class PeopleCloudComponent implements OnInit, OnChanges, AfterViewInit {
for (const user of this.getPreselectedUsers()) { for (const user of this.getPreselectedUsers()) {
try { try {
const validationResult = ( const validationResult = (
await this.identityUserService await firstValueFrom(
.search(user.username, { roles: this.roles, withinApplication: this.appName, groups: this.groupsRestriction }) this.identityUserService.search(user.username, {
.toPromise() roles: this.roles,
withinApplication: this.appName,
groups: this.groupsRestriction
})
)
)[0]; )[0];
if (!this.equalsUsers(user, validationResult)) { if (!this.equalsUsers(user, validationResult)) {

View File

@@ -246,7 +246,7 @@ describe('ProcessFilterCloudService', () => {
changedFilter.processDefinitionKey = 'modifiedProcessDefinitionKey'; changedFilter.processDefinitionKey = 'modifiedProcessDefinitionKey';
spyOn<any>(service, 'defaultProcessFilters').and.returnValue(fakeProcessCloudFilters); spyOn<any>(service, 'defaultProcessFilters').and.returnValue(fakeProcessCloudFilters);
await service.resetProcessFilterToDefaults('mock-appName', changedFilter).toPromise(); await firstValueFrom(service.resetProcessFilterToDefaults('mock-appName', changedFilter));
expect(updatePreferenceSpy).toHaveBeenCalledWith('mock-appName', 'process-filters-mock-appName-mock-username', fakeProcessCloudFilters); expect(updatePreferenceSpy).toHaveBeenCalledWith('mock-appName', 'process-filters-mock-appName-mock-username', fakeProcessCloudFilters);
}); });

View File

@@ -182,7 +182,7 @@ describe('ProcessListCloudService', () => {
it('should append to the call all the parameters', async () => { it('should append to the call all the parameters', async () => {
const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ProcessQueryCloudRequestModel; const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ProcessQueryCloudRequestModel;
requestSpy.and.callFake(returnCallQueryParameters); requestSpy.and.callFake(returnCallQueryParameters);
const request = await service.getAdminProcessByRequest(processRequest).toPromise(); const request = await firstValueFrom(service.getAdminProcessByRequest(processRequest));
expect(request).toBeDefined(); expect(request).toBeDefined();
expect(request).not.toBeNull(); expect(request).not.toBeNull();
@@ -194,7 +194,7 @@ describe('ProcessListCloudService', () => {
it('should concat the app name to the request url', async () => { it('should concat the app name to the request url', async () => {
const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ProcessQueryCloudRequestModel; const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ProcessQueryCloudRequestModel;
requestSpy.and.callFake(returnCallUrl); requestSpy.and.callFake(returnCallUrl);
const requestUrl = await service.getAdminProcessByRequest(processRequest).toPromise(); const requestUrl = await firstValueFrom(service.getAdminProcessByRequest(processRequest));
expect(requestUrl).toBeDefined(); expect(requestUrl).toBeDefined();
expect(requestUrl).not.toBeNull(); expect(requestUrl).not.toBeNull();
@@ -213,7 +213,7 @@ describe('ProcessListCloudService', () => {
] ]
} as ProcessQueryCloudRequestModel; } as ProcessQueryCloudRequestModel;
requestSpy.and.callFake(returnCallQueryParameters); requestSpy.and.callFake(returnCallQueryParameters);
const request = await service.getAdminProcessByRequest(processRequest).toPromise(); const request = await firstValueFrom(service.getAdminProcessByRequest(processRequest));
expect(request).toBeDefined(); expect(request).toBeDefined();
expect(request).not.toBeNull(); expect(request).not.toBeNull();
@@ -225,7 +225,7 @@ describe('ProcessListCloudService', () => {
requestSpy.and.callFake(returnCallUrl); requestSpy.and.callFake(returnCallUrl);
try { try {
await service.getAdminProcessByRequest(processRequest).toPromise(); await firstValueFrom(service.getAdminProcessByRequest(processRequest));
fail('Should have thrown error'); fail('Should have thrown error');
} catch (error) { } catch (error) {
@@ -236,7 +236,7 @@ describe('ProcessListCloudService', () => {
it('should make post request', async () => { it('should make post request', async () => {
const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ProcessQueryCloudRequestModel; const processRequest = { appName: 'fakeName', skipCount: 0, maxItems: 20, service: 'fake-service' } as ProcessQueryCloudRequestModel;
requestSpy.and.callFake(returnCallOperation); requestSpy.and.callFake(returnCallOperation);
const adminProcessResponse = await service.getAdminProcessByRequest(processRequest).toPromise(); const adminProcessResponse = await firstValueFrom(service.getAdminProcessByRequest(processRequest));
expect(adminProcessResponse).toBeDefined(); expect(adminProcessResponse).toBeDefined();
expect(adminProcessResponse).not.toBeNull(); expect(adminProcessResponse).not.toBeNull();
expect(adminProcessResponse.httpMethod).toBe('POST'); expect(adminProcessResponse.httpMethod).toBe('POST');
@@ -251,7 +251,7 @@ describe('ProcessListCloudService', () => {
variableKeys: ['test-one', 'test-two'] variableKeys: ['test-one', 'test-two']
} as ProcessQueryCloudRequestModel; } as ProcessQueryCloudRequestModel;
requestSpy.and.callFake(returnCallQueryParameters); requestSpy.and.callFake(returnCallQueryParameters);
const requestParams = await service.getAdminProcessByRequest(processRequest).toPromise(); const requestParams = await firstValueFrom(service.getAdminProcessByRequest(processRequest));
expect(requestParams).toBeDefined(); expect(requestParams).toBeDefined();
expect(requestParams).not.toBeNull(); expect(requestParams).not.toBeNull();
@@ -267,7 +267,7 @@ describe('ProcessListCloudService', () => {
variableKeys: ['test-one', 'test-two'] variableKeys: ['test-one', 'test-two']
} as ProcessQueryCloudRequestModel; } as ProcessQueryCloudRequestModel;
requestSpy.and.callFake(returnCallBody); requestSpy.and.callFake(returnCallBody);
const requestBodyParams = await service.getAdminProcessByRequest(processRequest).toPromise(); const requestBodyParams = await firstValueFrom(service.getAdminProcessByRequest(processRequest));
expect(requestBodyParams).toBeDefined(); expect(requestBodyParams).toBeDefined();
expect(requestBodyParams).not.toBeNull(); expect(requestBodyParams).not.toBeNull();

View File

@@ -16,7 +16,7 @@
*/ */
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { of, throwError } from 'rxjs'; import { firstValueFrom, of, throwError } from 'rxjs';
import { StartProcessCloudService } from './start-process-cloud.service'; import { StartProcessCloudService } from './start-process-cloud.service';
import { fakeProcessPayload } from '../mock/start-process.component.mock'; import { fakeProcessPayload } from '../mock/start-process.component.mock';
import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model'; import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model';
@@ -37,7 +37,7 @@ describe('StartProcessCloudService', () => {
it('should be able to create a new process', async () => { it('should be able to create a new process', async () => {
spyOn(service, 'startProcess').and.returnValue(of({ id: 'fake-id', name: 'fake-name' })); spyOn(service, 'startProcess').and.returnValue(of({ id: 'fake-id', name: 'fake-name' }));
const result = await service.startProcess('appName1', fakeProcessPayload).toPromise(); const result = await firstValueFrom(service.startProcess('appName1', fakeProcessPayload));
expect(result).toBeDefined(); expect(result).toBeDefined();
expect(result.id).toEqual('fake-id'); expect(result.id).toEqual('fake-id');
@@ -46,7 +46,7 @@ describe('StartProcessCloudService', () => {
it('should be able to create a new process with form', async () => { it('should be able to create a new process with form', async () => {
spyOn(service, 'startProcessWithForm').and.returnValue(of({ id: 'fake-id', name: 'fake-name' })); spyOn(service, 'startProcessWithForm').and.returnValue(of({ id: 'fake-id', name: 'fake-name' }));
const result = await service.startProcessWithForm('appName1', 'mockFormId', 1, fakeProcessPayload).toPromise(); const result = await firstValueFrom(service.startProcessWithForm('appName1', 'mockFormId', 1, fakeProcessPayload));
expect(result).toBeDefined(); expect(result).toBeDefined();
expect(result.id).toEqual('fake-id'); expect(result.id).toEqual('fake-id');
@@ -61,14 +61,11 @@ describe('StartProcessCloudService', () => {
}); });
spyOn(service, 'startProcess').and.returnValue(throwError(errorResponse)); spyOn(service, 'startProcess').and.returnValue(throwError(errorResponse));
const result = await service const result = await firstValueFrom(service.startProcess('appName1', fakeProcessPayload)).catch((error) => {
.startProcess('appName1', fakeProcessPayload) expect(error.status).toEqual(404);
.toPromise() expect(error.statusText).toEqual('Not Found');
.catch((error) => { expect(error.error).toEqual('Mock Error');
expect(error.status).toEqual(404); });
expect(error.statusText).toEqual('Not Found');
expect(error.error).toEqual('Mock Error');
});
if (result) { if (result) {
fail('expected an error, not applications'); fail('expected an error, not applications');
@@ -77,7 +74,7 @@ describe('StartProcessCloudService', () => {
it('should be able to get all the process definitions', async () => { it('should be able to get all the process definitions', async () => {
spyOn(service, 'getProcessDefinitions').and.returnValue(of([new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' })])); spyOn(service, 'getProcessDefinitions').and.returnValue(of([new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' })]));
const result = await service.getProcessDefinitions('appName1').toPromise(); const result = await firstValueFrom(service.getProcessDefinitions('appName1'));
expect(result).toBeDefined(); expect(result).toBeDefined();
expect(result[0].id).toEqual('fake-id'); expect(result[0].id).toEqual('fake-id');
@@ -91,14 +88,11 @@ describe('StartProcessCloudService', () => {
statusText: 'Not Found' statusText: 'Not Found'
}); });
spyOn(service, 'getProcessDefinitions').and.returnValue(throwError(errorResponse)); spyOn(service, 'getProcessDefinitions').and.returnValue(throwError(errorResponse));
const result = await service const result = await firstValueFrom(service.getProcessDefinitions('appName1')).catch((error) => {
.getProcessDefinitions('appName1') expect(error.status).toEqual(404);
.toPromise() expect(error.statusText).toEqual('Not Found');
.catch((error) => { expect(error.error).toEqual('Mock Error');
expect(error.status).toEqual(404); });
expect(error.statusText).toEqual('Not Found');
expect(error.error).toEqual('Mock Error');
});
if (result) { if (result) {
fail('expected an error, not applications'); fail('expected an error, not applications');
@@ -111,7 +105,7 @@ describe('StartProcessCloudService', () => {
const requestSpy = spyOn(adfHttpClient, 'request'); const requestSpy = spyOn(adfHttpClient, 'request');
requestSpy.and.returnValue(Promise.resolve({ static1: 'value', static2: 0, static3: true })); requestSpy.and.returnValue(Promise.resolve({ static1: 'value', static2: 0, static3: true }));
const result = await service.getStartEventFormStaticValuesMapping(appName, processDefinitionId).toPromise(); const result = await firstValueFrom(service.getStartEventFormStaticValuesMapping(appName, processDefinitionId));
expect(result.length).toEqual(3); expect(result.length).toEqual(3);
expect(result[0].name).toEqual('static1'); expect(result[0].name).toEqual('static1');
expect(result[0].id).toEqual('static1'); expect(result[0].id).toEqual('static1');
@@ -132,7 +126,7 @@ describe('StartProcessCloudService', () => {
const requestSpy = spyOn(adfHttpClient, 'request'); const requestSpy = spyOn(adfHttpClient, 'request');
requestSpy.and.returnValue(Promise.resolve({ constant1: 'value', constant2: '0', constant3: 'true' })); requestSpy.and.returnValue(Promise.resolve({ constant1: 'value', constant2: '0', constant3: 'true' }));
const result = await service.getStartEventConstants(appName, processDefinitionId).toPromise(); const result = await firstValueFrom(service.getStartEventConstants(appName, processDefinitionId));
expect(result.length).toEqual(3); expect(result.length).toEqual(3);
expect(result[0].name).toEqual('constant1'); expect(result[0].name).toEqual('constant1');

View File

@@ -18,6 +18,7 @@
import { Directive, Input, HostListener, Output, EventEmitter, OnInit, ElementRef, Renderer2 } from '@angular/core'; import { Directive, Input, HostListener, Output, EventEmitter, OnInit, ElementRef, Renderer2 } from '@angular/core';
import { IdentityUserService } from '../../../../../people/services/identity-user.service'; import { IdentityUserService } from '../../../../../people/services/identity-user.service';
import { TaskCloudService } from '../../../../services/task-cloud.service'; import { TaskCloudService } from '../../../../services/task-cloud.service';
import { firstValueFrom } from 'rxjs';
@Directive({ @Directive({
// eslint-disable-next-line @angular-eslint/directive-selector // eslint-disable-next-line @angular-eslint/directive-selector
@@ -86,7 +87,7 @@ export class ClaimTaskCloudDirective implements OnInit {
const currentUser: string = this.identityUserService.getCurrentUserInfo().username; const currentUser: string = this.identityUserService.getCurrentUserInfo().username;
try { try {
this.renderer.setAttribute(this.el.nativeElement, 'disabled', 'true'); this.renderer.setAttribute(this.el.nativeElement, 'disabled', 'true');
const result = await this.taskListService.claimTask(this.appName, this.taskId, currentUser).toPromise(); const result = await firstValueFrom(this.taskListService.claimTask(this.appName, this.taskId, currentUser));
if (result) { if (result) {
this.success.emit(result); this.success.emit(result);
} }

View File

@@ -17,6 +17,7 @@
import { Directive, Input, HostListener, Output, EventEmitter, OnInit, ElementRef, Renderer2 } from '@angular/core'; import { Directive, Input, HostListener, Output, EventEmitter, OnInit, ElementRef, Renderer2 } from '@angular/core';
import { TaskCloudService } from '../../../../services/task-cloud.service'; import { TaskCloudService } from '../../../../services/task-cloud.service';
import { firstValueFrom } from 'rxjs';
@Directive({ @Directive({
// eslint-disable-next-line @angular-eslint/directive-selector // eslint-disable-next-line @angular-eslint/directive-selector
@@ -41,7 +42,11 @@ export class UnClaimTaskCloudDirective implements OnInit {
invalidParams: string[] = []; invalidParams: string[] = [];
constructor(private readonly el: ElementRef, private readonly renderer: Renderer2, private taskListService: TaskCloudService) {} constructor(
private readonly el: ElementRef,
private readonly renderer: Renderer2,
private taskListService: TaskCloudService
) {}
ngOnInit() { ngOnInit() {
this.validateInputs(); this.validateInputs();
@@ -71,7 +76,7 @@ export class UnClaimTaskCloudDirective implements OnInit {
async onClick() { async onClick() {
try { try {
this.renderer.setAttribute(this.el.nativeElement, 'disabled', 'true'); this.renderer.setAttribute(this.el.nativeElement, 'disabled', 'true');
await this.taskListService.unclaimTask(this.appName, this.taskId).toPromise(); await firstValueFrom(this.taskListService.unclaimTask(this.appName, this.taskId));
this.success.emit(this.taskId); this.success.emit(this.taskId);
} catch (error) { } catch (error) {
this.renderer.removeAttribute(this.el.nativeElement, 'disabled'); this.renderer.removeAttribute(this.el.nativeElement, 'disabled');

View File

@@ -17,6 +17,7 @@
import { Directive, Input, HostListener, Output, EventEmitter, OnInit, ElementRef, Renderer2 } from '@angular/core'; import { Directive, Input, HostListener, Output, EventEmitter, OnInit, ElementRef, Renderer2 } from '@angular/core';
import { TaskCloudService } from '../../../../services/task-cloud.service'; import { TaskCloudService } from '../../../../services/task-cloud.service';
import { firstValueFrom } from 'rxjs';
@Directive({ @Directive({
// eslint-disable-next-line @angular-eslint/directive-selector // eslint-disable-next-line @angular-eslint/directive-selector
@@ -41,7 +42,11 @@ export class CompleteTaskDirective implements OnInit {
invalidParams: string[] = []; invalidParams: string[] = [];
constructor(private readonly el: ElementRef, private readonly renderer: Renderer2, private readonly taskListService: TaskCloudService) {} constructor(
private readonly el: ElementRef,
private readonly renderer: Renderer2,
private readonly taskListService: TaskCloudService
) {}
ngOnInit() { ngOnInit() {
this.validateInputs(); this.validateInputs();
@@ -71,7 +76,7 @@ export class CompleteTaskDirective implements OnInit {
async onClick() { async onClick() {
try { try {
this.renderer.setAttribute(this.el.nativeElement, 'disabled', 'true'); this.renderer.setAttribute(this.el.nativeElement, 'disabled', 'true');
const result = await this.taskListService.completeTask(this.appName, this.taskId).toPromise(); const result = await firstValueFrom(this.taskListService.completeTask(this.appName, this.taskId));
if (result) { if (result) {
this.success.emit(result); this.success.emit(result);
} }

View File

@@ -18,7 +18,7 @@
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { ServiceTaskListCloudService } from './service-task-list-cloud.service'; import { ServiceTaskListCloudService } from './service-task-list-cloud.service';
import { ServiceTaskQueryCloudRequestModel } from '../models/service-task-cloud.model'; import { ServiceTaskQueryCloudRequestModel } from '../models/service-task-cloud.model';
import { of } from 'rxjs'; import { firstValueFrom, of } from 'rxjs';
import { AdfHttpClient } from '@alfresco/adf-core/api'; import { AdfHttpClient } from '@alfresco/adf-core/api';
import { NoopTranslateModule } from '@alfresco/adf-core'; import { NoopTranslateModule } from '@alfresco/adf-core';
@@ -112,56 +112,44 @@ describe('Activiti ServiceTaskList Cloud Service', () => {
const spyOnPost = spyOn<any>(service, 'post').and.returnValue(of({})); const spyOnPost = spyOn<any>(service, 'post').and.returnValue(of({}));
const params = ['fakeName', 'executionId_1', 'flowNodeId_1'] as const; const params = ['fakeName', 'executionId_1', 'flowNodeId_1'] as const;
await service.replayServiceTaskRequest(...params).toPromise(); await firstValueFrom(service.replayServiceTaskRequest(...params));
expect(spyOnPost).toHaveBeenCalledWith(expected.expectedQueryUrl, expected.expectedPayload); expect(spyOnPost).toHaveBeenCalledWith(expected.expectedQueryUrl, expected.expectedPayload);
}); });
it('should throw an exeption and execute logService error if appName is null', (done) => { it('should throw an exeption and execute logService error if appName is null', (done) => {
const expectedErrorMessage = 'Appname/executionId/flowNodeId not configured'; const expectedErrorMessage = 'Appname/executionId/flowNodeId not configured';
const params = [null, 'executionId_1', 'flowNodeId_1'] as const; const params = [null, 'executionId_1', 'flowNodeId_1'] as const;
service firstValueFrom(service.replayServiceTaskRequest(...params)).catch((error) => {
.replayServiceTaskRequest(...params) expect(error).toEqual(expectedErrorMessage);
.toPromise() done();
.catch((error) => { });
expect(error).toEqual(expectedErrorMessage);
done();
});
}); });
it('should throw an exeption and execute logService error if executionId is null', (done) => { it('should throw an exeption and execute logService error if executionId is null', (done) => {
const expectedErrorMessage = 'Appname/executionId/flowNodeId not configured'; const expectedErrorMessage = 'Appname/executionId/flowNodeId not configured';
const params = ['fakeName', null, 'flowNodeId_1'] as const; const params = ['fakeName', null, 'flowNodeId_1'] as const;
service firstValueFrom(service.replayServiceTaskRequest(...params)).catch((error) => {
.replayServiceTaskRequest(...params) expect(error).toEqual(expectedErrorMessage);
.toPromise() done();
.catch((error) => { });
expect(error).toEqual(expectedErrorMessage);
done();
});
}); });
it('should throw an exeption and execute logService error if flowNodeId is null', (done) => { it('should throw an exeption and execute logService error if flowNodeId is null', (done) => {
const expectedErrorMessage = 'Appname/executionId/flowNodeId not configured'; const expectedErrorMessage = 'Appname/executionId/flowNodeId not configured';
const params = ['fakeName', 'executionId_1', null] as const; const params = ['fakeName', 'executionId_1', null] as const;
service firstValueFrom(service.replayServiceTaskRequest(...params)).catch((error) => {
.replayServiceTaskRequest(...params) expect(error).toEqual(expectedErrorMessage);
.toPromise() done();
.catch((error) => { });
expect(error).toEqual(expectedErrorMessage);
done();
});
}); });
it('should throw an exeption and execute logService error if appName, executionId and flowNodeId are null', (done) => { it('should throw an exeption and execute logService error if appName, executionId and flowNodeId are null', (done) => {
const expectedErrorMessage = 'Appname/executionId/flowNodeId not configured'; const expectedErrorMessage = 'Appname/executionId/flowNodeId not configured';
const params = [null, null, null] as const; const params = [null, null, null] as const;
service firstValueFrom(service.replayServiceTaskRequest(...params)).catch((error) => {
.replayServiceTaskRequest(...params) expect(error).toEqual(expectedErrorMessage);
.toPromise() done();
.catch((error) => { });
expect(error).toEqual(expectedErrorMessage);
done();
});
}); });
}); });
}); });

View File

@@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { of, timer } from 'rxjs'; import { firstValueFrom, of, timer } from 'rxjs';
import { FormFieldModel, FormModel, GroupModel, FormFieldTypes, UnitTestingUtils } from '@alfresco/adf-core'; import { FormFieldModel, FormModel, GroupModel, FormFieldTypes, UnitTestingUtils } from '@alfresco/adf-core';
import { FunctionalGroupWidgetComponent } from './functional-group.widget'; import { FunctionalGroupWidgetComponent } from './functional-group.widget';
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
@@ -64,7 +64,7 @@ describe('FunctionalGroupWidgetComponent', () => {
component.searchTerm.setValue(text); component.searchTerm.setValue(text);
fixture.detectChanges(); fixture.detectChanges();
await timer(300).toPromise(); await firstValueFrom(timer(300));
await fixture.whenStable(); await fixture.whenStable();
fixture.detectChanges(); fixture.detectChanges();