Skip to content

Commit

Permalink
[MNT-24575] Added unit tests. Fixed typo
Browse files Browse the repository at this point in the history
  • Loading branch information
swapnil-verma-gl committed Dec 20, 2024
1 parent f54345a commit 1e97b60
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*!
* @license
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { AlfrescoApiService, AlfrescoApiServiceMock, NodesApiService } from '@alfresco/adf-content-services';
import { CoreTestingModule, RedirectAuthService } from '@alfresco/adf-core';
import { EMPTY, firstValueFrom, of } from 'rxjs';
import { JobIdBodyEntry, SizeDetails, SizeDetailsEntry } from '@alfresco/js-api';

const fakeInitiateFolderSizeResponse: JobIdBodyEntry = {
entry: {
jobId: 'fake-job-id'
}
};

const fakeFolderSizeResponse: SizeDetailsEntry = {
entry: {
jobId: 'fake-job-id',
calculatedAt: new Date().toString(),
sizeInBytes: '1234',
numberOfFiles: 1,
status: SizeDetails.StatusEnum.COMPLETE,
id: 'fake-id'
}
};

describe('NodesApiService', () => {
let nodesApiService: NodesApiService;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule, CoreTestingModule],
providers: [
NodesApiService,
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
{ provide: RedirectAuthService, useValue: { onLogin: EMPTY, onTokenReceived: of(), init: () => {} } }
]
});

nodesApiService = TestBed.inject(NodesApiService);
});

it('should call initiateFolderSizeCalculation api with nodeId parameter', async () => {
spyOn(nodesApiService.nodesApi, 'initiateFolderSizeCalculation').and.returnValue(Promise.resolve(fakeInitiateFolderSizeResponse));
await firstValueFrom(nodesApiService.initiateFolderSizeCalculation('fake-node-id'));

expect(nodesApiService.nodesApi.initiateFolderSizeCalculation).toHaveBeenCalledWith('fake-node-id');
});

it('should call getFolderSizeInfo api with nodeId and jobId parameter', async () => {
spyOn(nodesApiService.nodesApi, 'getFolderSizeInfo').and.returnValue(Promise.resolve(fakeFolderSizeResponse));
await firstValueFrom(nodesApiService.getFolderSizeInfo('fake-node-id', 'fake-job-id'));

expect(nodesApiService.nodesApi.getFolderSizeInfo).toHaveBeenCalledWith('fake-node-id', 'fake-job-id');
});
});
6 changes: 3 additions & 3 deletions lib/js-api/src/api/content-rest-api/docs/NodesApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ All URIs are relative to *https://localhost/alfresco/api/-default-/public/alfres
| [unlockNode](#unlockNode) | **POST** /nodes/{nodeId}/unlock | Unlock a node |
| [updateNode](#updateNode) | **PUT** /nodes/{nodeId} | Update a node |
| [updateNodeContent](#updateNodeContent) | **PUT** /nodes/{nodeId}/content | Update node content |
| [initialFolderSizeCalculation](#initialFolderSizeCalculation) | **POST** /nodes/{nodeId}/size-details | Initiate a new request to calculate folder size |
| [initiateFolderSizeCalculation](#initiateFolderSizeCalculation) | **POST** /nodes/{nodeId}/size-details | Initiate a new request to calculate folder size |
| [getFolderSizeInfo](#getFolderSizeInfo) | **GET** /nodes/{nodeId}/size-details/{jobId} | Gets the details of a folder |

## copyNode
Expand Down Expand Up @@ -1198,7 +1198,7 @@ nodesApi.updateNodeContent(`<nodeId>`, contentBodyUpdate, opts).then((data) => {
console.log('API called successfully. Returned data: ' + data);
});
```
## initialFolderSizeCalculation
## initiateFolderSizeCalculation

Initiate a new request to calculate folder size.

Expand Down Expand Up @@ -1241,7 +1241,7 @@ Fetches the size details of folder with the identifier **nodeId**
| Name | Type | Description |
|------------|----------|------------------------------------------------------------------------------------|
| **nodeId** | string | The identifier of a node. |
| **jobId** | string | The identifier for the job which is calculating the currently selected node's size |
| **jobId** | string | The identifier for the job which is calculating the currently selected node's size |

**Return type**: [SizeDetailsEntry](#SizeDetailsEntry)

Expand Down

0 comments on commit 1e97b60

Please sign in to comment.