Skip to content

Commit

Permalink
[MNT-24575] Added delay to API retry call. Added unit test for API re…
Browse files Browse the repository at this point in the history
…try functionality
  • Loading branch information
swapnil-verma-gl committed Dec 5, 2024
1 parent 206384c commit ef304eb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { FolderInformationComponent } from './folder-information.component';
import { DIALOG_COMPONENT_DATA, RedirectAuthService } from '@alfresco/adf-core';
import { ContentService, NodesApiService } from '@alfresco/adf-content-services';
import { By } from '@angular/platform-browser';
import { EMPTY, Subject } from 'rxjs';
import { EMPTY, of, Subject } from 'rxjs';
import { LibTestingModule } from '@alfresco/aca-shared';

describe('FolderInformationComponent', () => {
Expand Down Expand Up @@ -84,4 +84,21 @@ describe('FolderInformationComponent', () => {
mockSub.next({ entry: { jobId: 'mock-job-id' } });
expect(getFolderSizeInfoSpy).toHaveBeenCalled();
});

it('should make repeated calls to get folder size info, if the response returned from the API is IN_PROGRESS', fakeAsync(() => {
getFolderSizeInfoSpy.and.returnValue(of({ entry: { status: 'IN_PROGRESS' } }));
fixture.detectChanges();
expect(getFolderSizeInfoSpy).not.toHaveBeenCalled();
mockSub.next({ entry: { jobId: 'mock-job-id' } });
expect(getFolderSizeInfoSpy).toHaveBeenCalledTimes(1);
tick(5000);
expect(getFolderSizeInfoSpy).toHaveBeenCalledTimes(2);
tick(5000);
expect(getFolderSizeInfoSpy).toHaveBeenCalledTimes(3);
getFolderSizeInfoSpy.and.returnValue(of({ entry: { status: 'COMPLETE' } }));
tick(5000);
expect(getFolderSizeInfoSpy).toHaveBeenCalledTimes(4);
tick(5000);
expect(getFolderSizeInfoSpy).not.toHaveBeenCalledTimes(5);
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import { JobIdBodyEntry, Node, SizeDetailsEntry } from '@alfresco/js-api';
import { MatDividerModule } from '@angular/material/divider';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { ContentService, NodesApiService } from '@alfresco/adf-content-services';
import { expand, first } from 'rxjs/operators';
import { concatMap, expand, first } from 'rxjs/operators';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { EMPTY } from 'rxjs';
import { EMPTY, timer } from 'rxjs';

const MEMORY_UNIT_LIST = ['bytes', 'KB', 'MB', 'GB', 'TB'];

Expand Down Expand Up @@ -75,7 +75,9 @@ export class FolderInformationComponent implements OnInit {
.getFolderSizeInfo(this.data.id, jobIdEntry.entry.jobId)
.pipe(
expand((result: any) =>
result.entry.status !== 'COMPLETED' ? this.nodesService.getFolderSizeInfo(this.data.id, jobIdEntry.entry.jobId) : EMPTY
result.entry.status === 'IN_PROGRESS'
? timer(5000).pipe(concatMap(() => this.nodesService.getFolderSizeInfo(this.data.id, jobIdEntry.entry.jobId)))
: EMPTY
),
takeUntilDestroyed(this.destroyRef)
)
Expand Down

0 comments on commit ef304eb

Please sign in to comment.