mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[ACS-12332] Add checkout and cancel-checkout node support (#12133)
* [ACS-12332] Add checkout and cancel-checkout node support * [ACS-12332] cr fix
This commit is contained in:
@@ -18,11 +18,19 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { RedirectAuthService } from '@alfresco/adf-core';
|
||||
import { EMPTY, firstValueFrom, of } from 'rxjs';
|
||||
import { JobIdBodyEntry, SizeDetails, SizeDetailsEntry } from '@alfresco/js-api';
|
||||
import { JobIdBodyEntry, NodeEntry, SizeDetails, SizeDetailsEntry } from '@alfresco/js-api';
|
||||
import { NodesApiService } from './nodes-api.service';
|
||||
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
||||
import { AlfrescoApiServiceMock } from '../../mock/alfresco-api.service.mock';
|
||||
|
||||
const fakeNodeEntry = {
|
||||
entry: {
|
||||
id: 'fake-node-id',
|
||||
name: 'fake-file.txt',
|
||||
nodeType: 'cm:content'
|
||||
}
|
||||
} as NodeEntry;
|
||||
|
||||
const fakeInitiateFolderSizeResponse: JobIdBodyEntry = {
|
||||
entry: {
|
||||
jobId: 'fake-job-id'
|
||||
@@ -75,4 +83,20 @@ describe('NodesApiService', () => {
|
||||
|
||||
expect(nodesApiService.nodesApi.listParents).toHaveBeenCalledWith('fake-node-id', { include: ['path'], where: 'isPrimary=true' });
|
||||
});
|
||||
|
||||
it('should call nodesApi.checkoutNode with the node ID and optional query params', async () => {
|
||||
const opts = { include: ['path', 'allowableOperations'], fields: ['id', 'name'] };
|
||||
spyOn(nodesApiService.nodesApi, 'checkoutNode').and.returnValue(Promise.resolve(fakeNodeEntry));
|
||||
await firstValueFrom(nodesApiService.checkoutNode(fakeNodeEntry.entry.id, opts));
|
||||
|
||||
expect(nodesApiService.nodesApi.checkoutNode).toHaveBeenCalledWith(fakeNodeEntry.entry.id, opts);
|
||||
});
|
||||
|
||||
it('should call nodesApi.cancelCheckoutNode with the node ID and optional query params', async () => {
|
||||
const opts = { include: ['path'], fields: ['id'] };
|
||||
spyOn(nodesApiService.nodesApi, 'cancelCheckoutNode').and.returnValue(Promise.resolve(fakeNodeEntry));
|
||||
await firstValueFrom(nodesApiService.cancelCheckoutNode(fakeNodeEntry.entry.id, opts));
|
||||
|
||||
expect(nodesApiService.nodesApi.cancelCheckoutNode).toHaveBeenCalledWith(fakeNodeEntry.entry.id, opts);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -293,6 +293,30 @@ export class NodesApiService {
|
||||
return from(this.nodesApi.listParents(nodeId, opts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks out a file node for offline editing.
|
||||
* Creates a private working copy and locks the original.
|
||||
*
|
||||
* @param nodeId ID of the node to check out
|
||||
* @param opts Optional query parameters (`include`, `fields`)
|
||||
* @returns Observable emitting the working copy node
|
||||
*/
|
||||
checkoutNode(nodeId: string, opts?: NodesIncludeQuery): Observable<NodeEntry> {
|
||||
return from(this.nodesApi.checkoutNode(nodeId, opts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels a checkout. Accepts either the working copy or the original node.
|
||||
* Deletes the working copy and unlocks the original.
|
||||
*
|
||||
* @param nodeId ID of the working copy or the original checked-out node
|
||||
* @param opts Optional query parameters (`include`, `fields`)
|
||||
* @returns Observable emitting the original (unlocked) node
|
||||
*/
|
||||
cancelCheckoutNode(nodeId: string, opts?: NodesIncludeQuery): Observable<NodeEntry> {
|
||||
return from(this.nodesApi.cancelCheckoutNode(nodeId, opts));
|
||||
}
|
||||
|
||||
private randomNodeName(): string {
|
||||
return `node_${Date.now()}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user