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 { PersonPaging } from '@alfresco/js-api';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { EMPTY, of } from 'rxjs';
import { EMPTY, firstValueFrom, of } from 'rxjs';
import { AlfrescoApiService } from '../../services';
import { AlfrescoApiServiceMock } from '../../mock';
@@ -83,14 +83,14 @@ describe('PeopleContentService', () => {
it('should be able to fetch person details based on id', async () => {
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.email).toEqual('fakeEcm@ecmUser.com');
});
it('should be able to list people', async () => {
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 pagination = response.pagination;
@@ -112,7 +112,7 @@ describe('PeopleContentService', () => {
};
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);
});
@@ -122,14 +122,14 @@ describe('PeopleContentService', () => {
const requestQueryParams: PeopleContentQueryRequestModel = { skipCount: 10, maxItems: 20, sorting: undefined };
const expectedValue = { skipCount: 10, maxItems: 20 };
await peopleContentService.listPeople(requestQueryParams).toPromise();
await firstValueFrom(peopleContentService.listPeople(requestQueryParams));
expect(listPeopleSpy).toHaveBeenCalledWith(expectedValue);
});
it('should be able to create new person', async () => {
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.email).toEqual('fakeEcm@ecmUser.com');
});
@@ -150,12 +150,12 @@ describe('PeopleContentService', () => {
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(peopleContentService.isCurrentUserAdmin()).toBe(true);
expect(getCurrentPersonSpy.calls.count()).toEqual(1);
await peopleContentService.getCurrentUserInfo().toPromise();
await firstValueFrom(peopleContentService.getCurrentUserInfo());
expect(peopleContentService.isCurrentUserAdmin()).toBe(true);
expect(getCurrentPersonSpy.calls.count()).toEqual(1);
@@ -165,13 +165,13 @@ describe('PeopleContentService', () => {
const getCurrentPersonSpy = spyOn(peopleContentService.peopleApi, 'getPerson').and.returnValue(
Promise.resolve({ entry: fakeEcmAdminUser } as any)
);
await peopleContentService.getCurrentUserInfo().toPromise();
await firstValueFrom(peopleContentService.getCurrentUserInfo());
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);
const currentUser = await peopleContentService.getCurrentUserInfo().toPromise();
const currentUser = await firstValueFrom(peopleContentService.getCurrentUserInfo());
expect(peopleContentService.isCurrentUserAdmin()).toBe(true);
expect(currentUser.id).toEqual(fakeEcmAdminUser.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 { MatExpansionPanel } from '@angular/material/expansion';
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 { TagsCreatorComponent, TagsCreatorMode } from '../../../tag';
import { ContentTestingModule } from '../../../testing/content.testing.module';
@@ -1144,7 +1144,7 @@ describe('ContentMetadataComponent', () => {
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
fixture.detectChanges();
await component.groupedProperties$.toPromise();
await firstValueFrom(component.groupedProperties$);
fixture.detectChanges();
const verProp = queryDom('Versionable');
@@ -1164,7 +1164,7 @@ describe('ContentMetadataComponent', () => {
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
fixture.detectChanges();
await component.groupedProperties$.toPromise();
await firstValueFrom(component.groupedProperties$);
fixture.detectChanges();
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) });
fixture.detectChanges();
await component.groupedProperties$.toPromise();
await firstValueFrom(component.groupedProperties$);
fixture.detectChanges();
const verProp = queryDom('Versionable');
@@ -1205,7 +1205,7 @@ describe('ContentMetadataComponent', () => {
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
fixture.detectChanges();
await component.groupedProperties$.toPromise();
await firstValueFrom(component.groupedProperties$);
fixture.detectChanges();
const verProp = queryDom('Versionable');
@@ -1225,7 +1225,7 @@ describe('ContentMetadataComponent', () => {
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
fixture.detectChanges();
await component.groupedProperties$.toPromise();
await firstValueFrom(component.groupedProperties$);
fixture.detectChanges();
const verProp = queryDom('Versionable');
@@ -1249,7 +1249,7 @@ describe('ContentMetadataComponent', () => {
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
fixture.detectChanges();
await component.groupedProperties$.toPromise();
await firstValueFrom(component.groupedProperties$);
fixture.detectChanges();
const exifProp = queryDom('Exif');
@@ -1283,7 +1283,7 @@ describe('ContentMetadataComponent', () => {
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
fixture.detectChanges();
await component.groupedProperties$.toPromise();
await firstValueFrom(component.groupedProperties$);
fixture.detectChanges();
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 { ClassesApi, Node } from '@alfresco/js-api';
import { TestBed } from '@angular/core/testing';
import { of } from 'rxjs';
import { firstValueFrom, of } from 'rxjs';
import { ContentTestingModule } from '../../testing/content.testing.module';
import { OrganisedPropertyGroup } from '../interfaces/content-metadata.interfaces';
import { PropertyGroup } from '../interfaces/property-group.interface';
@@ -253,7 +253,7 @@ describe('ContentMetaDataService', () => {
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[0].title).toEqual('Exif');
@@ -267,7 +267,7 @@ describe('ContentMetaDataService', () => {
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[0].title).toEqual('Exif');
@@ -284,7 +284,7 @@ describe('ContentMetaDataService', () => {
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[0].title).toEqual('Versionable');
@@ -301,7 +301,7 @@ describe('ContentMetaDataService', () => {
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[0].title).toEqual('Versionable');
@@ -319,7 +319,7 @@ describe('ContentMetaDataService', () => {
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(classesApi.getClass).toHaveBeenCalledTimes(1 + fakeContentNode.aspectNames.length);
@@ -335,7 +335,7 @@ describe('ContentMetaDataService', () => {
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[0].title).toEqual('Versionable');
@@ -351,7 +351,7 @@ describe('ContentMetaDataService', () => {
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(classesApi.getClass).toHaveBeenCalledTimes(1 + fakeContentNode.aspectNames.length);
@@ -367,7 +367,7 @@ describe('ContentMetaDataService', () => {
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[0].title).toEqual('Exif');
@@ -387,7 +387,7 @@ describe('ContentMetaDataService', () => {
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[0].title).toEqual('Exif');

View File

@@ -18,7 +18,7 @@
import { Component, EventEmitter, Output } from '@angular/core';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
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 { ContentTestingModule } from '../testing/content.testing.module';
import {
@@ -114,7 +114,7 @@ describe('NewVersionUploaderService', () => {
});
it('should open dialog with default configuration', fakeAsync(() => {
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData).toPromise();
firstValueFrom(service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData));
tick();
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig);
}));
@@ -124,7 +124,7 @@ describe('NewVersionUploaderService', () => {
panelClass: 'adf-custom-class',
width: '500px'
};
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration).toPromise();
firstValueFrom(service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration));
tick();
expectedConfig.panelClass = 'adf-custom-class';
expectedConfig.width = '500px';
@@ -135,7 +135,7 @@ describe('NewVersionUploaderService', () => {
const mockDialogConfiguration: MatDialogConfig = {
height: '600px'
};
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration).toPromise();
firstValueFrom(service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration));
tick();
expectedConfig.height = '600px';
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig);
@@ -143,7 +143,7 @@ describe('NewVersionUploaderService', () => {
it('should not override dialog configuration, if dialog configuration is empty', fakeAsync(() => {
const mockDialogConfiguration: MatDialogConfig = {};
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration).toPromise();
firstValueFrom(service.openUploadNewVersionDialog(mockNewVersionUploaderDialogData, mockDialogConfiguration));
tick();
expect(spyOnDialogOpen).toHaveBeenCalledWith(NewVersionUploaderDialogComponent, expectedConfig);
}));
@@ -156,7 +156,7 @@ describe('NewVersionUploaderService', () => {
showComments: true,
allowDownload: true
};
service.openUploadNewVersionDialog(mockNewVersionUploaderDialogDataWithVersionsOnly).toPromise();
firstValueFrom(service.openUploadNewVersionDialog(mockNewVersionUploaderDialogDataWithVersionsOnly));
tick();
expectedConfig.data.showVersionsOnly = true;
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 { fakeMarksApiResponse, createNewSecurityMarkMock } from './mock/security-marks.mock';
import { SecurityGroupBody, SecurityMarkBody, SecurityMarkEntry } from '@alfresco/js-api';
import { firstValueFrom } from 'rxjs';
describe('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;
expect(response.entry.groupName).toEqual('TestGroup');
@@ -176,7 +177,7 @@ describe('SecurityControlsService', () => {
it('should delete a security group', async () => {
spyOn(service.groupsApi, 'deleteSecurityGroup').and.returnValue(Promise.resolve());
await service.deleteSecurityGroup(securityGroupId).toPromise();
await firstValueFrom(service.deleteSecurityGroup(securityGroupId));
expect(service.groupsApi.deleteSecurityGroup).toHaveBeenCalled();
});
@@ -185,7 +186,7 @@ describe('SecurityControlsService', () => {
Promise.resolve(fakeAuthorityClearanceApiResponse)
);
const clearancePromise = service.getClearancesForAuthority('test-id', 0, 10);
const clearance = await clearancePromise.toPromise();
const clearance = await firstValueFrom(clearancePromise);
expect(getClearancesForAuthoritySpy).toHaveBeenCalledWith('test-id', {
skipCount: 0,
@@ -210,15 +211,15 @@ describe('SecurityControlsService', () => {
}
})
);
const response = (await service
.updateClearancesForAuthority('test-id', [
const response = (await firstValueFrom(
service.updateClearancesForAuthority('test-id', [
{
groupId: 'test-group-id',
op: 'test-op',
id: 'test-id'
}
])
.toPromise()) as SecurityMarkEntry;
)) as SecurityMarkEntry;
expect(response.entry.id).toEqual('test-id');
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 { fakeAsync, TestBed, tick } from '@angular/core/testing';
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';
describe('TagService', () => {
@@ -75,7 +75,7 @@ describe('TagService', () => {
let lastValue: any;
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);
});
@@ -83,7 +83,7 @@ describe('TagService', () => {
let lastValue = false;
service.refresh.subscribe(() => (lastValue = true));
await service.deleteTag('fake-tag-id').toPromise();
await firstValueFrom(service.deleteTag('fake-tag-id'));
expect(lastValue).toBeTrue();
});
@@ -110,7 +110,7 @@ describe('TagService', () => {
spyOn(service.refresh, 'emit');
spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.resolve(tag));
await service.createTags([]).toPromise();
await firstValueFrom(service.createTags([]));
expect(service.refresh.emit).toHaveBeenCalledWith(tag);
});
});
@@ -248,7 +248,7 @@ describe('TagService', () => {
it('should emit refresh when tag updated successfully', async () => {
spyOn(service.refresh, 'emit');
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);
});
});