Skip to content

Commit

Permalink
fix the private access to the service variables (#8202)
Browse files Browse the repository at this point in the history
* fix the private access to the service variables

* fix issues with unit tests
  • Loading branch information
DenysVuika authored Jan 28, 2023
1 parent b503773 commit 2a45c1e
Show file tree
Hide file tree
Showing 37 changed files with 72 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { AspectEntry, AspectPaging, AspectsApi } from '@alfresco/js-api';
})
export class AspectListService {

_aspectsApi: AspectsApi;
private _aspectsApi: AspectsApi;
get aspectsApi(): AspectsApi {
this._aspectsApi = this._aspectsApi ?? new AspectsApi(this.alfrescoApiService.getInstance());
return this._aspectsApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class DialogAspectListService {
width,
role: 'dialog',
disableClose: true
}).afterClosed().subscribe(() => DialogAspectListService.focusOnClose(selectorAutoFocusedOnClose));
}).afterClosed().subscribe(() => this.focusOnClose(selectorAutoFocusedOnClose));
this.overlayContainer.getContainerElement().setAttribute('role', 'main');
}

Expand All @@ -65,7 +65,7 @@ export class DialogAspectListService {
this.overlayContainer.getContainerElement().setAttribute('role', 'region');
}

private static focusOnClose(selectorAutoFocusedOnClose: string): void {
private focusOnClose(selectorAutoFocusedOnClose: string): void {
if (selectorAutoFocusedOnClose) {
document.querySelector<HTMLElement>(selectorAutoFocusedOnClose).focus();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/content-services/src/lib/audit/audit.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { catchError } from 'rxjs/operators';
})
export class AuditService {

_auditApi: AuditApi;
private _auditApi: AuditApi;
get auditApi(): AuditApi {
this._auditApi = this._auditApi ?? new AuditApi(this.apiService.getInstance());
return this._auditApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { catchError } from 'rxjs/operators';
})
export class FavoritesApiService {

_favoritesApi: FavoritesApi;
private _favoritesApi: FavoritesApi;
get favoritesApi(): FavoritesApi {
this._favoritesApi = this._favoritesApi ?? new FavoritesApi(this.apiService.getInstance());
return this._favoritesApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { ClassesApi } from '@alfresco/js-api';
})
export class PropertyDescriptorsService {

private _classesApi;
private _classesApi: ClassesApi;
get classesApi(): ClassesApi {
this._classesApi = this._classesApi ?? new ClassesApi(this.alfrescoApiService.getInstance());
return this._classesApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { map } from 'rxjs/operators';
})
export class ContentTypeService {

_typesApi: TypesApi;
private _typesApi: TypesApi;
get typesApi(): TypesApi {
this._typesApi = this._typesApi ?? new TypesApi(this.alfrescoApiService.getInstance());
return this._typesApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { AlfrescoApiService } from '@alfresco/adf-core';
})
export class GroupService {

_groupsApi: GroupsApi;
private _groupsApi: GroupsApi;
get groupsApi(): GroupsApi {
this._groupsApi = this._groupsApi ?? new GroupsApi(this.alfrescoApiService.getInstance());
return this._groupsApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { OverlayContainer } from '@angular/cdk/overlay';
})
export class NewVersionUploaderService {

_versionsApi: VersionsApi;
private _versionsApi: VersionsApi;
get versionsApi(): VersionsApi {
this._versionsApi = this._versionsApi ?? new VersionsApi(this.apiService.getInstance());
return this._versionsApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { RoleModel } from '../models/role.model';
})
export class NodePermissionService {

_groupsApi: GroupsApi;
private _groupsApi: GroupsApi;
get groupsApi(): GroupsApi {
this._groupsApi = this._groupsApi ?? new GroupsApi(this.apiService.getInstance());
return this._groupsApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { SearchForm } from '../models/search-form.interface';
})
export abstract class BaseQueryBuilderService {

_searchApi: SearchApi;
private _searchApi: SearchApi;
get searchApi(): SearchApi {
this._searchApi = this._searchApi ?? new SearchApi(this.alfrescoApiService.getInstance());
return this._searchApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ import { SearchConfigurationInterface } from '@alfresco/adf-core';
})
export class SearchConfigurationService implements SearchConfigurationInterface {

constructor() {
}

/**
* Generates a QueryBody object with custom search parameters.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { RatingServiceInterface } from './rating.service.interface';
})
export class RatingService implements RatingServiceInterface {

_ratingsApi: RatingsApi;
private _ratingsApi: RatingsApi;
get ratingsApi(): RatingsApi {
this._ratingsApi = this._ratingsApi ?? new RatingsApi(this.apiService.getInstance());
return this._ratingsApi;
Expand Down
42 changes: 22 additions & 20 deletions lib/content-services/src/lib/tag/services/tag.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ import {
RequestQuery,
RequestSortDefinitionInner,
ResultSetPaging,
SearchApi,
SearchRequest,
TagBody,
TagEntry
} from '@alfresco/js-api';

describe('TagService', () => {

let service: TagService;
let logService: LogService;
let userPreferencesService: UserPreferencesService;

setupTestBed({
imports: [
Expand All @@ -44,10 +44,13 @@ describe('TagService', () => {

beforeEach(() => {
service = TestBed.inject(TagService);
spyOn(service['tagsApi'], 'deleteTagFromNode').and.returnValue(
logService = TestBed.inject(LogService);
userPreferencesService = TestBed.inject(UserPreferencesService);

spyOn(service.tagsApi, 'deleteTagFromNode').and.returnValue(
Promise.resolve({})
);
spyOn(service['tagsApi'], 'createTagForNode').and.returnValue(
spyOn(service.tagsApi, 'createTagForNode').and.returnValue(
Promise.resolve(new TagEntry({}))
);
});
Expand Down Expand Up @@ -82,11 +85,11 @@ describe('TagService', () => {
describe('createTags', () => {
it('should call createTags on tagsApi', () => {
spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.resolve([]));
const tag1: TagBody = new TagBody();
const tag1 = new TagBody();
tag1.tag = 'Some tag 1';
const tag2: TagBody = new TagBody();
const tag2 = new TagBody();
tag2.tag = 'Some tag 2';
const tags: TagBody[] = [tag1, tag2];
const tags = [tag1, tag2];
service.createTags(tags);
expect(service.tagsApi.createTags).toHaveBeenCalledWith(tags);
});
Expand All @@ -106,9 +109,8 @@ describe('TagService', () => {
}));

it('should call error on logService when error occurs during tags creation', fakeAsync(() => {
const logService: LogService = TestBed.inject(LogService);
spyOn(logService, 'error');
const error: string = 'Some error';
const error = 'Some error';
spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.reject(error));
service.createTags([]);
tick();
Expand All @@ -124,15 +126,16 @@ describe('TagService', () => {
});

it('should call search on searchApi with correct parameters', () => {
const searchSpy: jasmine.Spy<(queryBody: SearchRequest) => Promise<ResultSetPaging>> =
spyOn(SearchApi.prototype, 'search').and.returnValue(Promise.resolve(result));
const name: string = 'test';
const sortingByName: RequestSortDefinitionInner = new RequestSortDefinitionInner();
const maxItems: number = 25;
spyOnProperty(TestBed.inject(UserPreferencesService), 'paginationSize').and.returnValue(maxItems);
const searchSpy = spyOn(service.searchApi, 'search').and.returnValue(Promise.resolve(result));
const name = 'test';
const maxItems = 25;
spyOnProperty(userPreferencesService, 'paginationSize').and.returnValue(maxItems);

const sortingByName = new RequestSortDefinitionInner();
sortingByName.field = 'cm:name';
sortingByName.ascending = true;
sortingByName.type = RequestSortDefinitionInner.TypeEnum.FIELD;

service.searchTags(name);
expect(searchSpy).toHaveBeenCalledWith({
query: {
Expand All @@ -148,18 +151,18 @@ describe('TagService', () => {
});

it('should return observable which emits paging object for tags', (done) => {
spyOn(SearchApi.prototype, 'search').and.returnValue(Promise.resolve(result));
spyOn(service.searchApi, 'search').and.returnValue(Promise.resolve(result));

service.searchTags('test').subscribe((tagsResult) => {
expect(tagsResult).toBe(result);
done();
});
});

it('should call error on logService when error occurs during fetching paging object for tags', fakeAsync(() => {
const logService: LogService = TestBed.inject(LogService);
spyOn(logService, 'error');
const error: string = 'Some error';
spyOn(SearchApi.prototype, 'search').and.returnValue(Promise.reject(error));
spyOn(service.searchApi, 'search').and.returnValue(Promise.reject(error));
service.searchTags('test').subscribe({
error: () => {
expect(logService.error).toHaveBeenCalledWith(error);
Expand Down Expand Up @@ -200,9 +203,8 @@ describe('TagService', () => {
}));

it('should call error on logService when error occurs during tag update', fakeAsync(() => {
const logService: LogService = TestBed.inject(LogService);
spyOn(logService, 'error');
const error: string = 'Some error';
const error = 'Some error';
spyOn(service.tagsApi, 'updateTag').and.returnValue(Promise.reject(error));
service.updateTag(tag.entry.id, tagBody);
tick();
Expand Down
9 changes: 6 additions & 3 deletions lib/content-services/src/lib/tag/services/tag.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@ import {
@Injectable({
providedIn: 'root'
})
// eslint-disable-next-line @angular-eslint/directive-class-suffix
export class TagService {

_tagsApi: TagsApi;
private _tagsApi: TagsApi;
get tagsApi(): TagsApi {
this._tagsApi = this._tagsApi ?? new TagsApi(this.apiService.getInstance());
return this._tagsApi;
}

private searchApi: SearchApi = new SearchApi(this.apiService.getInstance());
private _searchApi: SearchApi;
get searchApi(): SearchApi {
this._searchApi = this._searchApi ?? new SearchApi(this.apiService.getInstance());
return this._searchApi;
}

/** Emitted when tag information is updated. */
@Output()
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/lib/services/content.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export class ContentService {
folderCreate: Subject<MinimalNode> = new Subject<MinimalNode>();
folderEdit: Subject<MinimalNode> = new Subject<MinimalNode>();

_contentApi: ContentApi;
private _contentApi: ContentApi;
get contentApi(): ContentApi {
this._contentApi = this._contentApi ?? new ContentApi(this.apiService.getInstance());
return this._contentApi;
}

_nodesApi: NodesApi;
private _nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
return this._nodesApi;
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/lib/services/deleted-nodes-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import { catchError } from 'rxjs/operators';
})
export class DeletedNodesApiService {

_nodesApi: NodesApi;
private _nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
return this._nodesApi;
}

_trashcanApi: TrashcanApi;
private _trashcanApi: TrashcanApi;
get trashcanApi(): TrashcanApi {
this._trashcanApi = this._trashcanApi ?? new TrashcanApi(this.apiService.getInstance());
return this._trashcanApi;
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/lib/services/discovery-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class DiscoveryApiService {

return from(systemPropertiesApi.getProperties())
.pipe(
map((res) => {
map((res: any) => {
if ('string' === typeof (res)) {
throw new Error('Not valid response');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/lib/services/ecm-user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { PeopleApi } from '@alfresco/js-api';
})
export class EcmUserService {

_peopleApi: PeopleApi;
private _peopleApi: PeopleApi;
get peopleApi(): PeopleApi {
this._peopleApi = this._peopleApi ?? new PeopleApi(this.apiService.getInstance());
return this._peopleApi;
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/lib/services/nodes-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ export class NodesApiService {
*/
nodeUpdated = new Subject<Node>();

_trashcanApi: TrashcanApi;
private _trashcanApi: TrashcanApi;
get trashcanApi(): TrashcanApi {
this._trashcanApi = this._trashcanApi ?? new TrashcanApi(this.apiService.getInstance());
return this._trashcanApi;
}

_nodesApi: NodesApi;
private _nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
return this._nodesApi;
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/lib/services/people-process.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ import { GroupModel } from '../form';
})
export class PeopleProcessService {

_taskActionsApi: TaskActionsApi;
private _taskActionsApi: TaskActionsApi;
get taskActionsApi(): TaskActionsApi {
this._taskActionsApi = this._taskActionsApi ?? new TaskActionsApi(this.apiService.getInstance());
return this._taskActionsApi;
}

_userApi: UsersApi;
private _userApi: UsersApi;
get userApi(): UsersApi {
this._userApi = this._userApi ?? new UsersApi(this.apiService.getInstance());
return this._userApi;
}

_groupsApi: ActivitiGroupsApi;
private _groupsApi: ActivitiGroupsApi;
get groupsApi(): ActivitiGroupsApi {
this._groupsApi = this._groupsApi ?? new ActivitiGroupsApi(this.apiService.getInstance());
return this._groupsApi;
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/lib/services/thumbnail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class ThumbnailService {
'multipart/related': './assets/images/ft_ic_website.svg'
};

_contentApi: ContentApi;
private _contentApi: ContentApi;
get contentApi(): ContentApi {
this._contentApi = this._contentApi ?? new ContentApi(this.apiService.getInstance());
return this._contentApi;
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/lib/viewer/services/view-util.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ export class ViewUtilService {
viewerTypeChange: Subject<string> = new Subject<string>();
urlFileContentChange: Subject<string> = new Subject<string>();

_renditionsApi: RenditionsApi;
private _renditionsApi: RenditionsApi;
get renditionsApi(): RenditionsApi {
this._renditionsApi = this._renditionsApi ?? new RenditionsApi(this.apiService.getInstance());
return this._renditionsApi;
}

_contentApi: ContentApi;
private _contentApi: ContentApi;
get contentApi(): ContentApi {
this._contentApi = this._contentApi ?? new ContentApi(this.apiService.getInstance());
return this._contentApi;
}

_versionsApi: VersionsApi;
private _versionsApi: VersionsApi;
get versionsApi(): VersionsApi {
this._versionsApi = this._versionsApi ?? new VersionsApi(this.apiService.getInstance());
return this._versionsApi;
Expand Down
2 changes: 1 addition & 1 deletion lib/insights/src/lib/diagram/services/diagrams.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { ModelJsonBpmnApi } from '@alfresco/js-api';
@Injectable({ providedIn: 'root' })
export class DiagramsService {

_modelJsonBpmnApi: ModelJsonBpmnApi;
private _modelJsonBpmnApi: ModelJsonBpmnApi;
get modelJsonBpmnApi(): ModelJsonBpmnApi {
this._modelJsonBpmnApi = this._modelJsonBpmnApi ?? new ModelJsonBpmnApi(this.apiService.getInstance());
return this._modelJsonBpmnApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { FormCloudServiceInterface } from './form-cloud.service.interface';
})
export class FormCloudService extends BaseCloudService implements FormCloudServiceInterface {

private _uploadApi;
private _uploadApi: UploadApi;
get uploadApi(): UploadApi {
this._uploadApi = this._uploadApi ?? new UploadApi(this.apiService.getInstance());
return this._uploadApi;
Expand Down
Loading

0 comments on commit 2a45c1e

Please sign in to comment.