mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-06-30 18:14:45 +00:00
[ACA-1635][ACA-1636] update favoritesApi and nodesApi to use alfresco-js-api-node (#564)
* refactor favoritesApi and nodesApi to use alfresco-js-api-node * remove node-rest-client
This commit is contained in:
parent
213c2deedc
commit
86a90d33e2
@ -62,15 +62,15 @@ describe('Delete and undo delete', () => {
|
||||
const fileLocked1 = `fileLocked-${Utils.random()}.txt`; let fileLocked1Id;
|
||||
|
||||
beforeAll(done => {
|
||||
apis.user.nodes.createFile(file1).then(resp => file1Id = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(file2).then(resp => file2Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder(folder1).then(resp => folder1Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder(folder2).then(resp => folder2Id = resp.data.entry.id))
|
||||
apis.user.nodes.createFile(file1).then(resp => file1Id = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(file2).then(resp => file2Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder(folder1).then(resp => folder1Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder(folder2).then(resp => folder2Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(file3, folder1Id))
|
||||
.then(() => apis.user.nodes.createFile(file4, folder2Id).then(resp => file4Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(file4, folder2Id).then(resp => file4Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.lockFile(file4Id))
|
||||
|
||||
.then(() => apis.user.nodes.createFile(fileLocked1).then(resp => fileLocked1Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(fileLocked1).then(resp => fileLocked1Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.lockFile(fileLocked1Id))
|
||||
|
||||
.then(() => loginPage.loginWith(username))
|
||||
@ -275,10 +275,10 @@ describe('Delete and undo delete', () => {
|
||||
const sharedFile4 = `sharedFile4-${Utils.random()}.txt`; let sharedFile4Id;
|
||||
|
||||
beforeAll(done => {
|
||||
apis.user.nodes.createFile(sharedFile1).then(resp => sharedFile1Id = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(sharedFile2).then(resp => sharedFile2Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(sharedFile3).then(resp => sharedFile3Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(sharedFile4).then(resp => sharedFile4Id = resp.data.entry.id))
|
||||
apis.user.nodes.createFile(sharedFile1).then(resp => sharedFile1Id = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(sharedFile2).then(resp => sharedFile2Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(sharedFile3).then(resp => sharedFile3Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(sharedFile4).then(resp => sharedFile4Id = resp.entry.id))
|
||||
.then(() => apis.user.shared.shareFilesByIds([sharedFile1Id, sharedFile2Id, sharedFile3Id, sharedFile4Id]))
|
||||
.then(() => apis.user.shared.waitForApi({ expect: 4 }))
|
||||
|
||||
@ -386,15 +386,15 @@ describe('Delete and undo delete', () => {
|
||||
const favoriteFileLocked1 = `favFileLocked-${Utils.random()}.txt`; let favoriteFileLocked1Id;
|
||||
|
||||
beforeAll(done => {
|
||||
apis.user.nodes.createFile(favoriteFile1).then(resp => favoriteFile1Id = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(favoriteFile2).then(resp => favoriteFile2Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder(favoriteFolder1).then(resp => favoriteFolder1Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder(favoriteFolder2).then(resp => favoriteFolder2Id = resp.data.entry.id))
|
||||
apis.user.nodes.createFile(favoriteFile1).then(resp => favoriteFile1Id = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(favoriteFile2).then(resp => favoriteFile2Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder(favoriteFolder1).then(resp => favoriteFolder1Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder(favoriteFolder2).then(resp => favoriteFolder2Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(favoriteFile3, favoriteFolder1Id))
|
||||
.then(() => apis.user.nodes.createFile(favoriteFile4, favoriteFolder2Id).then(resp => favoriteFile4Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(favoriteFile4, favoriteFolder2Id).then(resp => favoriteFile4Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.lockFile(favoriteFile4Id))
|
||||
|
||||
.then(() => apis.user.nodes.createFile(favoriteFileLocked1).then(resp => favoriteFileLocked1Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(favoriteFileLocked1).then(resp => favoriteFileLocked1Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.lockFile(favoriteFileLocked1Id))
|
||||
|
||||
.then(() => apis.user.favorites.addFavoritesByIds('file', [favoriteFile1Id, favoriteFile2Id, favoriteFileLocked1Id]))
|
||||
@ -603,10 +603,10 @@ describe('Delete and undo delete', () => {
|
||||
const recentFile4 = `recentFile4-${Utils.random()}.txt`; let recentFile4Id;
|
||||
|
||||
beforeAll(done => {
|
||||
apis.user.nodes.createFile(recentFile1).then(resp => recentFile1Id = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(recentFile2).then(resp => recentFile2Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(recentFile3).then(resp => recentFile3Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(recentFile4).then(resp => recentFile4Id = resp.data.entry.id))
|
||||
apis.user.nodes.createFile(recentFile1).then(resp => recentFile1Id = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(recentFile2).then(resp => recentFile2Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(recentFile3).then(resp => recentFile3Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(recentFile4).then(resp => recentFile4Id = resp.entry.id))
|
||||
.then(() => apis.user.search.waitForApi(username, { expect: 4 }))
|
||||
|
||||
.then(() => loginPage.loginWith(username))
|
||||
|
@ -64,7 +64,7 @@ describe('Edit folder', () => {
|
||||
.then(() => apis.admin.sites.addSiteMember(siteName, username, SITE_ROLES.SITE_CONSUMER))
|
||||
|
||||
.then(() => apis.user.nodes.createFolder( parent ))
|
||||
.then(resp => apis.user.nodes.createFolder( folderName, resp.data.entry.id, '', folderDescription ))
|
||||
.then(resp => apis.user.nodes.createFolder( folderName, resp.entry.id, '', folderDescription ))
|
||||
.then(() => apis.user.nodes.createFolders([ folderNameToEdit, duplicateFolderName ], parent))
|
||||
|
||||
.then(() => loginPage.loginWith(username))
|
||||
|
@ -52,11 +52,11 @@ describe('Mark items as favorites', () => {
|
||||
|
||||
beforeAll(done => {
|
||||
apis.admin.people.createUser({ username })
|
||||
.then(() => apis.user.nodes.createFile( file1NotFav ).then(resp => file1Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFile( file2NotFav ).then(resp => file2Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFile( file3Fav ).then(resp => file3Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFile( file4Fav ).then(resp => file4Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder( folder1 ).then(resp => folder1Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFile( file1NotFav ).then(resp => file1Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFile( file2NotFav ).then(resp => file2Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFile( file3Fav ).then(resp => file3Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFile( file4Fav ).then(resp => file4Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder( folder1 ).then(resp => folder1Id = resp.entry.id))
|
||||
|
||||
.then(() => apis.user.favorites.addFavoriteById('file', file3Id))
|
||||
.then(() => apis.user.favorites.addFavoriteById('file', file4Id))
|
||||
|
@ -52,9 +52,9 @@ describe('Permanently delete from Trash', () => {
|
||||
beforeAll(done => {
|
||||
apis.admin.people.createUser({ username })
|
||||
.then(() => apis.user.nodes.createFiles([ file1, file2 ]))
|
||||
.then(resp => filesIds = resp.data.list.entries.map(entries => entries.entry.id))
|
||||
.then(resp => filesIds = resp.list.entries.map(entries => entries.entry.id))
|
||||
.then(() => apis.user.nodes.createFolders([ folder1, folder2 ]))
|
||||
.then(resp => foldersIds = resp.data.list.entries.map(entries => entries.entry.id))
|
||||
.then(resp => foldersIds = resp.list.entries.map(entries => entries.entry.id))
|
||||
|
||||
.then(() => apis.user.nodes.deleteNodesById(filesIds, false))
|
||||
.then(() => apis.user.nodes.deleteNodesById(foldersIds, false))
|
||||
|
@ -63,8 +63,8 @@ describe('Restore from Trash', () => {
|
||||
const folder = `folder-${Utils.random()}`; let folderId;
|
||||
|
||||
beforeAll(done => {
|
||||
apis.user.nodes.createFile(file).then(resp => fileId = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFolder(folder).then(resp => folderId = resp.data.entry.id))
|
||||
apis.user.nodes.createFile(file).then(resp => fileId = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFolder(folder).then(resp => folderId = resp.entry.id))
|
||||
.then(() => apis.user.nodes.deleteNodesById([ fileId, folderId ], false))
|
||||
.then(done);
|
||||
});
|
||||
@ -157,13 +157,13 @@ describe('Restore from Trash', () => {
|
||||
const folder2 = `folder-${Utils.random()}`; let folder2Id;
|
||||
|
||||
beforeAll(done => {
|
||||
apis.user.nodes.createFolder(folder1).then(resp => folder1Id = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(file1, folder1Id).then(resp => file1Id1 = resp.data.entry.id))
|
||||
apis.user.nodes.createFolder(folder1).then(resp => folder1Id = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(file1, folder1Id).then(resp => file1Id1 = resp.entry.id))
|
||||
.then(() => apis.user.nodes.deleteNodeById(file1Id1, false))
|
||||
.then(() => apis.user.nodes.createFile(file1, folder1Id).then(resp => file1Id2 = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(file1, folder1Id).then(resp => file1Id2 = resp.entry.id))
|
||||
|
||||
.then(() => apis.user.nodes.createFolder(folder2).then(resp => folder2Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(file2, folder2Id).then(resp => file2Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder(folder2).then(resp => folder2Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(file2, folder2Id).then(resp => file2Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.deleteNodeById(file2Id, false))
|
||||
.then(() => apis.user.nodes.deleteNodeById(folder2Id, false))
|
||||
|
||||
@ -215,19 +215,19 @@ describe('Restore from Trash', () => {
|
||||
const file5 = `file5-${Utils.random()}.txt`; let file5Id;
|
||||
|
||||
beforeAll(done => {
|
||||
apis.user.nodes.createFolder(folder1).then(resp => folder1Id = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(file1, folder1Id).then(resp => file1Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder(folder2).then(resp => folder2Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(file2, folder2Id).then(resp => file2Id = resp.data.entry.id))
|
||||
apis.user.nodes.createFolder(folder1).then(resp => folder1Id = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(file1, folder1Id).then(resp => file1Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder(folder2).then(resp => folder2Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(file2, folder2Id).then(resp => file2Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.deleteNodeById(file1Id, false))
|
||||
.then(() => apis.user.nodes.deleteNodeById(folder1Id, false))
|
||||
.then(() => apis.user.nodes.deleteNodeById(file2Id, false))
|
||||
|
||||
.then(() => apis.user.nodes.createFolder(folder3).then(resp => folder3Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(file3, folder3Id).then(resp => file3Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(file4, folder3Id).then(resp => file4Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder(folder4).then(resp => folder4Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(file5, folder4Id).then(resp => file5Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder(folder3).then(resp => folder3Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(file3, folder3Id).then(resp => file3Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(file4, folder3Id).then(resp => file4Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder(folder4).then(resp => folder4Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFile(file5, folder4Id).then(resp => file5Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.deleteNodeById(file3Id, false))
|
||||
.then(() => apis.user.nodes.deleteNodeById(file4Id, false))
|
||||
.then(() => apis.user.nodes.deleteNodeById(folder3Id, false))
|
||||
|
@ -67,14 +67,14 @@ describe('Toolbar actions - multiple selection : ', () => {
|
||||
|
||||
beforeAll(done => {
|
||||
apis.admin.people.createUser({ username: user1 })
|
||||
.then(() => apis.user.nodes.createFiles([ file1 ]).then(resp => file1Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFiles([ file2 ]).then(resp => file2Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFolders([ folder1 ]).then(resp => folder1Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFolders([ folder2 ]).then(resp => folder2Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFiles([ fileForDelete1 ]).then(resp => fileForDelete1Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFiles([ fileForDelete2 ]).then(resp => fileForDelete2Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFolders([ folderForDelete1 ]).then(resp => folderForDelete1Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFolders([ folderForDelete2 ]).then(resp => folderForDelete2Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFiles([ file1 ]).then(resp => file1Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFiles([ file2 ]).then(resp => file2Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFolders([ folder1 ]).then(resp => folder1Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFolders([ folder2 ]).then(resp => folder2Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFiles([ fileForDelete1 ]).then(resp => fileForDelete1Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFiles([ fileForDelete2 ]).then(resp => fileForDelete2Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFolders([ folderForDelete1 ]).then(resp => folderForDelete1Id = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFolders([ folderForDelete2 ]).then(resp => folderForDelete2Id = resp.entry.id))
|
||||
|
||||
.then(() => apis.user.shared.shareFilesByIds([ file1Id, file2Id ]))
|
||||
.then(() => apis.user.shared.waitForApi({ expect: 2 }))
|
||||
|
@ -55,10 +55,10 @@ describe('Toolbar actions - single selection : ', () => {
|
||||
beforeAll(async (done) => {
|
||||
await apis.admin.people.createUser({ username });
|
||||
|
||||
fileUserId = (await apis.user.nodes.createFiles([fileUser])).data.entry.id;
|
||||
fileForDeleteId = (await apis.user.nodes.createFiles([fileForDelete])).data.entry.id;
|
||||
folderForDeleteId = (await apis.user.nodes.createFolders([ folderForDelete ])).data.entry.id;
|
||||
folderUserId = (await apis.user.nodes.createFolders([ folderUser ])).data.entry.id;
|
||||
fileUserId = (await apis.user.nodes.createFiles([fileUser])).entry.id;
|
||||
fileForDeleteId = (await apis.user.nodes.createFiles([fileForDelete])).entry.id;
|
||||
folderForDeleteId = (await apis.user.nodes.createFolders([ folderForDelete ])).entry.id;
|
||||
folderUserId = (await apis.user.nodes.createFolders([ folderUser ])).entry.id;
|
||||
|
||||
await apis.user.shared.shareFileById(fileUserId);
|
||||
await apis.user.shared.waitForApi({ expect: 1 });
|
||||
@ -123,8 +123,8 @@ describe('Toolbar actions - single selection : ', () => {
|
||||
await apis.admin.sites.createSite(site, SITE_VISIBILITY.PRIVATE);
|
||||
const docLibId = await apis.admin.sites.getDocLibId(site);
|
||||
|
||||
file1Id = (await apis.admin.nodes.createFile(file1, docLibId)).data.entry.id;
|
||||
file2Id = (await apis.admin.nodes.createFile(file2, docLibId)).data.entry.id;
|
||||
file1Id = (await apis.admin.nodes.createFile(file1, docLibId)).entry.id;
|
||||
file2Id = (await apis.admin.nodes.createFile(file2, docLibId)).entry.id;
|
||||
|
||||
await apis.admin.sites.addSiteMember(site, username, SITE_ROLES.SITE_CONSUMER);
|
||||
await apis.admin.nodes.setGranularPermission(file1Id, false, username, SITE_ROLES.SITE_CONSUMER);
|
||||
|
@ -46,7 +46,7 @@ describe('Upload files', () => {
|
||||
|
||||
beforeAll(done => {
|
||||
apis.admin.people.createUser({ username })
|
||||
.then(() => apis.user.nodes.createFolder(folder1).then(resp => folder1Id = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder(folder1).then(resp => folder1Id = resp.entry.id))
|
||||
|
||||
.then(() => loginPage.loginWith(username))
|
||||
.then(done);
|
||||
|
@ -58,22 +58,22 @@ describe('Favorites', () => {
|
||||
const docLibId = await apis.admin.sites.getDocLibId(siteName);
|
||||
await apis.admin.sites.addSiteMember(siteName, username, SITE_ROLES.SITE_MANAGER);
|
||||
|
||||
const file1Id = (await apis.admin.nodes.createFile(fileName1, docLibId)).data.entry.id;
|
||||
const file1Id = (await apis.admin.nodes.createFile(fileName1, docLibId)).entry.id;
|
||||
await apis.user.favorites.addFavoriteById('file', file1Id);
|
||||
|
||||
const folderId = (await apis.user.nodes.createFolder(favFolderName)).data.entry.id;
|
||||
const folderId = (await apis.user.nodes.createFolder(favFolderName)).entry.id;
|
||||
await apis.user.favorites.addFavoriteById('folder', folderId);
|
||||
|
||||
const parentId = (await apis.user.nodes.createFolder(parentFolder)).data.entry.id;
|
||||
const parentId = (await apis.user.nodes.createFolder(parentFolder)).entry.id;
|
||||
|
||||
const file2Id = (await apis.user.nodes.createFile(fileName2, parentId)).data.entry.id;
|
||||
const file2Id = (await apis.user.nodes.createFile(fileName2, parentId)).entry.id;
|
||||
await apis.user.favorites.addFavoriteById('file', file2Id);
|
||||
|
||||
const file3Id = (await apis.user.nodes.createFile(fileName3, parentId)).data.entry.id;
|
||||
const file3Id = (await apis.user.nodes.createFile(fileName3, parentId)).entry.id;
|
||||
await apis.user.favorites.addFavoriteById('file', file3Id);
|
||||
await apis.user.nodes.deleteNodeById(file3Id, false);
|
||||
|
||||
const file4Id = (await apis.user.nodes.createFile(fileName4, parentId)).data.entry.id;
|
||||
const file4Id = (await apis.user.nodes.createFile(fileName4, parentId)).entry.id;
|
||||
await apis.user.favorites.addFavoriteById('file', file4Id);
|
||||
await apis.user.nodes.deleteNodeById(file4Id, false);
|
||||
await apis.user.trashcan.restore(file4Id);
|
||||
|
@ -59,7 +59,7 @@ describe('Special permissions', () => {
|
||||
apis.admin.sites.createSite(sitePrivate, SITE_VISIBILITY.PRIVATE)
|
||||
.then(() => apis.admin.sites.addSiteMember(sitePrivate, username, SITE_ROLES.SITE_COLLABORATOR))
|
||||
.then(() => apis.admin.nodes.createFiles([ fileName ], `Sites/${sitePrivate}/documentLibrary`)
|
||||
.then(resp => fileId = resp.data.entry.id))
|
||||
.then(resp => fileId = resp.entry.id))
|
||||
.then(() => apis.user.favorites.addFavoriteById('file', fileId))
|
||||
.then(() => apis.admin.shared.shareFileById(fileId))
|
||||
.then(() => apis.user.nodes.editNodeContent(fileId, 'edited by user'))
|
||||
@ -133,7 +133,7 @@ describe('Special permissions', () => {
|
||||
.then(() => apis.admin.sites.addSiteMember(sitePrivate, username, SITE_ROLES.SITE_COLLABORATOR))
|
||||
.then(() => apis.admin.sites.getDocLibId(sitePrivate))
|
||||
.then(resp => apis.user.nodes.createFile(fileName, resp))
|
||||
.then(resp => fileId = resp.data.entry.id)
|
||||
.then(resp => fileId = resp.entry.id)
|
||||
.then(() => apis.user.favorites.addFavoriteById('file', fileId))
|
||||
.then(() => apis.user.shared.shareFileById(fileId))
|
||||
.then(() => apis.user.shared.waitForApi({ expect: 1 }))
|
||||
|
@ -129,7 +129,7 @@ describe('Personal Files', () => {
|
||||
it('navigates to folder - [C213244]', () => {
|
||||
const getNodeIdPromise = apis.user.nodes
|
||||
.getNodeByPath(`/${userFolder}`)
|
||||
.then(response => response.data.entry.id);
|
||||
.then(response => response.entry.id);
|
||||
|
||||
const navigatePromise = dataTable
|
||||
.doubleClickOnRowByName(userFolder)
|
||||
|
@ -53,14 +53,14 @@ describe('Recent Files', () => {
|
||||
|
||||
beforeAll(done => {
|
||||
apis.admin.people.createUser({ username })
|
||||
.then(() => apis.user.nodes.createFolders([ folderName ])).then(resp => folderId = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFolders([ folderName ])).then(resp => folderId = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFiles([ fileName1 ], folderName))
|
||||
.then(() => apis.user.nodes.createFiles([ fileName2 ])).then(resp => file2Id = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFiles([ fileName3 ]).then(resp => apis.user.nodes.deleteNodeById(resp.data.entry.id, false)))
|
||||
.then(() => apis.user.nodes.createFiles([ fileName2 ])).then(resp => file2Id = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFiles([ fileName3 ]).then(resp => apis.user.nodes.deleteNodeById(resp.entry.id, false)))
|
||||
|
||||
.then(() => apis.user.sites.createSite(siteName, SITE_VISIBILITY.PUBLIC))
|
||||
.then(() => apis.user.sites.getDocLibId(siteName))
|
||||
.then(resp => apis.user.nodes.createFolder(folderSite, resp)).then(resp => folderSiteId = resp.data.entry.id)
|
||||
.then(resp => apis.user.nodes.createFolder(folderSite, resp)).then(resp => folderSiteId = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(fileSite, folderSiteId))
|
||||
|
||||
.then(() => apis.user.search.waitForApi(username, { expect: 3 }))
|
||||
|
@ -57,13 +57,13 @@ describe('Shared Files', () => {
|
||||
.then(() => apis.admin.sites.createSite(siteName, SITE_VISIBILITY.PUBLIC))
|
||||
.then(() => apis.admin.sites.addSiteMember(siteName, username, SITE_ROLES.SITE_CONSUMER))
|
||||
.then(() => apis.admin.nodes.createFiles([ fileAdmin ], `Sites/${siteName}/documentLibrary`))
|
||||
.then(resp => apis.admin.shared.shareFileById(resp.data.entry.id))
|
||||
.then(resp => apis.admin.shared.shareFileById(resp.entry.id))
|
||||
|
||||
.then(() => apis.user.nodes.createFolders([ folderUser ]))
|
||||
.then(() => apis.user.nodes.createFiles([ file1User ], folderUser)).then(resp => file1Id = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(file2User)).then(resp => file2Id = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(file3User)).then(resp => file3Id = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(file4User)).then(resp => file4Id = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFiles([ file1User ], folderUser)).then(resp => file1Id = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(file2User)).then(resp => file2Id = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(file3User)).then(resp => file3Id = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(file4User)).then(resp => file4Id = resp.entry.id)
|
||||
.then(() => apis.user.shared.shareFilesByIds([file1Id, file2Id, file3Id, file4Id]))
|
||||
|
||||
.then(() => apis.user.shared.waitForApi({ expect: 5 }))
|
||||
|
@ -59,21 +59,21 @@ describe('File / folder tooltips', () => {
|
||||
beforeAll(done => {
|
||||
apis.admin.people.createUser({ username })
|
||||
.then(() => apis.user.nodes.createFolder( parent ))
|
||||
.then(resp => parentId = resp.data.entry.id)
|
||||
.then(resp => parentId = resp.entry.id)
|
||||
|
||||
.then(() => Promise.all([
|
||||
apis.user.nodes.createFile(file, parentId).then(resp => file1Id = resp.data.entry.id),
|
||||
apis.user.nodes.createFile(fileWithDesc, parentId, '', fileDescription).then(resp => file2Id = resp.data.entry.id),
|
||||
apis.user.nodes.createFile(fileWithTitle, parentId, fileTitle).then(resp => file3Id = resp.data.entry.id),
|
||||
apis.user.nodes.createFile(file, parentId).then(resp => file1Id = resp.entry.id),
|
||||
apis.user.nodes.createFile(fileWithDesc, parentId, '', fileDescription).then(resp => file2Id = resp.entry.id),
|
||||
apis.user.nodes.createFile(fileWithTitle, parentId, fileTitle).then(resp => file3Id = resp.entry.id),
|
||||
apis.user.nodes.createFile(fileWithTitleAndDesc, parentId, fileTitle, fileDescription)
|
||||
.then(resp => file4Id = resp.data.entry.id),
|
||||
.then(resp => file4Id = resp.entry.id),
|
||||
apis.user.nodes.createFile(fileNameEqTitleEqDesc, parentId, fileNameEqTitleEqDesc, fileNameEqTitleEqDesc)
|
||||
.then(resp => file5Id = resp.data.entry.id),
|
||||
.then(resp => file5Id = resp.entry.id),
|
||||
apis.user.nodes.createFile(fileNameEqTitleDiffDesc, parentId, fileNameEqTitleDiffDesc, fileDescription)
|
||||
.then(resp => file6Id = resp.data.entry.id),
|
||||
.then(resp => file6Id = resp.entry.id),
|
||||
apis.user.nodes.createFile(fileNameEqDescDiffTitle, parentId, fileTitle, fileNameEqDescDiffTitle)
|
||||
.then(resp => file7Id = resp.data.entry.id),
|
||||
apis.user.nodes.createFile(fileTitleEqDesc, parentId, fileTitle, fileTitle).then(resp => file8Id = resp.data.entry.id)
|
||||
.then(resp => file7Id = resp.entry.id),
|
||||
apis.user.nodes.createFile(fileTitleEqDesc, parentId, fileTitle, fileTitle).then(resp => file8Id = resp.entry.id)
|
||||
]))
|
||||
|
||||
.then(() => apis.user.shared.shareFilesByIds([ file1Id, file2Id, file3Id, file4Id, file5Id, file6Id, file7Id, file8Id ]))
|
||||
@ -265,24 +265,24 @@ describe('File / folder tooltips', () => {
|
||||
|
||||
beforeAll(done => {
|
||||
apis.user.nodes.createFolder( parentForTrash )
|
||||
.then(resp => parentForTrashId = resp.data.entry.id)
|
||||
.then(resp => parentForTrashId = resp.entry.id)
|
||||
.then(() => Promise.all([
|
||||
apis.user.nodes.createFile(file, parentForTrashId)
|
||||
.then(resp => file1TrashId = resp.data.entry.id),
|
||||
.then(resp => file1TrashId = resp.entry.id),
|
||||
apis.user.nodes.createFile(fileWithDesc, parentForTrashId, '', fileDescription)
|
||||
.then(resp => file2TrashId = resp.data.entry.id),
|
||||
.then(resp => file2TrashId = resp.entry.id),
|
||||
apis.user.nodes.createFile(fileWithTitle, parentForTrashId, fileTitle)
|
||||
.then(resp => file3TrashId = resp.data.entry.id),
|
||||
.then(resp => file3TrashId = resp.entry.id),
|
||||
apis.user.nodes.createFile(fileWithTitleAndDesc, parentForTrashId, fileTitle, fileDescription)
|
||||
.then(resp => file4TrashId = resp.data.entry.id),
|
||||
.then(resp => file4TrashId = resp.entry.id),
|
||||
apis.user.nodes.createFile(fileNameEqTitleEqDesc, parentForTrashId, fileNameEqTitleEqDesc, fileNameEqTitleEqDesc)
|
||||
.then(resp => file5TrashId = resp.data.entry.id),
|
||||
.then(resp => file5TrashId = resp.entry.id),
|
||||
apis.user.nodes.createFile(fileNameEqTitleDiffDesc, parentForTrashId, fileNameEqTitleDiffDesc, fileDescription)
|
||||
.then(resp => file6TrashId = resp.data.entry.id),
|
||||
.then(resp => file6TrashId = resp.entry.id),
|
||||
apis.user.nodes.createFile(fileNameEqDescDiffTitle, parentForTrashId, fileTitle, fileNameEqDescDiffTitle)
|
||||
.then(resp => file7TrashId = resp.data.entry.id),
|
||||
.then(resp => file7TrashId = resp.entry.id),
|
||||
apis.user.nodes.createFile(fileTitleEqDesc, parentForTrashId, fileTitle, fileTitle)
|
||||
.then(resp => file8TrashId = resp.data.entry.id)
|
||||
.then(resp => file8TrashId = resp.entry.id)
|
||||
]))
|
||||
|
||||
.then(() => apis.user.nodes.deleteNodesById([
|
||||
|
@ -60,18 +60,18 @@ describe('Trash', () => {
|
||||
|
||||
beforeAll(done => {
|
||||
apis.admin.people.createUser({ username })
|
||||
.then(() => apis.admin.nodes.createFiles([ fileAdmin ]).then(resp => fileAdminId = resp.data.entry.id))
|
||||
.then(() => apis.admin.nodes.createFolders([ folderAdmin ]).then(resp => folderAdminId = resp.data.entry.id))
|
||||
.then(() => apis.admin.nodes.createFiles([ fileAdmin ]).then(resp => fileAdminId = resp.entry.id))
|
||||
.then(() => apis.admin.nodes.createFolders([ folderAdmin ]).then(resp => folderAdminId = resp.entry.id))
|
||||
.then(() => apis.admin.sites.createSite(siteName, SITE_VISIBILITY.PUBLIC))
|
||||
.then(() => apis.admin.sites.addSiteMember(siteName, username, SITE_ROLES.SITE_MANAGER))
|
||||
.then(() => apis.admin.nodes.createFiles([ fileSite ], `Sites/${siteName}/documentLibrary`)
|
||||
.then(resp => fileSiteId = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFiles([ fileUser ]).then(resp => fileUserId = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFolders([ folderUser ]).then(resp => folderUserId = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder(folderDeleted).then(resp => folderDeletedId = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFiles([ fileDeleted ], folderDeleted).then(resp => fileDeletedId = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder(folderNotDeleted).then(resp => folderNotDeletedId = resp.data.entry.id))
|
||||
.then(() => apis.user.nodes.createFiles([ fileInFolder ], folderNotDeleted).then(resp => fileInFolderId = resp.data.entry.id))
|
||||
.then(resp => fileSiteId = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFiles([ fileUser ]).then(resp => fileUserId = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFolders([ folderUser ]).then(resp => folderUserId = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder(folderDeleted).then(resp => folderDeletedId = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFiles([ fileDeleted ], folderDeleted).then(resp => fileDeletedId = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFolder(folderNotDeleted).then(resp => folderNotDeletedId = resp.entry.id))
|
||||
.then(() => apis.user.nodes.createFiles([ fileInFolder ], folderNotDeleted).then(resp => fileInFolderId = resp.entry.id))
|
||||
|
||||
.then(() => apis.admin.nodes.deleteNodesById([ fileAdminId, folderAdminId ], false))
|
||||
.then(() => apis.user.nodes.deleteNodesById([ fileSiteId, fileUserId, folderUserId, fileInFolderId ], false))
|
||||
|
@ -56,19 +56,19 @@ describe('Breadcrumb', () => {
|
||||
|
||||
beforeAll(done => {
|
||||
apis.admin.people.createUser({ username })
|
||||
.then(() => apis.user.nodes.createFolder(parent)).then(resp => parentId = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFolder(subFolder1, parentId)).then(resp => subFolder1Id = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFolder(subFolder2, subFolder1Id)).then(resp => subFolder2Id = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFolder(parent)).then(resp => parentId = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFolder(subFolder1, parentId)).then(resp => subFolder1Id = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFolder(subFolder2, subFolder1Id)).then(resp => subFolder2Id = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(fileName1, subFolder2Id))
|
||||
|
||||
.then(() => apis.user.nodes.createFolder(parent2)).then(resp => parent2Id = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFolder(folder1, parent2Id)).then(resp => folder1Id = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFolder(parent2)).then(resp => parent2Id = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFolder(folder1, parent2Id)).then(resp => folder1Id = resp.entry.id)
|
||||
|
||||
.then(() => apis.user.sites.createSite(siteName, SITE_VISIBILITY.PUBLIC))
|
||||
.then(() => apis.user.sites.getDocLibId(siteName))
|
||||
.then(resp => apis.user.nodes.createFolder(parent, resp)).then(resp => parentId = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFolder(subFolder1, parentId)).then(resp => subFolder1Id = resp.data.entry.id)
|
||||
.then(() => apis.user.nodes.createFolder(subFolder2, subFolder1Id)).then(resp => subFolder2Id = resp.data.entry.id)
|
||||
.then(resp => apis.user.nodes.createFolder(parent, resp)).then(resp => parentId = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFolder(subFolder1, parentId)).then(resp => subFolder1Id = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFolder(subFolder2, subFolder1Id)).then(resp => subFolder2Id = resp.entry.id)
|
||||
.then(() => apis.user.nodes.createFile(fileName1, subFolder2Id))
|
||||
|
||||
.then(() => loginPage.loginWith(username))
|
||||
@ -220,7 +220,7 @@ describe('Breadcrumb', () => {
|
||||
beforeAll(done => {
|
||||
logoutPage.load()
|
||||
.then(() => apis.admin.people.createUser({ username: user2 }))
|
||||
.then(() => user2Api.nodes.createFolder(userFolder).then(resp => userFolderId = resp.data.entry.id))
|
||||
.then(() => user2Api.nodes.createFolder(userFolder).then(resp => userFolderId = resp.entry.id))
|
||||
.then(() => loginPage.loginWithAdmin())
|
||||
.then(done);
|
||||
});
|
||||
|
@ -81,7 +81,7 @@ describe('Pagination on Favorites', () => {
|
||||
|
||||
describe('on single page', () => {
|
||||
beforeAll(done => {
|
||||
nodesApi.createFile(file).then(resp => fileId = resp.data.entry.id)
|
||||
nodesApi.createFile(file).then(resp => fileId = resp.entry.id)
|
||||
.then(() => favoritesApi.addFavoriteById('file', fileId))
|
||||
.then(() => loginPage.loginWith(username))
|
||||
.then(done);
|
||||
@ -105,7 +105,7 @@ describe('Pagination on Favorites', () => {
|
||||
describe('on multiple pages', () => {
|
||||
beforeAll(done => {
|
||||
nodesApi.createFiles(files, parent)
|
||||
.then(resp => filesIds = resp.data.list.entries.map(entries => entries.entry.id))
|
||||
.then(resp => filesIds = resp.list.entries.map(entries => entries.entry.id))
|
||||
.then(() => favoritesApi.addFavoritesByIds('file', filesIds))
|
||||
.then(() => favoritesApi.waitForApi({ expect: 101 }))
|
||||
.then(() => loginPage.loginWith(username))
|
||||
|
@ -80,7 +80,7 @@ describe('Pagination on Personal Files', () => {
|
||||
|
||||
describe('on single page', () => {
|
||||
beforeAll(done => {
|
||||
nodesApi.createFile(file).then(resp => fileId = resp.data.entry.id)
|
||||
nodesApi.createFile(file).then(resp => fileId = resp.entry.id)
|
||||
.then(() => loginPage.loginWith(username))
|
||||
.then(done);
|
||||
});
|
||||
|
@ -80,7 +80,7 @@ describe('Pagination on Recent Files', () => {
|
||||
|
||||
describe('on single page', () => {
|
||||
beforeAll(done => {
|
||||
nodesApi.createFile(file).then(resp => fileId = resp.data.entry.id)
|
||||
nodesApi.createFile(file).then(resp => fileId = resp.entry.id)
|
||||
.then(() => searchApi.waitForApi(username, { expect: 1 }))
|
||||
.then(() => loginPage.loginWith(username))
|
||||
.then(done);
|
||||
|
@ -81,7 +81,7 @@ describe('Pagination on Shared Files', () => {
|
||||
|
||||
describe('on single page', () => {
|
||||
beforeAll(done => {
|
||||
nodesApi.createFile(file).then(resp => fileId = resp.data.entry.id)
|
||||
nodesApi.createFile(file).then(resp => fileId = resp.entry.id)
|
||||
.then(() => sharedApi.shareFileById(fileId))
|
||||
.then(() => sharedApi.waitForApi({ expect: 1 }))
|
||||
.then(() => loginPage.loginWith(username))
|
||||
@ -106,7 +106,7 @@ describe('Pagination on Shared Files', () => {
|
||||
describe('on multiple pages', () => {
|
||||
beforeAll(done => {
|
||||
nodesApi.createFiles(files, parent)
|
||||
.then(resp => filesIds = resp.data.list.entries.map(entries => entries.entry.id))
|
||||
.then(resp => filesIds = resp.list.entries.map(entries => entries.entry.id))
|
||||
|
||||
.then(() => sharedApi.shareFilesByIds(filesIds))
|
||||
.then(() => sharedApi.waitForApi({ expect: 101 }))
|
||||
|
@ -80,7 +80,7 @@ describe('Pagination on Trash', () => {
|
||||
|
||||
describe('on single page', () => {
|
||||
beforeAll(done => {
|
||||
nodesApi.createFile(file).then(resp => fileId = resp.data.entry.id)
|
||||
nodesApi.createFile(file).then(resp => fileId = resp.entry.id)
|
||||
.then(() => nodesApi.deleteNodeById(fileId, false))
|
||||
.then(() => trashApi.waitForApi({ expect: 1 }))
|
||||
.then(() => loginPage.loginWith(username))
|
||||
@ -105,7 +105,7 @@ describe('Pagination on Trash', () => {
|
||||
describe('on multiple pages', () => {
|
||||
beforeAll(done => {
|
||||
nodesApi.createFiles(filesForDelete)
|
||||
.then(resp => filesDeletedIds = resp.data.list.entries.map(entries => entries.entry.id))
|
||||
.then(resp => filesDeletedIds = resp.list.entries.map(entries => entries.entry.id))
|
||||
.then(() => nodesApi.deleteNodesById(filesDeletedIds, false))
|
||||
.then(() => trashApi.waitForApi({expect: 101}))
|
||||
|
||||
|
@ -23,96 +23,82 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { promise } from 'protractor';
|
||||
import { RepoApi } from '../repo-api';
|
||||
import { NodesApi } from '../nodes/nodes-api';
|
||||
import { RepoClient } from './../../repo-client';
|
||||
import { Utils } from '../../../../utilities/utils';
|
||||
|
||||
export class FavoritesApi extends RepoApi {
|
||||
|
||||
addFavorite(api: RepoClient, nodeType: string, name: string): Promise<any> {
|
||||
return api.nodes.getNodeByPath(name)
|
||||
.then((response) => {
|
||||
const { id } = response.data.entry;
|
||||
return ([{
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
async addFavorite(api: RepoClient, nodeType: string, name: string) {
|
||||
const nodeId = (await api.nodes.getNodeByPath(name)).entry.id;
|
||||
const data = {
|
||||
target: {
|
||||
[nodeType]: {
|
||||
guid: nodeId
|
||||
}
|
||||
}
|
||||
};
|
||||
return await this.alfrescoJsApi.core.favoritesApi.addFavorite('-me-', data);
|
||||
}
|
||||
|
||||
async addFavoriteById(nodeType: 'file' | 'folder', id: string) {
|
||||
const data = {
|
||||
target: {
|
||||
[nodeType]: {
|
||||
guid: id
|
||||
}
|
||||
}
|
||||
}]);
|
||||
})
|
||||
.then((data) => {
|
||||
return this.post(`/people/-me-/favorites`, { data });
|
||||
})
|
||||
.catch(this.handleError);
|
||||
};
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.favoritesApi.addFavorite('-me-', data);
|
||||
}
|
||||
|
||||
addFavoriteById(nodeType: 'file' | 'folder', id: string): Promise<any> {
|
||||
const data = [{
|
||||
target: {
|
||||
[nodeType]: {
|
||||
guid: id
|
||||
}
|
||||
}
|
||||
}];
|
||||
return this
|
||||
.post(`/people/-me-/favorites`, { data })
|
||||
.catch(this.handleError);
|
||||
async addFavoritesByIds(nodeType: 'file' | 'folder', ids: string[]) {
|
||||
await this.apiAuth();
|
||||
return await ids.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
await this.addFavoriteById(nodeType, current);
|
||||
}, Promise.resolve());
|
||||
}
|
||||
|
||||
addFavoritesByIds(nodeType: 'file' | 'folder', ids: string[]): Promise<any[]> {
|
||||
return ids.reduce((previous, current) => (
|
||||
previous.then(() => this.addFavoriteById(nodeType, current))
|
||||
), Promise.resolve());
|
||||
async getFavorites() {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.favoritesApi.getFavorites(this.getUsername());
|
||||
}
|
||||
|
||||
getFavorites(): Promise<any> {
|
||||
return this
|
||||
.get('/people/-me-/favorites')
|
||||
.catch(this.handleError);
|
||||
async getFavoriteById(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.favoritesApi.getFavorite('-me', nodeId);
|
||||
}
|
||||
|
||||
getFavoriteById(nodeId: string): Promise<any> {
|
||||
return this
|
||||
.get(`/people/-me-/favorites/${nodeId}`)
|
||||
.catch(this.handleError);
|
||||
async isFavorite(nodeId: string) {
|
||||
return JSON.stringify((await this.getFavorites()).list.entries).includes(nodeId);
|
||||
}
|
||||
|
||||
isFavorite(nodeId: string) {
|
||||
return this.getFavorites()
|
||||
.then(resp => JSON.stringify(resp.data.list.entries).includes(nodeId));
|
||||
async removeFavoriteById(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.peopleApi.removeFavoriteSite('-me-', nodeId);
|
||||
}
|
||||
|
||||
removeFavorite(api: RepoClient, nodeType: string, name: string): Promise<any> {
|
||||
return api.nodes.getNodeByPath(name)
|
||||
.then((response) => {
|
||||
const { id } = response.data.entry;
|
||||
return this.delete(`/people/-me-/favorites/${id}`);
|
||||
})
|
||||
.catch(this.handleError);
|
||||
async removeFavorite(api: RepoClient, name: string) {
|
||||
const nodeId = (await api.nodes.getNodeByPath(name)).entry.id;
|
||||
return await this.removeFavoriteById(nodeId);
|
||||
}
|
||||
|
||||
removeFavoriteById(nodeId: string) {
|
||||
return this
|
||||
.delete(`/people/-me-/favorites/${nodeId}`)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
waitForApi(data) {
|
||||
const favoriteFiles = () => {
|
||||
return this.getFavorites()
|
||||
.then(response => response.data.list.pagination.totalItems)
|
||||
.then(totalItems => {
|
||||
async waitForApi(data) {
|
||||
const favoriteFiles = async () => {
|
||||
const totalItems = (await this.getFavorites()).list.pagination.totalItems;
|
||||
if ( totalItems < data.expect) {
|
||||
return Promise.reject(totalItems);
|
||||
} else {
|
||||
return Promise.resolve(totalItems);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return Utils.retryCall(favoriteFiles);
|
||||
return await Utils.retryCall(favoriteFiles);
|
||||
}
|
||||
}
|
||||
|
@ -23,127 +23,125 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { NodeBodyLock } from 'alfresco-js-api-node';
|
||||
import { RepoApi } from '../repo-api';
|
||||
import { NodeBodyCreate, NODE_TYPE_FILE, NODE_TYPE_FOLDER } from './node-body-create';
|
||||
import { NodeBodyCreate } from './node-body-create';
|
||||
import { NodeContentTree, flattenNodeContentTree } from './node-content-tree';
|
||||
|
||||
export class NodesApi extends RepoApi {
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
// nodes
|
||||
getNodeByPath(relativePath: string = '/'): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/-my-`, { parameters: { relativePath } })
|
||||
.catch(this.handleError);
|
||||
|
||||
async getNodeByPath(relativePath: string = '/') {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.getNode('-my-', { relativePath });
|
||||
}
|
||||
|
||||
getNodeById(id: string): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/${id}`)
|
||||
.catch(this.handleError);
|
||||
async getNodeById(id: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.getNode(id);
|
||||
}
|
||||
|
||||
getNodeDescription(name: string, relativePath: string = '/') {
|
||||
async getNodeDescription(name: string, relativePath: string = '/') {
|
||||
relativePath = (relativePath === '/')
|
||||
? `${name}`
|
||||
: `${relativePath}/${name}`;
|
||||
|
||||
return this.getNodeByPath(`${relativePath}`)
|
||||
.then(response => response.data.entry.properties['cm:description']);
|
||||
return (await this.getNodeByPath(`${relativePath}`)).entry.properties['cm:description'];
|
||||
}
|
||||
|
||||
deleteNodeById(id: string, permanent: boolean = true): Promise<any> {
|
||||
return this
|
||||
.delete(`/nodes/${id}?permanent=${permanent}`)
|
||||
.catch(this.handleError);
|
||||
async deleteNodeById(id: string, permanent: boolean = true) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.deleteNode(id, { permanent });
|
||||
}
|
||||
|
||||
deleteNodeByPath(path: string, permanent: boolean = true): Promise<any> {
|
||||
return this
|
||||
.getNodeByPath(path)
|
||||
.then((response: any): string => response.data.entry.id)
|
||||
.then((id: string): any => this.deleteNodeById(id, permanent))
|
||||
.catch(this.handleError);
|
||||
async deleteNodeByPath(path: string, permanent: boolean = true) {
|
||||
const id = (await this.getNodeByPath(path)).entry.id;
|
||||
return await this.deleteNodeById(id, permanent);
|
||||
}
|
||||
|
||||
deleteNodes(names: string[], relativePath: string = '', permanent: boolean = true): Promise<any[]> {
|
||||
return names.reduce((previous, current) => (
|
||||
previous.then(() => this.deleteNodeByPath(`${relativePath}/${current}`, permanent))
|
||||
), Promise.resolve());
|
||||
async deleteNodes(names: string[], relativePath: string = '', permanent: boolean = true) {
|
||||
return await names.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
return await this.deleteNodeByPath(`${relativePath}/${current}`, permanent);
|
||||
}, Promise.resolve());
|
||||
}
|
||||
|
||||
deleteNodesById(ids: string[], permanent: boolean = true): Promise<any[]> {
|
||||
return ids.reduce((previous, current) => (
|
||||
previous.then(() => this.deleteNodeById(current, permanent))
|
||||
), Promise.resolve());
|
||||
async deleteNodesById(ids: string[], permanent: boolean = true) {
|
||||
return await ids.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
return await this.deleteNodeById(current, permanent);
|
||||
}, Promise.resolve());
|
||||
}
|
||||
|
||||
// children
|
||||
getNodeChildren(nodeId: string): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/${nodeId}/children`)
|
||||
.catch(this.handleError);
|
||||
|
||||
async getNodeChildren(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.getNodeChildren(nodeId);
|
||||
}
|
||||
|
||||
createNode(nodeType: string, name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<any> {
|
||||
const data = {
|
||||
name: name,
|
||||
nodeType: nodeType,
|
||||
async createNode(nodeType: string, name: string, parentId: string = '-my-', title: string = '', description: string = '') {
|
||||
const nodeBody = {
|
||||
name,
|
||||
nodeType,
|
||||
properties: {
|
||||
'cm:title': title, 'cm:description': description
|
||||
'cm:title': title,
|
||||
'cm:description': description
|
||||
}
|
||||
};
|
||||
|
||||
return this
|
||||
.post(`/nodes/${parentId}/children`, { data })
|
||||
.catch(this.handleError);
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.addNode(parentId, nodeBody);
|
||||
}
|
||||
|
||||
createFile(name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<any> {
|
||||
return this.createNode('cm:content', name, parentId, title, description);
|
||||
async createFile(name: string, parentId: string = '-my-', title: string = '', description: string = '') {
|
||||
return await this.createNode('cm:content', name, parentId, title, description);
|
||||
}
|
||||
|
||||
createFolder(name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<any> {
|
||||
return this.createNode('cm:folder', name, parentId, title, description);
|
||||
async createFolder(name: string, parentId: string = '-my-', title: string = '', description: string = '') {
|
||||
return await this.createNode('cm:folder', name, parentId, title, description);
|
||||
}
|
||||
|
||||
createChildren(data: NodeBodyCreate[]): Promise<any> {
|
||||
return this
|
||||
.post(`/nodes/-my-/children`, { data })
|
||||
.catch(this.handleError);
|
||||
async createChildren(data: NodeBodyCreate[]) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.addNode('-my-', data);
|
||||
}
|
||||
|
||||
createContent(content: NodeContentTree, relativePath: string = '/'): Promise<any> {
|
||||
return this.createChildren(flattenNodeContentTree(content, relativePath));
|
||||
async createContent(content: NodeContentTree, relativePath: string = '/') {
|
||||
return await this.createChildren(flattenNodeContentTree(content, relativePath));
|
||||
}
|
||||
|
||||
createFolders(names: string[], relativePath: string = '/'): Promise<any> {
|
||||
return this.createContent({ folders: names }, relativePath);
|
||||
async createFolders(names: string[], relativePath: string = '/') {
|
||||
return await this.createContent({ folders: names }, relativePath);
|
||||
}
|
||||
|
||||
createFiles(names: string[], relativePath: string = '/'): Promise<any> {
|
||||
return this.createContent({ files: names }, relativePath);
|
||||
async createFiles(names: string[], relativePath: string = '/') {
|
||||
return await this.createContent({ files: names }, relativePath);
|
||||
}
|
||||
|
||||
// node content
|
||||
getNodeContent(nodeId: string): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/${nodeId}/content`)
|
||||
.catch(this.handleError);
|
||||
async getNodeContent(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.getNodeContent(nodeId);
|
||||
}
|
||||
|
||||
editNodeContent(nodeId: string, content: string): Promise<any> {
|
||||
return this
|
||||
.put(`/nodes/${nodeId}/content`, { data: content })
|
||||
.catch(this.handleError);
|
||||
async editNodeContent(nodeId: string, content: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.updateNodeContent(nodeId, content);
|
||||
}
|
||||
|
||||
renameNode(nodeId: string, newName: string): Promise<any> {
|
||||
return this
|
||||
.put(`/nodes/${nodeId}`, { data: { name: newName } })
|
||||
.catch(this.handleError);
|
||||
async renameNode(nodeId: string, newName: string) {
|
||||
await this.apiAuth();
|
||||
return this.alfrescoJsApi.core.nodesApi.updateNode(nodeId, { name: newName });
|
||||
}
|
||||
|
||||
// node permissions
|
||||
setGranularPermission(nodeId: string, inheritPermissions: boolean = false, username: string, role: string): Promise<any> {
|
||||
async setGranularPermission(nodeId: string, inheritPermissions: boolean = false, username: string, role: string) {
|
||||
const data = {
|
||||
permissions: {
|
||||
isInheritanceEnabled: inheritPermissions,
|
||||
@ -156,27 +154,26 @@ export class NodesApi extends RepoApi {
|
||||
}
|
||||
};
|
||||
|
||||
return this
|
||||
.put(`/nodes/${nodeId}`, { data })
|
||||
.catch(this.handleError);
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.updateNode(nodeId, data);
|
||||
}
|
||||
|
||||
getNodePermissions(nodeId: string): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/${nodeId}?include=permissions`)
|
||||
.catch(this.handleError);
|
||||
async getNodePermissions(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.getNode(nodeId, { include: ['permissions'] });
|
||||
}
|
||||
|
||||
// lock node
|
||||
lockFile(nodeId: string, lockType: string = 'FULL') {
|
||||
return this
|
||||
.post(`/nodes/${nodeId}/lock?include=isLocked`, { data: { 'type': lockType } })
|
||||
.catch(this.handleError);
|
||||
async lockFile(nodeId: string, lockType: string = 'FULL') {
|
||||
const data = <NodeBodyLock>{
|
||||
type: lockType
|
||||
};
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.lockNode(nodeId, data );
|
||||
}
|
||||
|
||||
unlockFile(nodeId: string) {
|
||||
return this
|
||||
.post(`/nodes/${nodeId}/unlock`)
|
||||
.catch(this.handleError);
|
||||
async unlockFile(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.unlockNode(nodeId);
|
||||
}
|
||||
}
|
||||
|
@ -24,9 +24,9 @@
|
||||
*/
|
||||
|
||||
import { PersonModel, Person } from './people-api-models';
|
||||
import { RepoApiNew } from '../repo-api-new';
|
||||
import { RepoApi } from '../repo-api';
|
||||
|
||||
export class PeopleApi extends RepoApiNew {
|
||||
export class PeopleApi extends RepoApi {
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
|
@ -1,46 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import * as AlfrescoApi from 'alfresco-js-api-node';
|
||||
import { REPO_API_HOST } from '../../../configs';
|
||||
import { RepoClientAuth } from '../repo-client-models';
|
||||
|
||||
export abstract class RepoApiNew {
|
||||
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
provider: 'ECM',
|
||||
hostEcm: REPO_API_HOST
|
||||
});
|
||||
|
||||
constructor(
|
||||
private username: string = RepoClientAuth.DEFAULT_USERNAME,
|
||||
private password: string = RepoClientAuth.DEFAULT_PASSWORD
|
||||
) {}
|
||||
|
||||
apiAuth() {
|
||||
return this.alfrescoJsApi.login(this.username, this.password);
|
||||
}
|
||||
|
||||
}
|
51
e2e/utilities/repo-client/apis/repo-api.ts
Executable file → Normal file
51
e2e/utilities/repo-client/apis/repo-api.ts
Executable file → Normal file
@ -23,49 +23,28 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { RestClient, RestClientArgs, RestClientResponse } from '../../rest-client/rest-client';
|
||||
import { RepoClientAuth, RepoClientConfig } from '../repo-client-models';
|
||||
import * as AlfrescoApi from 'alfresco-js-api-node';
|
||||
import { REPO_API_HOST } from '../../../configs';
|
||||
import { RepoClientAuth } from '../repo-client-models';
|
||||
|
||||
export abstract class RepoApi {
|
||||
private client: RestClient;
|
||||
private defaults: RepoClientConfig = new RepoClientConfig();
|
||||
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
provider: 'ECM',
|
||||
hostEcm: REPO_API_HOST
|
||||
});
|
||||
|
||||
constructor(
|
||||
auth: RepoClientAuth = new RepoClientAuth(),
|
||||
private config?: RepoClientConfig
|
||||
) {
|
||||
const { username, password } = auth;
|
||||
private username: string = RepoClientAuth.DEFAULT_USERNAME,
|
||||
private password: string = RepoClientAuth.DEFAULT_PASSWORD
|
||||
) {}
|
||||
|
||||
this.client = new RestClient(username, password);
|
||||
apiAuth() {
|
||||
return this.alfrescoJsApi.login(this.username, this.password);
|
||||
}
|
||||
|
||||
private createEndpointUri(endpoint: string, apiDefinition: string = 'alfresco'): string {
|
||||
const { defaults, config } = this;
|
||||
const { host, tenant } = Object.assign(defaults, config);
|
||||
|
||||
return `${host}/alfresco/api/${tenant}/public/${apiDefinition}/versions/1${endpoint}`;
|
||||
getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
protected handleError(response: RestClientResponse) {
|
||||
const { request: { method, path, data }, data: error } = response;
|
||||
|
||||
console.log(`ERROR on ${method}\n${path}\n${data}`);
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
protected get(endpoint: string, args: RestClientArgs = {}, apiDefinition: string = 'alfresco') {
|
||||
return this.client.get(this.createEndpointUri(endpoint, apiDefinition), args);
|
||||
}
|
||||
|
||||
protected post(endpoint: string, args: RestClientArgs = {}, apiDefinition: string = 'alfresco') {
|
||||
return this.client.post(this.createEndpointUri(endpoint, apiDefinition), args);
|
||||
}
|
||||
|
||||
protected put(endpoint: string, args: RestClientArgs = {}, apiDefinition: string = 'alfresco') {
|
||||
return this.client.put(this.createEndpointUri(endpoint, apiDefinition), args);
|
||||
}
|
||||
|
||||
protected delete(endpoint: string, args: RestClientArgs = {}, apiDefinition: string = 'alfresco') {
|
||||
return this.client.delete(this.createEndpointUri(endpoint, apiDefinition), args);
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,10 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { RepoApiNew } from '../repo-api-new';
|
||||
import { RepoApi } from '../repo-api';
|
||||
import { Utils } from '../../../../utilities/utils';
|
||||
|
||||
export class SearchApi extends RepoApiNew {
|
||||
export class SearchApi extends RepoApi {
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
|
@ -23,10 +23,10 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { RepoApiNew } from '../repo-api-new';
|
||||
import { RepoApi } from '../repo-api';
|
||||
import { Utils } from '../../../../utilities/utils';
|
||||
|
||||
export class SharedLinksApi extends RepoApiNew {
|
||||
export class SharedLinksApi extends RepoApi {
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
|
@ -23,11 +23,11 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { RepoApiNew } from '../repo-api-new';
|
||||
import { RepoApi } from '../repo-api';
|
||||
import { SiteBody, SiteMemberRoleBody, SiteMemberBody } from 'alfresco-js-api-node';
|
||||
import { SITE_VISIBILITY } from '../../../../configs';
|
||||
|
||||
export class SitesApi extends RepoApiNew {
|
||||
export class SitesApi extends RepoApi {
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
|
@ -23,10 +23,10 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { RepoApiNew } from '../repo-api-new';
|
||||
import { RepoApi } from '../repo-api';
|
||||
import { Utils } from '../../../../utilities/utils';
|
||||
|
||||
export class TrashcanApi extends RepoApiNew {
|
||||
export class TrashcanApi extends RepoApi {
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
|
@ -25,9 +25,7 @@
|
||||
|
||||
import {
|
||||
ADMIN_USERNAME,
|
||||
ADMIN_PASSWORD,
|
||||
REPO_API_HOST,
|
||||
REPO_API_TENANT
|
||||
ADMIN_PASSWORD
|
||||
} from '../../configs';
|
||||
|
||||
export class RepoClientAuth {
|
||||
@ -39,8 +37,3 @@ export class RepoClientAuth {
|
||||
public password: string = RepoClientAuth.DEFAULT_PASSWORD
|
||||
) {}
|
||||
}
|
||||
|
||||
export class RepoClientConfig {
|
||||
host?: string = REPO_API_HOST;
|
||||
tenant?: string = REPO_API_TENANT;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { RepoClientAuth, RepoClientConfig } from './repo-client-models';
|
||||
import { RepoClientAuth } from './repo-client-models';
|
||||
|
||||
import { PeopleApi } from './apis/people/people-api';
|
||||
import { NodesApi } from './apis/nodes/nodes-api';
|
||||
@ -36,8 +36,7 @@ import { SearchApi } from './apis/search/search-api';
|
||||
export class RepoClient {
|
||||
constructor(
|
||||
private username: string = RepoClientAuth.DEFAULT_USERNAME,
|
||||
private password: string = RepoClientAuth.DEFAULT_PASSWORD,
|
||||
private config?: RepoClientConfig
|
||||
private password: string = RepoClientAuth.DEFAULT_PASSWORD
|
||||
) {}
|
||||
|
||||
private get auth(): RepoClientAuth {
|
||||
@ -50,7 +49,7 @@ export class RepoClient {
|
||||
}
|
||||
|
||||
get nodes() {
|
||||
return new NodesApi(this.auth, this.config);
|
||||
return new NodesApi(this.auth.username, this.auth.password);
|
||||
}
|
||||
|
||||
get sites() {
|
||||
@ -58,7 +57,7 @@ export class RepoClient {
|
||||
}
|
||||
|
||||
get favorites() {
|
||||
return new FavoritesApi(this.auth, this.config);
|
||||
return new FavoritesApi(this.auth.username, this.auth.password);
|
||||
}
|
||||
|
||||
get shared() {
|
||||
|
@ -1,63 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
interface RequestConfig {
|
||||
timeout?: number;
|
||||
noDelay?: boolean;
|
||||
keepAlive?: boolean;
|
||||
keepAliveDelay?: number;
|
||||
}
|
||||
|
||||
interface ResponseConfig {
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
interface ResponseRequest {
|
||||
method: string;
|
||||
path: string;
|
||||
data: string;
|
||||
}
|
||||
|
||||
export interface NodeRestClient {
|
||||
get(uri: string, callback: Function): Function;
|
||||
post(uri: string, callback: Function): Function;
|
||||
put(uri: string, callback: Function): Function;
|
||||
delete(uri: string, callback: Function): Function;
|
||||
}
|
||||
|
||||
export interface RestClientArgs {
|
||||
data?: any;
|
||||
parameters?: any;
|
||||
headers?: any;
|
||||
requestConfig?: RequestConfig;
|
||||
responseConfig?: ResponseConfig;
|
||||
}
|
||||
|
||||
export interface RestClientResponse {
|
||||
request: ResponseRequest;
|
||||
data: any;
|
||||
statusMessage: string;
|
||||
statusCode: number;
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Client } from 'node-rest-client';
|
||||
import { NodeRestClient, RestClientArgs, RestClientResponse } from './rest-client-models';
|
||||
|
||||
export * from './rest-client-models';
|
||||
|
||||
export class RestClient {
|
||||
private static DEFAULT_HEADERS = {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
};
|
||||
|
||||
private client: NodeRestClient;
|
||||
|
||||
constructor(user: string, password: string) {
|
||||
this.client = <NodeRestClient>(new Client({ user, password }));
|
||||
}
|
||||
|
||||
get(uri: string, args: RestClientArgs = {}): Promise<RestClientResponse> {
|
||||
return this.promisify('get', uri, args);
|
||||
}
|
||||
|
||||
post(uri: string, args: RestClientArgs = {}): Promise<RestClientResponse> {
|
||||
return this.promisify('post', uri, args);
|
||||
}
|
||||
|
||||
put(uri: string, args: RestClientArgs = {}): Promise<RestClientResponse> {
|
||||
return this.promisify('put', uri, args);
|
||||
}
|
||||
|
||||
delete(uri: string, args: RestClientArgs = {}): Promise<RestClientResponse> {
|
||||
return this.promisify('delete', uri, args);
|
||||
}
|
||||
|
||||
private createArgs(args: RestClientArgs = {}): RestClientArgs {
|
||||
const data = JSON.stringify(args.data);
|
||||
|
||||
return Object.assign({}, RestClient.DEFAULT_HEADERS, args, { data });
|
||||
}
|
||||
|
||||
private promisify(fnName: string, uri: string, args: RestClientArgs): Promise<RestClientResponse> {
|
||||
const fn: Function = this.client[fnName];
|
||||
const fnArgs = [ encodeURI(uri), this.createArgs(args) ];
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const fnCallback = (data, rawResponse) => {
|
||||
const {
|
||||
statusCode, statusMessage,
|
||||
req: { method, path }
|
||||
} = rawResponse;
|
||||
|
||||
const response: RestClientResponse = {
|
||||
data, statusCode, statusMessage,
|
||||
request: { method, path, data: args.data }
|
||||
};
|
||||
|
||||
(response.statusCode >= 400)
|
||||
? reject(response)
|
||||
: resolve(response);
|
||||
};
|
||||
|
||||
fn(...fnArgs, fnCallback);
|
||||
});
|
||||
}
|
||||
}
|
6052
package-lock.json
generated
6052
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -81,7 +81,6 @@
|
||||
"karma-coverage-istanbul-reporter": "^1.2.1",
|
||||
"karma-jasmine": "~1.1.0",
|
||||
"karma-jasmine-html-reporter": "^0.2.2",
|
||||
"node-rest-client": "^3.1.0",
|
||||
"protractor": "5.3.2",
|
||||
"rimraf": "2.6.2",
|
||||
"selenium-webdriver": "4.0.0-alpha.1",
|
||||
|
Loading…
x
Reference in New Issue
Block a user