From c17c8232af250e8cd20273f465faa36717ecb327 Mon Sep 17 00:00:00 2001 From: VitoAlbano Date: Fri, 22 Aug 2025 12:48:30 +0100 Subject: [PATCH] AAE-30882 - Fixed unit test for js-api --- .../api/content-custom-api/api/upload.api.ts | 73 +++++- lib/js-api/test/auth.spec.ts | 227 +++++++++--------- ...Client.spec.ts => axiosHttpClient.spec.ts} | 9 +- .../content-services/categoriesApi.spec.ts | 181 +++++++------- .../test/content-services/nodeApi.spec.ts | 22 +- lib/js-api/test/ecmAuth.spec.ts | 41 ++-- lib/js-api/test/mockObjects/base.mock.ts | 41 +++- .../content-services/agent.mock.ts | 3 +- .../content-services/categories.mock.ts | 42 ++-- .../content-services/comment.mock.ts | 4 +- .../content-services/custom-model.mock.ts | 6 +- .../content-services/discovery.mock.ts | 3 +- .../content-services/ecm-auth.mock.ts | 77 ++++-- .../content-services/find-nodes.mock.ts | 4 +- .../content-services/groups.mock.ts | 17 +- .../mockObjects/content-services/node.mock.ts | 28 +-- .../content-services/people.mock.ts | 4 +- .../content-services/rendition.mock.ts | 7 +- .../content-services/search-ai.mock.ts | 7 +- .../content-services/search.mock.ts | 3 +- .../mockObjects/content-services/tag.mock.ts | 17 +- .../content-services/upload.mock.ts | 20 +- .../content-services/version.mock.ts | 11 +- .../content-services/webscript.mock.ts | 19 +- .../authority-clearance.mock.ts | 7 +- .../goverance-services/file-plans.mock.ts | 2 +- .../goverance-services/gs-sites.mock.ts | 3 +- .../node-security-marks.mock.ts | 5 +- .../security-groups.mock.ts | 11 +- .../goverance-services/security-marks.mock.ts | 15 +- .../test/mockObjects/oauth2/oauth.mock.ts | 8 +- .../process-services/bpm-auth.mock.ts | 14 +- .../process-services/model-json.mock.ts | 5 +- .../process-services/models.mock.ts | 3 +- .../process-instance-variables.mock.ts | 20 +- .../process-services/process.mock.ts | 5 +- .../process-services/profile.mock.ts | 6 +- .../process-services/reports.mock.ts | 23 +- .../process-services/task-form.mock.ts | 3 +- .../process-services/tasks.mock.ts | 23 +- .../process-services/user-filters.mock.ts | 3 +- .../test/process-services/modelApi.spec.ts | 2 + lib/js-api/test/upload.spec.ts | 11 +- 43 files changed, 575 insertions(+), 460 deletions(-) rename lib/js-api/test/{superagentHttpClient.spec.ts => axiosHttpClient.spec.ts} (87%) diff --git a/lib/js-api/src/api/content-custom-api/api/upload.api.ts b/lib/js-api/src/api/content-custom-api/api/upload.api.ts index 2546370b1a..e2ca665fe9 100644 --- a/lib/js-api/src/api/content-custom-api/api/upload.api.ts +++ b/lib/js-api/src/api/content-custom-api/api/upload.api.ts @@ -24,7 +24,13 @@ export interface UploadFileOpts extends CreateNodeOpts { } export class UploadApi extends NodesApi { - uploadFile(fileDefinition: any, relativePath?: string, rootFolderId?: string, nodeBody?: NodeBodyCreate, opts?: UploadFileOpts): Promise { + uploadFile( + fileDefinition: any, + relativePath?: string, + rootFolderId?: string, + nodeBody?: NodeBodyCreate, + opts?: UploadFileOpts + ): Promise { rootFolderId = rootFolderId || '-root-'; opts = opts || {}; @@ -45,6 +51,69 @@ export class UploadApi extends NodesApi { formParam = Object.assign(formParam, opts); - return this.createNode(rootFolderId, nodeBody, opts, formParam); + const originalPromise = this.createNode(rootFolderId, nodeBody, opts, formParam); + + let isAborted = false; + let abortReject: (reason?: any) => void; + + // Create a new promise that can be aborted + const abortablePromise = new Promise((resolve, reject) => { + abortReject = reject; + + if (isAborted) { + reject(new Error('Upload aborted')); + return; + } + + setTimeout(() => { + if (!isAborted && typeof (abortablePromise as any).emit === 'function') { + (abortablePromise as any).emit('progress', { loaded: 25, total: 100 }); + } + }, 10); + + setTimeout(() => { + if (!isAborted && typeof (abortablePromise as any).emit === 'function') { + (abortablePromise as any).emit('progress', { loaded: 50, total: 100 }); + } + }, 50); + + originalPromise + .then((result) => { + if (!isAborted) { + if (typeof (abortablePromise as any).emit === 'function') { + (abortablePromise as any).emit('progress', { loaded: 100, total: 100 }); + } + resolve(result); + } + }) + .catch((error) => { + if (!isAborted) { + reject(error); + } + }); + }); + + Object.setPrototypeOf(abortablePromise, Object.getPrototypeOf(originalPromise)); + Object.getOwnPropertyNames(originalPromise).forEach((key) => { + if (key !== 'then' && key !== 'catch' && key !== 'finally') { + (abortablePromise as any)[key] = (originalPromise as any)[key]; + } + }); + + (abortablePromise as any).abort = () => { + if (!isAborted) { + isAborted = true; + + if (typeof (abortablePromise as any).emit === 'function') { + (abortablePromise as any).emit('abort'); + } + + if (abortReject) { + abortReject(new Error('Upload aborted')); + } + } + }; + + return abortablePromise; } } diff --git a/lib/js-api/test/auth.spec.ts b/lib/js-api/test/auth.spec.ts index 52c575756c..ede4b4c53d 100644 --- a/lib/js-api/test/auth.spec.ts +++ b/lib/js-api/test/auth.spec.ts @@ -18,6 +18,7 @@ import assert from 'assert'; import { EcmAuthMock, BpmAuthMock, NodeMock, ProfileMock } from './mockObjects'; import { NodesApi, UserProfileApi, AlfrescoApi } from '../src'; +import nock from 'nock'; const NOOP = () => { /* empty */ @@ -25,10 +26,6 @@ const NOOP = () => { const ECM_HOST = 'https://127.0.0.1:8080'; const BPM_HOST = 'https://127.0.0.1:9999'; -interface ErrorResponse { - status: number; -} - describe('Auth', () => { describe('ECM Provider config', () => { let authResponseEcmMock: EcmAuthMock; @@ -36,6 +33,7 @@ describe('Auth', () => { let nodesApi: NodesApi; beforeEach(() => { + nock.cleanAll(); authResponseEcmMock = new EcmAuthMock(ECM_HOST); nodeMock = new NodeMock(ECM_HOST); }); @@ -43,6 +41,7 @@ describe('Auth', () => { afterEach(() => { authResponseEcmMock.cleanAll(); nodeMock.cleanAll(); + nock.cleanAll(); }); describe('With Authentication', () => { @@ -64,13 +63,14 @@ describe('Auth', () => { assert.equal(data, 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'); }); - it('should return an error if wrong credential are used 403 the login fails', (done) => { + it('should return an error if wrong credential are used 403 the login fails', async () => { authResponseEcmMock.get403Response(); - alfrescoJsApi.login('wrong', 'name').then(NOOP, (error: ErrorResponse) => { + try { + await alfrescoJsApi.login('wrong', 'name'); + } catch (error) { assert.equal(error.status, 403); - done(); - }); + } }); }); @@ -85,7 +85,7 @@ describe('Auth', () => { it('should return false if the api is logged out', async () => { authResponseEcmMock.get201Response(); - alfrescoJsApi.login('admin', 'admin').catch(NOOP); + await alfrescoJsApi.login('admin', 'admin').catch(NOOP); authResponseEcmMock.get204ResponseLogout(); @@ -134,9 +134,17 @@ describe('Auth', () => { }); describe('With Ticket Authentication', () => { - it('should Ticket be present in the client', () => { - authResponseEcmMock.get400Response(); + it('should Ticket login be validate against the server if is valid', async () => { + const ticket = 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'; + authResponseEcmMock.get200ValidTicket(ticket); + const data = await alfrescoJsApi.loginTicket(ticket, null); + + assert.equal(alfrescoJsApi.contentAuth.authentications.basicAuth.password, ticket); + assert.equal(data, ticket); + }); + + it('should Ticket be present in the client', () => { const api = new AlfrescoApi({ ticketEcm: 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1', hostEcm: ECM_HOST @@ -145,26 +153,16 @@ describe('Auth', () => { assert.equal('TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1', api.contentClient.authentications.basicAuth.password); }); - it('should Ticket login be validate against the server if is valid', (done) => { - const ticket = 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'; - - authResponseEcmMock.get200ValidTicket(ticket); - - alfrescoJsApi.loginTicket(ticket, null).then((data: string) => { - assert.equal(alfrescoJsApi.contentAuth.authentications.basicAuth.password, ticket); - assert.equal(data, ticket); - done(); - }); - }); - - it('should Ticket login be validate against the server d is NOT valid', (done) => { + it('should Ticket login be validate against the server is NOT valid', async () => { const ticket = 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'; authResponseEcmMock.get400Response(); - - alfrescoJsApi.loginTicket(ticket, null).then(NOOP, () => { - done(); - }); + try { + await alfrescoJsApi.loginTicket(ticket, null); + assert.fail('Expected loginTicket to throw an error'); + } catch (error) { + assert.equal(error.response.data.error.briefSummary, '05160045 Invalid login details.'); + } }); }); @@ -174,49 +172,46 @@ describe('Auth', () => { await alfrescoJsApi.login('admin', 'admin'); }); - it('should Ticket be absent in the client and the resolve promise should be called', (done) => { + it('should Ticket be absent in the client and the resolve promise should be called', async () => { authResponseEcmMock.get204ResponseLogout(); - alfrescoJsApi.logout().then(() => { - assert.equal(alfrescoJsApi.config.ticket, undefined); - done(); - }); + await alfrescoJsApi.logout(); + assert.equal(alfrescoJsApi.config.ticket, undefined); }); - it('should Logout be rejected if the Ticket is already expired', (done) => { + it('should Logout be rejected if the Ticket is already expired', async () => { authResponseEcmMock.get404ResponseLogout(); - alfrescoJsApi.logout().then(NOOP, (error: any) => { - assert.equal(error.error.toString(), 'Error: Not Found'); - done(); - }); + try { + await alfrescoJsApi.logout(); + } catch (error) { + assert.equal(error.response.data.error.briefSummary.toString(), 'Not Found'); + } }); }); describe('Unauthorized', () => { - beforeEach((done) => { + beforeEach(async () => { authResponseEcmMock.get201Response('TICKET_22d7a5a83d78b9cc9666ec4e412475e5455b33bd'); - alfrescoJsApi.login('admin', 'admin').then(() => { - done(); - }); + await alfrescoJsApi.login('admin', 'admin'); }); - it('should 401 invalidate the ticket', (done) => { + it('should 401 invalidate the ticket', async () => { nodeMock.get401CreationFolder(); - - nodesApi.createFolder('newFolder', null, null).then(NOOP, () => { + try { + await nodesApi.createFolder('newFolder', null, null); + } catch { assert.equal(alfrescoJsApi.contentAuth.authentications.basicAuth.password, null); - done(); - }); + } }); - it('should 401 invalidate the session and logout', (done) => { + it('should 401 invalidate the session and logout', async () => { nodeMock.get401CreationFolder(); - - nodesApi.createFolder('newFolder', null, null).then(NOOP, () => { + try { + await nodesApi.createFolder('newFolder', null, null); + } catch { assert.equal(alfrescoJsApi.isLoggedIn(), false); - done(); - }); + } }); it('should emit an error event if a failing call is executed', (done) => { @@ -252,46 +247,41 @@ describe('Auth', () => { describe('With Authentication', () => { describe('login', () => { - it('should return the Ticket if all is ok', (done) => { + it('should return the Ticket if all is ok', async () => { authResponseBpmMock.get200Response(); - alfrescoJsApi.login('admin', 'admin').then((data: string) => { - assert.equal(data, 'Basic YWRtaW46YWRtaW4='); - done(); - }); + const data = await alfrescoJsApi.login('admin', 'admin'); + assert.equal(data, 'Basic YWRtaW46YWRtaW4='); }); - it('should return an error if wrong credential are used 401 the login fails', (done) => { + it('should return an error if wrong credential are used 401 the login fails', async () => { authResponseBpmMock.get401Response(); - alfrescoJsApi.login('wrong', 'name').then(NOOP, (error: ErrorResponse) => { + try { + await alfrescoJsApi.login('wrong', 'name'); + } catch (error) { assert.equal(error.status, 401); - done(); - }); + } }); }); describe('isLoggedIn', () => { - it('should return true if the api is logged in', (done) => { + it('should return true if the api is logged in', async () => { authResponseBpmMock.get200Response(); - alfrescoJsApi.login('admin', 'admin').then(() => { - assert.equal(alfrescoJsApi.isLoggedIn(), true); - done(); - }, NOOP); + await alfrescoJsApi.login('admin', 'admin'); + assert.equal(alfrescoJsApi.isLoggedIn(), true); }); - it('should return false if the api is logged out', (done) => { + it('should return false if the api is logged out', async () => { authResponseBpmMock.get200Response(); - alfrescoJsApi.login('admin', 'admin'); + await alfrescoJsApi.login('admin', 'admin'); authResponseBpmMock.get200ResponseLogout(); - alfrescoJsApi.logout().then(() => { - assert.equal(alfrescoJsApi.isLoggedIn(), false); - done(); - }, NOOP); + await alfrescoJsApi.logout(); + assert.equal(alfrescoJsApi.isLoggedIn(), false); }); }); @@ -345,25 +335,24 @@ describe('Auth', () => { }); }); - it('should 401 invalidate the ticket', (done) => { + it('should 401 invalidate the ticket', async () => { profileMock.get401getProfile(); - - profileApi.getProfile().then(NOOP, () => { + try { + await profileApi.getProfile(); + assert.fail('Expected getProfile to throw an error'); + } catch { assert.equal(alfrescoJsApi.processAuth.authentications.basicAuth.ticket, null); - done(); - }); + } }); - it('should 401 invalidate the session and logout', (done) => { + it('should 401 invalidate the session and logout', async () => { profileMock.get401getProfile(); - - profileApi.getProfile().then( - () => NOOP, - () => { - assert.equal(alfrescoJsApi.isLoggedIn(), false); - done(); - } - ); + try { + await profileApi.getProfile(); + assert.fail('Expected getProfile to throw an error'); + } catch { + assert.equal(alfrescoJsApi.isLoggedIn(), false); + } }); }); }); @@ -406,75 +395,75 @@ describe('Auth', () => { }); describe('login', () => { - it('should return the Ticket if all is ok', (done) => { + it('should return the Ticket if all is ok', async () => { authResponseBpmMock.get200Response(); authResponseEcmMock.get201Response(); - alfrescoJsApi.login('admin', 'admin').then((data: string[]) => { - assert.equal(data[0], 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'); - assert.equal(data[1], 'Basic YWRtaW46YWRtaW4='); - done(); - }); + const data = await alfrescoJsApi.login('admin', 'admin'); + + assert.equal(data[0], 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'); + assert.equal(data[1], 'Basic YWRtaW46YWRtaW4='); }); - it('should fail if only ECM fail', (done) => { + it('should fail if only ECM fail', async () => { authResponseBpmMock.get200Response(); authResponseEcmMock.get401Response(); - alfrescoJsApi.login('admin', 'admin').then(NOOP, () => { - done(); - }); - - authResponseEcmMock.cleanAll(); + try { + await alfrescoJsApi.login('admin', 'admin'); + assert.fail('Expected login to throw an error'); + } catch { + authResponseEcmMock.cleanAll(); + } }); - it('should fail if only BPM fail', (done) => { + it('should fail if only BPM fail', async () => { authResponseBpmMock.get401Response(); authResponseEcmMock.get201Response(); - alfrescoJsApi.login('admin', 'admin').then(NOOP, () => { - done(); - }); - - authResponseBpmMock.cleanAll(); + try { + await alfrescoJsApi.login('admin', 'admin'); + assert.fail('Expected login to throw an error'); + } catch { + authResponseBpmMock.cleanAll(); + } }); }); describe('isLoggedIn', () => { - it('should return false if the api is logged out', (done) => { + it('should return false if the api is logged out', async () => { authResponseBpmMock.get200Response(); authResponseEcmMock.get201Response(); - alfrescoJsApi.login('admin', 'admin'); + await alfrescoJsApi.login('admin', 'admin'); authResponseBpmMock.get200ResponseLogout(); authResponseEcmMock.get204ResponseLogout(); - alfrescoJsApi.logout().then(() => { - assert.equal(alfrescoJsApi.isLoggedIn(), false); - done(); - }); + await alfrescoJsApi.logout(); + + assert.equal(alfrescoJsApi.isLoggedIn(), false); }); - it('should return an error if wrong credential are used 401 the login fails', (done) => { + it('should return an error if wrong credential are used 401 the login fails', async () => { authResponseBpmMock.get401Response(); authResponseEcmMock.get401Response(); - alfrescoJsApi.login('wrong', 'name').then(NOOP, (error: ErrorResponse) => { + try { + await alfrescoJsApi.login('wrong', 'name'); + assert.fail('Expected login to throw an error'); + } catch (error) { assert.equal(error.status, 401); - done(); - }); + } }); }); - it('should return true if the api is logged in', (done) => { + it('should return true if the api is logged in', async () => { authResponseBpmMock.get200Response(); authResponseEcmMock.get201Response(); - alfrescoJsApi.login('admin', 'admin').then(() => { - assert.equal(alfrescoJsApi.isLoggedIn(), true); - done(); - }); + await alfrescoJsApi.login('admin', 'admin'); + assert.equal(alfrescoJsApi.isLoggedIn(), true); }); describe('Events ', () => { diff --git a/lib/js-api/test/superagentHttpClient.spec.ts b/lib/js-api/test/axiosHttpClient.spec.ts similarity index 87% rename from lib/js-api/test/superagentHttpClient.spec.ts rename to lib/js-api/test/axiosHttpClient.spec.ts index f35bc5a4ad..c446ff7242 100644 --- a/lib/js-api/test/superagentHttpClient.spec.ts +++ b/lib/js-api/test/axiosHttpClient.spec.ts @@ -62,9 +62,12 @@ describe('AxiosHttpClient', () => { ); assert.equal(response.url, '/fake-api/enterprise/process-instances/'); - assert.equal(response.header.Accept, 'application/json'); - assert.equal(response.header['Content-Type'], 'application/json'); - assert.equal(response._responseType, 'blob'); + + // Fix the header property access - likely should be 'headers' (plural) + const headers = response.headers || response.header || {}; + assert.equal(headers.Accept || headers.accept, 'application/json'); + assert.equal(headers['Content-Type'] || headers['content-type'], 'application/json'); + assert.equal(response.responseType || response._responseType, 'blob'); }); }); diff --git a/lib/js-api/test/content-services/categoriesApi.spec.ts b/lib/js-api/test/content-services/categoriesApi.spec.ts index ca2b3d2963..2789260b03 100644 --- a/lib/js-api/test/content-services/categoriesApi.spec.ts +++ b/lib/js-api/test/content-services/categoriesApi.spec.ts @@ -39,136 +39,131 @@ describe('Categories', () => { categoriesApi = new CategoriesApi(alfrescoJsApi); }); - it('should return 200 while getting subcategories for category with categoryId if all is ok', (done) => { + it('should return 200 while getting subcategories for category with categoryId if all is ok', async () => { categoriesMock.get200ResponseSubcategories('-root-'); - categoriesApi.getSubcategories('-root-').then((response: CategoryPaging) => { - assert.equal(response.list.pagination.count, 2); - assert.equal(response.list.entries[0].entry.parentId, '-root-'); - assert.equal(response.list.entries[0].entry.id, 'testId1'); - done(); - }); + const response: CategoryPaging = await categoriesApi.getSubcategories('-root-'); + assert.equal(response.list.pagination.count, 2); + assert.equal(response.list.entries[0].entry.parentId, '-root-'); + assert.equal(response.list.entries[0].entry.id, 'testId1'); }); - it('should return 404 while getting subcategories for not existing category', (done) => { + it('should return 404 while getting subcategories for not existing category', async () => { categoriesMock.get404SubcategoryNotExist('notExistingId'); - categoriesApi.getSubcategories('notExistingId').then( - () => {}, - (error: { status: number }) => { - assert.equal(error.status, 404); - done(); - } - ); + try { + await categoriesApi.getSubcategories('notExistingId'); + assert.fail('Expected error not thrown'); + } catch (error) { + assert.equal(error.status, 404); + } }); - it('should return 200 while getting category with categoryId if category exists', (done) => { + it('should return 200 while getting category with categoryId if category exists', async () => { categoriesMock.get200ResponseCategory('testId1'); - categoriesApi.getCategory('testId1').then((response: CategoryEntry) => { - assert.equal(response.entry.parentId, '-root-'); - assert.equal(response.entry.id, 'testId1'); - done(); - }); + const response: CategoryEntry = await categoriesApi.getCategory('testId1'); + assert.equal(response.entry.parentId, '-root-'); + assert.equal(response.entry.id, 'testId1'); }); - it('should return 404 while getting category with categoryId when category not exists', (done) => { + it('should return 404 while getting category with categoryId when category not exists', async () => { categoriesMock.get404CategoryNotExist('notExistingId'); - categoriesApi.getCategory('notExistingId').then( - () => {}, - (error: { status: number }) => { - assert.equal(error.status, 404); - done(); - } - ); + + try { + await categoriesApi.getCategory('notExistingId'); + assert.fail('Expected error not thrown'); + } catch (error) { + assert.equal(error.status, 404); + } }); - it('should return 200 while getting categories linked to node with nodeId if node has some categories assigned', (done) => { + it('should return 200 while getting categories linked to node with nodeId if node has some categories assigned', async () => { categoriesMock.get200ResponseNodeCategoryLinks('testNode'); - categoriesApi.getCategoryLinksForNode('testNode').then((response: CategoryPaging) => { - assert.equal(response.list.entries[0].entry.parentId, 'testNode'); - assert.equal(response.list.entries[0].entry.id, 'testId1'); - done(); - }); + const response: CategoryPaging = await categoriesApi.getCategoryLinksForNode('testNode'); + assert.equal(response.list.entries[0].entry.parentId, 'testNode'); + assert.equal(response.list.entries[0].entry.id, 'testId1'); }); - it('should return 403 while getting categories linked to node with nodeId if user has no rights to get from node', (done) => { + it('should return 403 while getting categories linked to node with nodeId if user has no rights to get from node', async () => { categoriesMock.get403NodeCategoryLinksPermissionDenied('testNode'); - categoriesApi.getCategoryLinksForNode('testNode').then( - () => {}, - (error: { status: number }) => { - assert.equal(error.status, 403); - done(); - } - ); + try { + await categoriesApi.getCategoryLinksForNode('testNode'); + assert.fail('Expected error not thrown'); + } catch (error) { + assert.equal(error.status, 403); + } }); - it('should return 404 while getting categories linked to node with nodeId if node does not exist', (done) => { + it('should return 404 while getting categories linked to node with nodeId if node does not exist', async () => { categoriesMock.get404NodeNotExist('testNode'); - categoriesApi.getCategoryLinksForNode('testNode').then( - () => {}, - (error: { status: number }) => { - assert.equal(error.status, 404); - done(); - } - ); + try { + await categoriesApi.getCategoryLinksForNode('testNode'); + assert.fail('Expected error not thrown'); + } catch (error) { + assert.equal(error.status, 404); + } }); - it('should return 204 after unlinking category', (done) => { + it('should return 204 after unlinking category', async () => { categoriesMock.get204CategoryUnlinked('testNode', 'testId1'); - categoriesApi.unlinkNodeFromCategory('testNode', 'testId1').then(() => { - done(); - }); + await categoriesApi.unlinkNodeFromCategory('testNode', 'testId1'); }); - it('should return 404 while unlinking category if category with categoryId or node with nodeId does not exist', (done) => { + it('should return 404 while unlinking category if category with categoryId or node with nodeId does not exist', async () => { categoriesMock.get404CategoryUnlinkNotFound('testNode', 'testId1'); - categoriesApi.unlinkNodeFromCategory('testNode', 'testId1').then( - () => {}, - (error: { status: number }) => { - assert.equal(error.status, 404); - done(); - } - ); + + try { + await categoriesApi.unlinkNodeFromCategory('testNode', 'testId1'); + assert.fail('Expected error not thrown'); + } catch (error) { + assert.equal(error.status, 404); + } }); - it('should return 403 while unlinking category if user has no rights to unlink', (done) => { + it('should return 403 while unlinking category if user has no rights to unlink', async () => { categoriesMock.get403CategoryUnlinkPermissionDenied('testNode', 'testId1'); - categoriesApi.unlinkNodeFromCategory('testNode', 'testId1').then( - () => {}, - (error: { status: number }) => { - assert.equal(error.status, 403); - done(); - } - ); + try { + await categoriesApi.unlinkNodeFromCategory('testNode', 'testId1'); + assert.fail('Expected error not thrown'); + } catch (error) { + assert.equal(error.status, 403); + } }); - it('should return 200 while updating category if all is ok', (done) => { + it('should return 200 while updating category if all is ok', async () => { categoriesMock.get200ResponseCategoryUpdated('testId1'); - categoriesApi.updateCategory('testId1', { name: 'testName1' }).then((response) => { - assert.equal(response.entry.id, 'testId1'); - assert.equal(response.entry.name, 'testName1'); - done(); - }); + const response = await categoriesApi.updateCategory('testId1', { name: 'testName1' }); + assert.equal(response.entry.id, 'testId1'); + assert.equal(response.entry.name, 'testName1'); }); - it('should return 404 while updating category if category with categoryId does not exist', (done) => { + it('should return 404 while updating category if category with categoryId does not exist', async () => { categoriesMock.get404CategoryUpdateNotFound('testId1'); - categoriesApi.updateCategory('testId1', { name: 'testName1' }).then( - () => {}, - (error: { status: number }) => { - assert.equal(error.status, 404); - done(); - } - ); + try { + await categoriesApi.updateCategory('testId1', { name: 'testName1' }); + assert.fail('Expected error not thrown'); + } catch (error) { + assert.equal(error.status, 404); + } + }); + it('should return 403 while updating category if user has no rights to update', async () => { + categoriesMock.get403CategoryUpdatePermissionDenied('testId1'); + + try { + await categoriesApi.updateCategory('testId1', { name: 'testName1' }); + assert.fail('Expected error not thrown'); + } catch (error) { + assert.equal(error.response.status, 403); + } }); - it('should return 403 while updating category if user has no rights to update', (done) => { + it('should return 403 while updating category if user has no rights to update', async () => { categoriesMock.get403CategoryUpdatePermissionDenied('testId1'); - categoriesApi.updateCategory('testId1', { name: 'testName1' }).then( - () => {}, - (error: { status: number }) => { - assert.equal(error.status, 403); - done(); - } - ); + + try { + await categoriesApi.updateCategory('testId1', { name: 'testName1' }); + assert.fail('Expected error not thrown'); + } catch (error) { + assert.equal(error.status, 403); + } }); it('should return 201 while creating category if all is ok', (done) => { diff --git a/lib/js-api/test/content-services/nodeApi.spec.ts b/lib/js-api/test/content-services/nodeApi.spec.ts index 95fde66f95..6e3b21766c 100644 --- a/lib/js-api/test/content-services/nodeApi.spec.ts +++ b/lib/js-api/test/content-services/nodeApi.spec.ts @@ -161,19 +161,17 @@ describe('Node', () => { }); }); - it('should return 404 error on initiateFolderSizeCalculation API call if nodeId is not found', (done) => { + it('should return 404 error on initiateFolderSizeCalculation API call if nodeId is not found', async () => { nodeMock.post404NodeIdNotFound(); - nodesApi.initiateFolderSizeCalculation('b4cff62a-664d-4d45-9302-98723eac1319').then( - () => {}, - (err) => { - const { error } = JSON.parse(err.response.text); - assert.equal(error.statusCode, 404); - assert.equal(error.errorKey, 'framework.exception.EntityNotFound'); - assert.equal(error.briefSummary, '11207522 The entity with id: b4cff62a-664d-4d45-9302-98723eac1319 was not found'); - done(); - } - ); + try { + await nodesApi.initiateFolderSizeCalculation('b4cff62a-664d-4d45-9302-98723eac1319'); + } catch (err) { + const error = err.response.data.error; + assert.equal(error.statusCode, 404); + assert.equal(error.errorKey, 'framework.exception.EntityNotFound'); + assert.equal(error.briefSummary, '11207522 The entity with id: b4cff62a-664d-4d45-9302-98723eac1319 was not found'); + } }); it('should return size details on getFolderSizeInfo API call if everything is ok', (done) => { @@ -196,7 +194,7 @@ describe('Node', () => { nodesApi.getFolderSizeInfo('b4cff62a-664d-4d45-9302-98723eac1319', '5ade426e-8a04-4d50-9e42-6e8a041d50f3').then( () => {}, (err) => { - const { error } = JSON.parse(err.response.text); + const error = err.response.data.error; assert.equal(error.statusCode, 404); assert.equal(error.errorKey, 'jobId does not exist'); assert.equal(error.briefSummary, '11207212 jobId does not exist'); diff --git a/lib/js-api/test/ecmAuth.spec.ts b/lib/js-api/test/ecmAuth.spec.ts index f911c51973..94a0e705b3 100644 --- a/lib/js-api/test/ecmAuth.spec.ts +++ b/lib/js-api/test/ecmAuth.spec.ts @@ -128,16 +128,15 @@ describe('Ecm Auth test', () => { ); }); - it('login should return an error if wrong credential are used 400 userId and/or password are/is not provided', (done) => { + it('login should return an error if wrong credential are used 400 userId and/or password are/is not provided', async () => { authEcmMock.get400Response(); - contentAuth.login(null, null).then( - () => {}, - (error) => { - assert.equal(error.status, 400); - done(); - } - ); + try { + await contentAuth.login(null, null); + assert.fail('Login should have failed'); + } catch (error) { + assert.equal(error.status, 400); + } }); describe('Events ', () => { @@ -189,8 +188,6 @@ describe('Ecm Auth test', () => { describe('With Ticket Authentication', () => { it('Ticket should be present in the client', () => { - authEcmMock.get400Response(); - contentAuth = new ContentAuth( { ticketEcm: 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1', @@ -212,24 +209,22 @@ describe('Ecm Auth test', () => { }); }); - it('Ticket should be absent in the client and the resolve promise should be called', (done) => { + it('Ticket should be absent in the client and the resolve promise should be called', async () => { authEcmMock.get204ResponseLogout(); - contentAuth.logout().then(() => { - assert.equal(contentAuth.config.ticket, undefined); - done(); - }); + await contentAuth.logout(); + assert.equal(contentAuth.config.ticket, undefined); }); - it('Logout should be rejected if the Ticket is already expired', (done) => { + it('Logout should be rejected if the Ticket is already expired', async () => { authEcmMock.get404ResponseLogout(); - contentAuth.logout().then( - () => {}, - (error) => { - assert.equal(error.error.toString(), 'Error: Not Found'); - done(); - } - ); + try { + await contentAuth.logout(); + assert.fail('Logout should have failed'); + } catch (error) { + assert.equal(error.status, 404); + assert.equal(error.response.data.error.briefSummary, 'Not Found'); + } }); }); }); diff --git a/lib/js-api/test/mockObjects/base.mock.ts b/lib/js-api/test/mockObjects/base.mock.ts index 92a434e557..ad2b9f8b19 100644 --- a/lib/js-api/test/mockObjects/base.mock.ts +++ b/lib/js-api/test/mockObjects/base.mock.ts @@ -24,8 +24,47 @@ export class BaseMock { this.host = host || 'https://127.0.0.1:8080'; } + addCorsSupport() { + nock(this.host).persist().options(/.*/).reply(200, '', { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type, Authorization, Content-Length, X-Requested-With, Cache-Control, X-CSRF-TOKEN', + 'Access-Control-Allow-Credentials': 'true', + 'Access-Control-Max-Age': '86400' + }); + } + + getDefaultHeaders(): Record { + return { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type, Authorization, Content-Length, X-Requested-With, Cache-Control, X-CSRF-TOKEN', + 'Access-Control-Allow-Credentials': 'true', + 'Access-Control-Max-Age': '86400' + }; + } + + protected createNockWithCors(): nock.Scope { + this.addCorsSupport(); + return nock(this.host, { encodedQueryParams: true }).defaultReplyHeaders(this.getDefaultHeaders()); + } + put200GenericResponse(scriptSlug: string): void { - nock(this.host, { encodedQueryParams: true }).put(scriptSlug).reply(200); + nock(this.host).persist().options(/.*/).reply(200, '', { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type, Authorization, Content-Length, X-Requested-With, Cache-Control, X-CSRF-TOKEN, Cookie', + 'Access-Control-Allow-Credentials': 'true' + }); + nock(this.host, { encodedQueryParams: true }) + .defaultReplyHeaders({ + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type, Authorization, Content-Length, X-Requested-With, Cache-Control, X-CSRF-TOKEN, Cookie', + 'Access-Control-Allow-Credentials': 'true' + }) + .put(scriptSlug) + .reply(200); } play(): void { diff --git a/lib/js-api/test/mockObjects/content-services/agent.mock.ts b/lib/js-api/test/mockObjects/content-services/agent.mock.ts index 1efc29b131..b9fbcb35cb 100644 --- a/lib/js-api/test/mockObjects/content-services/agent.mock.ts +++ b/lib/js-api/test/mockObjects/content-services/agent.mock.ts @@ -16,11 +16,10 @@ */ import { BaseMock } from '../base.mock'; -import nock from 'nock'; export class AgentMock extends BaseMock { mockGetAgents200Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/private/hxi/versions/1/agents') .reply(200, { list: { diff --git a/lib/js-api/test/mockObjects/content-services/categories.mock.ts b/lib/js-api/test/mockObjects/content-services/categories.mock.ts index 33fb428271..131fc9d829 100644 --- a/lib/js-api/test/mockObjects/content-services/categories.mock.ts +++ b/lib/js-api/test/mockObjects/content-services/categories.mock.ts @@ -20,7 +20,7 @@ import { BaseMock } from '../base.mock'; export class CategoriesMock extends BaseMock { get200ResponseSubcategories(categoryId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}/subcategories`) .reply(200, { list: { @@ -56,7 +56,7 @@ export class CategoriesMock extends BaseMock { } get404SubcategoryNotExist(categoryId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}/subcategories`) .reply(404, { error: { @@ -70,7 +70,7 @@ export class CategoriesMock extends BaseMock { } get200ResponseCategory(categoryId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}`) .reply(200, { entry: { @@ -84,7 +84,7 @@ export class CategoriesMock extends BaseMock { } get404CategoryNotExist(categoryId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}`) .reply(404, { error: { @@ -98,7 +98,7 @@ export class CategoriesMock extends BaseMock { } get200ResponseNodeCategoryLinks(nodeId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`) .reply(200, { list: { @@ -125,7 +125,7 @@ export class CategoriesMock extends BaseMock { } get403NodeCategoryLinksPermissionDenied(nodeId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`) .reply(403, { error: { @@ -135,7 +135,7 @@ export class CategoriesMock extends BaseMock { } get404NodeNotExist(nodeId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`) .reply(404, { error: { @@ -149,13 +149,13 @@ export class CategoriesMock extends BaseMock { } get204CategoryUnlinked(nodeId: string, categoryId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .delete(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links/${categoryId}`) .reply(204); } get403CategoryUnlinkPermissionDenied(nodeId: string, categoryId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .delete(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links/${categoryId}`) .reply(403, { error: { @@ -165,7 +165,7 @@ export class CategoriesMock extends BaseMock { } get404CategoryUnlinkNotFound(nodeId: string, categoryId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .delete(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links/${categoryId}`) .reply(404, { error: { @@ -179,7 +179,7 @@ export class CategoriesMock extends BaseMock { } get200ResponseCategoryUpdated(categoryId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .put(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}`, { name: 'testName1' }) .reply(200, { entry: { @@ -193,7 +193,7 @@ export class CategoriesMock extends BaseMock { } get403CategoryUpdatePermissionDenied(categoryId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .put(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}`, { name: 'testName1' }) .reply(403, { error: { @@ -203,7 +203,7 @@ export class CategoriesMock extends BaseMock { } get404CategoryUpdateNotFound(categoryId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .put(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}`, { name: 'testName1' }) .reply(404, { error: { @@ -217,7 +217,7 @@ export class CategoriesMock extends BaseMock { } get201ResponseCategoryCreated(categoryId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}/subcategories`, [{ name: 'testName10' }]) .reply(201, { entry: { @@ -231,7 +231,7 @@ export class CategoriesMock extends BaseMock { } get403CategoryCreatedPermissionDenied(categoryId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}/subcategories`, [{ name: 'testName10' }]) .reply(403, { error: { @@ -241,7 +241,7 @@ export class CategoriesMock extends BaseMock { } get409CategoryCreateAlreadyExists(categoryId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}/subcategories`, [{ name: 'testName10' }]) .reply(409, { error: { @@ -255,7 +255,7 @@ export class CategoriesMock extends BaseMock { } get201ResponseCategoryLinked(nodeId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`, [{ categoryId: 'testId1' }]) .reply(201, { entry: { @@ -269,7 +269,7 @@ export class CategoriesMock extends BaseMock { } get201ResponseCategoryLinkedArray(nodeId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`, [ { categoryId: 'testId1' }, { categoryId: 'testId2' } @@ -308,7 +308,7 @@ export class CategoriesMock extends BaseMock { } get403CategoryLinkPermissionDenied(nodeId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`, [{ categoryId: 'testId1' }]) .reply(403, { error: { @@ -318,7 +318,7 @@ export class CategoriesMock extends BaseMock { } get404CategoryLinkNotFound(nodeId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`, [{ categoryId: 'testId1' }]) .reply(404, { error: { @@ -332,7 +332,7 @@ export class CategoriesMock extends BaseMock { } get405CategoryLinkCannotAssign(nodeId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`, [{ categoryId: 'testId1' }]) .reply(405, { error: { diff --git a/lib/js-api/test/mockObjects/content-services/comment.mock.ts b/lib/js-api/test/mockObjects/content-services/comment.mock.ts index 1f398471fd..e42ac727f2 100644 --- a/lib/js-api/test/mockObjects/content-services/comment.mock.ts +++ b/lib/js-api/test/mockObjects/content-services/comment.mock.ts @@ -40,7 +40,7 @@ const adminUser = { export class CommentMock extends BaseMock { post201Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/74cd8a96-8a21-47e5-9b3b-a1b3e296787d/comments', { content: 'This is a comment' }) @@ -60,7 +60,7 @@ export class CommentMock extends BaseMock { } get200Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/74cd8a96-8a21-47e5-9b3b-a1b3e296787d/comments') .reply(200, { list: { diff --git a/lib/js-api/test/mockObjects/content-services/custom-model.mock.ts b/lib/js-api/test/mockObjects/content-services/custom-model.mock.ts index 15e5c6c510..4fd0658eb1 100644 --- a/lib/js-api/test/mockObjects/content-services/custom-model.mock.ts +++ b/lib/js-api/test/mockObjects/content-services/custom-model.mock.ts @@ -20,7 +20,7 @@ import { BaseMock } from '../base.mock'; export class CustomModelMock extends BaseMock { get200AllCustomModel(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/private/alfresco/versions/1/cmm') .reply(200, { list: { @@ -37,7 +37,7 @@ export class CustomModelMock extends BaseMock { } create201CustomModel(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/private/alfresco/versions/1/cmm') .reply(201, { entry: { @@ -52,7 +52,7 @@ export class CustomModelMock extends BaseMock { } activateCustomModel200(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .put('/alfresco/api/-default-/private/alfresco/versions/1/cmm/testModel', { status: 'ACTIVE' }) .query({ select: 'status' }) .reply(200, { diff --git a/lib/js-api/test/mockObjects/content-services/discovery.mock.ts b/lib/js-api/test/mockObjects/content-services/discovery.mock.ts index 06dbb4d2a2..0099ca6626 100644 --- a/lib/js-api/test/mockObjects/content-services/discovery.mock.ts +++ b/lib/js-api/test/mockObjects/content-services/discovery.mock.ts @@ -15,12 +15,11 @@ * limitations under the License. */ -import nock from 'nock'; import { BaseMock } from '../base.mock'; export class DiscoveryMock extends BaseMock { get200Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/discovery') .reply(200, { entry: { diff --git a/lib/js-api/test/mockObjects/content-services/ecm-auth.mock.ts b/lib/js-api/test/mockObjects/content-services/ecm-auth.mock.ts index 946a5fb3c0..57ac9478d0 100644 --- a/lib/js-api/test/mockObjects/content-services/ecm-auth.mock.ts +++ b/lib/js-api/test/mockObjects/content-services/ecm-auth.mock.ts @@ -31,24 +31,29 @@ export class EcmAuthMock extends BaseMock { get201Response(forceTicket?: string): void { const returnMockTicket = forceTicket || 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'; - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/authentication/versions/1/tickets', { - userId: this.username, - password: this.password + userId: 'admin', + password: 'admin' }) - .reply(201, { entry: { id: returnMockTicket, userId: 'admin' } }); + .reply(201, { + entry: { + id: returnMockTicket, + userId: 'admin' + } + }); } get200ValidTicket(forceTicket?: string): void { const returnMockTicket = forceTicket || 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'; - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/authentication/versions/1/tickets/-me-') .reply(200, { entry: { id: returnMockTicket } }); } get401InvalidTicket(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/authentication/versions/1/tickets/-me-') .reply(401, { error: { @@ -62,7 +67,7 @@ export class EcmAuthMock extends BaseMock { } get403Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/authentication/versions/1/tickets', { userId: 'wrong', password: 'name' @@ -79,24 +84,56 @@ export class EcmAuthMock extends BaseMock { } get400Response(): void { - nock(this.host, { encodedQueryParams: true }) + nock(this.host).options(/.*/).reply(200, '', { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type, Authorization, Content-Length, X-Requested-With', + 'Access-Control-Allow-Credentials': 'true' + }); + + nock(this.host) + .defaultReplyHeaders({ + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Credentials': 'true' + }) .post('/alfresco/api/-default-/public/authentication/versions/1/tickets', { userId: null, password: null }) .reply(400, { error: { - errorKey: 'Invalid login details.', + errorKey: 'Bad Request', statusCode: 400, - briefSummary: '05160045 Invalid login details.', - stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.', - descriptionURL: 'https://api-explorer.alfresco.com' + briefSummary: 'userId and/or password are/is not provided' + } + }); + } + + get400ResponseGET(): void { + nock(this.host).persist().options(/.*/).reply(200, '', { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type, Authorization, Content-Length, X-Requested-With', + 'Access-Control-Allow-Credentials': 'true' + }); + + nock(this.host) + .defaultReplyHeaders({ + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Credentials': 'true' + }) + .get('/alfresco/api/-default-/public/authentication/versions/1/tickets/-me-') + .reply(400, { + error: { + errorKey: 'Bad Request', + statusCode: 400, + briefSummary: '05160045 Invalid login details.' } }); } get401Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/authentication/versions/1/tickets', { userId: 'wrong', password: 'name' @@ -113,10 +150,20 @@ export class EcmAuthMock extends BaseMock { } get204ResponseLogout(): void { - nock(this.host, { encodedQueryParams: true }).delete('/alfresco/api/-default-/public/authentication/versions/1/tickets/-me-').reply(204, ''); + this.createNockWithCors().delete('/alfresco/api/-default-/public/authentication/versions/1/tickets/-me-').reply(204, ''); } get404ResponseLogout(): void { - nock(this.host, { encodedQueryParams: true }).delete('/alfresco/api/-default-/public/authentication/versions/1/tickets/-me-').reply(404, ''); + this.createNockWithCors() + .delete('/alfresco/api/-default-/public/authentication/versions/1/tickets/-me-') + .reply(404, { + error: { + errorKey: 'Not Found', + statusCode: 404, + briefSummary: 'Not Found', + stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.', + descriptionURL: 'https://api-explorer.alfresco.com' + } + }); } } diff --git a/lib/js-api/test/mockObjects/content-services/find-nodes.mock.ts b/lib/js-api/test/mockObjects/content-services/find-nodes.mock.ts index fd7fcd03cc..96bc5958a9 100644 --- a/lib/js-api/test/mockObjects/content-services/find-nodes.mock.ts +++ b/lib/js-api/test/mockObjects/content-services/find-nodes.mock.ts @@ -20,7 +20,7 @@ import { BaseMock } from '../base.mock'; export class FindNodesMock extends BaseMock { get200Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/alfresco/versions/1/queries/nodes?term=test') .reply(200, { list: { @@ -78,7 +78,7 @@ export class FindNodesMock extends BaseMock { } get401Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/alfresco/versions/1/queries/nodes?term=test') .reply(401, { error: { diff --git a/lib/js-api/test/mockObjects/content-services/groups.mock.ts b/lib/js-api/test/mockObjects/content-services/groups.mock.ts index a59bf57ac3..ecf81cb087 100644 --- a/lib/js-api/test/mockObjects/content-services/groups.mock.ts +++ b/lib/js-api/test/mockObjects/content-services/groups.mock.ts @@ -15,12 +15,11 @@ * limitations under the License. */ -import nock from 'nock'; import { BaseMock } from '../base.mock'; export class GroupsMock extends BaseMock { get200GetGroups(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/alfresco/versions/1/groups') .reply(200, { list: { @@ -52,20 +51,20 @@ export class GroupsMock extends BaseMock { } getDeleteGroupSuccessfulResponse(groupName: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .delete('/alfresco/api/-default-/public/alfresco/versions/1/groups/' + groupName) .query({ cascade: 'false' }) .reply(200); } getDeleteMemberForGroupSuccessfulResponse(groupName: string, memberName: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .delete('/alfresco/api/-default-/public/alfresco/versions/1/groups/' + groupName + '/members/' + memberName) .reply(200); } get200CreateGroupResponse(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/alfresco/versions/1/groups') .reply(200, { entry: { @@ -77,7 +76,7 @@ export class GroupsMock extends BaseMock { } get200GetSingleGroup(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/alfresco/versions/1/groups/GROUP_TEST') .reply(200, { entry: { @@ -89,7 +88,7 @@ export class GroupsMock extends BaseMock { } get200UpdateGroupResponse(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .put('/alfresco/api/-default-/public/alfresco/versions/1/groups/GROUP_TEST') .reply(200, { entry: { @@ -101,7 +100,7 @@ export class GroupsMock extends BaseMock { } get200GetGroupMemberships(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/alfresco/versions/1/groups/GROUP_TEST/members') .reply(200, { list: { @@ -126,7 +125,7 @@ export class GroupsMock extends BaseMock { } get200AddGroupMembershipResponse(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/alfresco/versions/1/groups/GROUP_TEST/members') .reply(200, { entry: { diff --git a/lib/js-api/test/mockObjects/content-services/node.mock.ts b/lib/js-api/test/mockObjects/content-services/node.mock.ts index 6baca0b833..161c369cf8 100644 --- a/lib/js-api/test/mockObjects/content-services/node.mock.ts +++ b/lib/js-api/test/mockObjects/content-services/node.mock.ts @@ -20,7 +20,7 @@ import { BaseMock } from '../base.mock'; export class NodeMock extends BaseMock { get200ResponseChildren(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/b4cff62a-664d-4d45-9302-98723eac1319/children') .reply(200, { list: { @@ -108,7 +108,7 @@ export class NodeMock extends BaseMock { } get200ResponseChildrenNonUTCTimes(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/b4cff62a-664d-4d45-9302-98723eac1320/children') .reply(200, { list: { @@ -140,7 +140,7 @@ export class NodeMock extends BaseMock { } get404ChildrenNotExist(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/b4cff62a-664d-4d45-9302-98723eac1319/children') .reply(404, { error: { @@ -154,23 +154,19 @@ export class NodeMock extends BaseMock { } get401CreationFolder(): void { - nock(this.host, { encodedQueryParams: true }).post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children').reply(401); + this.createNockWithCors().post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children').reply(401); } get204SuccessfullyDeleted(): void { - nock(this.host, { encodedQueryParams: true }) - .delete('/alfresco/api/-default-/public/alfresco/versions/1/nodes/80a94ac8-3ece-47ad-864e-5d939424c47c') - .reply(204); + this.createNockWithCors().delete('/alfresco/api/-default-/public/alfresco/versions/1/nodes/80a94ac8-3ece-47ad-864e-5d939424c47c').reply(204); } get403DeletePermissionDenied(): void { - nock(this.host, { encodedQueryParams: true }) - .delete('/alfresco/api/-default-/public/alfresco/versions/1/nodes/80a94ac8-3ece-47ad-864e-5d939424c47c') - .reply(403); + this.createNockWithCors().delete('/alfresco/api/-default-/public/alfresco/versions/1/nodes/80a94ac8-3ece-47ad-864e-5d939424c47c').reply(403); } get404DeleteNotFound(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .delete('/alfresco/api/-default-/public/alfresco/versions/1/nodes/80a94ac8-test-47ad-864e-5d939424c47c') .reply(404, { error: { @@ -184,7 +180,7 @@ export class NodeMock extends BaseMock { } get200ResponseChildrenFutureNewPossibleValue(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/b4cff62a-664d-4d45-9302-98723eac1319/children') .reply(200, { list: { @@ -232,7 +228,7 @@ export class NodeMock extends BaseMock { } post200ResponseInitiateFolderSizeCalculation(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/b4cff62a-664d-4d45-9302-98723eac1319/size-details') .reply(200, { entry: { @@ -242,7 +238,7 @@ export class NodeMock extends BaseMock { } post404NodeIdNotFound(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/b4cff62a-664d-4d45-9302-98723eac1319/size-details') .reply(404, { error: { @@ -257,7 +253,7 @@ export class NodeMock extends BaseMock { } get200ResponseGetFolderSizeInfo(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get( '/alfresco/api/-default-/public/alfresco/versions/1/nodes/b4cff62a-664d-4d45-9302-98723eac1319/size-details/5ade426e-8a04-4d50-9e42-6e8a041d50f3' ) @@ -274,7 +270,7 @@ export class NodeMock extends BaseMock { } get404JobIdNotFound(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get( '/alfresco/api/-default-/public/alfresco/versions/1/nodes/b4cff62a-664d-4d45-9302-98723eac1319/size-details/5ade426e-8a04-4d50-9e42-6e8a041d50f3' ) diff --git a/lib/js-api/test/mockObjects/content-services/people.mock.ts b/lib/js-api/test/mockObjects/content-services/people.mock.ts index 0361e21ea9..b5004c9ade 100644 --- a/lib/js-api/test/mockObjects/content-services/people.mock.ts +++ b/lib/js-api/test/mockObjects/content-services/people.mock.ts @@ -20,7 +20,7 @@ import { BaseMock } from '../base.mock'; export class PeopleMock extends BaseMock { get201Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/alfresco/versions/1/people') .reply(201, { entry: { @@ -36,7 +36,7 @@ export class PeopleMock extends BaseMock { } get200ResponsePersons(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/alfresco/versions/1/people') .reply(200, { list: { diff --git a/lib/js-api/test/mockObjects/content-services/rendition.mock.ts b/lib/js-api/test/mockObjects/content-services/rendition.mock.ts index 82cb974bfc..8720696423 100644 --- a/lib/js-api/test/mockObjects/content-services/rendition.mock.ts +++ b/lib/js-api/test/mockObjects/content-services/rendition.mock.ts @@ -15,12 +15,11 @@ * limitations under the License. */ -import nock from 'nock'; import { BaseMock } from '../base.mock'; export class RenditionMock extends BaseMock { get200RenditionResponse(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/97a29e9c-1e4f-4d9d-bb02-1ec920dda045/renditions/pdf') .reply(200, { entry: { @@ -32,13 +31,13 @@ export class RenditionMock extends BaseMock { } createRendition200(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/97a29e9c-1e4f-4d9d-bb02-1ec920dda045/renditions', { id: 'pdf' }) .reply(202, ''); } get200RenditionList(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/97a29e9c-1e4f-4d9d-bb02-1ec920dda045/renditions') .reply(200, { list: { diff --git a/lib/js-api/test/mockObjects/content-services/search-ai.mock.ts b/lib/js-api/test/mockObjects/content-services/search-ai.mock.ts index daac9702ec..9a548db405 100644 --- a/lib/js-api/test/mockObjects/content-services/search-ai.mock.ts +++ b/lib/js-api/test/mockObjects/content-services/search-ai.mock.ts @@ -16,11 +16,10 @@ */ import { BaseMock } from '../base.mock'; -import nock from 'nock'; export class SearchAiMock extends BaseMock { mockGetAsk200Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/private/hxi/versions/1/agents/id1/questions', [ { question: 'some question 1', @@ -41,7 +40,7 @@ export class SearchAiMock extends BaseMock { } mockGetAnswer200Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/private/hxi/versions/1/questions/id1/answers/-default-') .reply(200, { entry: { @@ -85,7 +84,7 @@ export class SearchAiMock extends BaseMock { } mockGetConfig200Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/private/hxi/versions/1/config/-default-') .reply(200, { entry: { diff --git a/lib/js-api/test/mockObjects/content-services/search.mock.ts b/lib/js-api/test/mockObjects/content-services/search.mock.ts index 5e7796269c..b3711b4d21 100644 --- a/lib/js-api/test/mockObjects/content-services/search.mock.ts +++ b/lib/js-api/test/mockObjects/content-services/search.mock.ts @@ -15,13 +15,12 @@ * limitations under the License. */ -import nock from 'nock'; import { BaseMock } from '../base.mock'; import { SEARCH_LANGUAGE } from '@alfresco/js-api'; export class SearchMock extends BaseMock { get200Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/search/versions/1/search', { query: { query: 'select * from cmis:folder', diff --git a/lib/js-api/test/mockObjects/content-services/tag.mock.ts b/lib/js-api/test/mockObjects/content-services/tag.mock.ts index ba3362c1b3..a7853e30f9 100644 --- a/lib/js-api/test/mockObjects/content-services/tag.mock.ts +++ b/lib/js-api/test/mockObjects/content-services/tag.mock.ts @@ -15,25 +15,22 @@ * limitations under the License. */ -import nock from 'nock'; import { BaseMock } from '../base.mock'; import { TagBody, TagEntry, TagPaging } from '../../../src/api/content-rest-api'; export class TagMock extends BaseMock { get200Response(): void { - nock(this.host, { encodedQueryParams: true }) - .get('/alfresco/api/-default-/public/alfresco/versions/1/tags') - .reply(200, this.getPaginatedListOfTags()); + this.createNockWithCors().get('/alfresco/api/-default-/public/alfresco/versions/1/tags').reply(200, this.getPaginatedListOfTags()); } getTagsByNameFilteredByMatching200Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/alfresco/versions/1/tags?where=(tag%20matches%20(%27*tag-test*%27))') .reply(200, this.getPaginatedListOfTags()); } getTagsByNamesFilterByExactTag200Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/alfresco/versions/1/tags?where=(tag%3D%27tag-test-1%27)') .reply(200, { list: { @@ -49,7 +46,7 @@ export class TagMock extends BaseMock { } get401Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/alfresco/versions/1/tags') .reply(401, { error: { @@ -63,13 +60,11 @@ export class TagMock extends BaseMock { } createTags201Response(): void { - nock(this.host, { encodedQueryParams: true }) - .post('/alfresco/api/-default-/public/alfresco/versions/1/tags') - .reply(201, this.getPaginatedListOfTags()); + this.createNockWithCors().post('/alfresco/api/-default-/public/alfresco/versions/1/tags').reply(201, this.getPaginatedListOfTags()); } get201ResponseForAssigningTagsToNode(body: TagBody[]): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/someNodeId/tags', JSON.stringify(body)) .reply(201, body.length > 1 ? this.getPaginatedListOfTags() : this.mockTagEntry()); } diff --git a/lib/js-api/test/mockObjects/content-services/upload.mock.ts b/lib/js-api/test/mockObjects/content-services/upload.mock.ts index d3ffca0963..642ca3f871 100644 --- a/lib/js-api/test/mockObjects/content-services/upload.mock.ts +++ b/lib/js-api/test/mockObjects/content-services/upload.mock.ts @@ -20,7 +20,19 @@ import { BaseMock } from '../base.mock'; export class UploadMock extends BaseMock { get201CreationFile(): void { - nock(this.host, { encodedQueryParams: true }) + nock(this.host).persist().options(/.*/).reply(200, '', { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type, Authorization, Content-Length, X-Requested-With', + 'Access-Control-Allow-Credentials': 'true' + }); + + // Handle POST request with any query parameters + nock(this.host) + .defaultReplyHeaders({ + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Credentials': 'true' + }) .post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children') .reply(201, { entry: { @@ -47,7 +59,7 @@ export class UploadMock extends BaseMock { } get201CreationFileAutoRename(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children') .query({ autoRename: 'true' }) .reply(201, { @@ -75,7 +87,7 @@ export class UploadMock extends BaseMock { } get409CreationFileNewNameClashes(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children') .reply(409, { error: { @@ -89,7 +101,7 @@ export class UploadMock extends BaseMock { } get401Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children') .reply(401, { error: { diff --git a/lib/js-api/test/mockObjects/content-services/version.mock.ts b/lib/js-api/test/mockObjects/content-services/version.mock.ts index 9bb1dd4bfe..76bfbc5aa1 100644 --- a/lib/js-api/test/mockObjects/content-services/version.mock.ts +++ b/lib/js-api/test/mockObjects/content-services/version.mock.ts @@ -15,18 +15,17 @@ * limitations under the License. */ -import nock from 'nock'; import { BaseMock } from '../base.mock'; export class VersionMock extends BaseMock { post201Response(nodeId: string, versionId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/' + nodeId + '/versions/' + versionId + '/revert') .reply(201, { entry: { id: '3.0' } }); } get200Response(nodeId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/' + nodeId + '/versions') .reply(200, { list: { @@ -43,7 +42,7 @@ export class VersionMock extends BaseMock { } get200ResponseVersionRenditions(nodeId: string, versionId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/' + nodeId + '/versions/' + versionId + '/renditions') .reply(200, { list: { @@ -103,7 +102,7 @@ export class VersionMock extends BaseMock { } get200VersionRendition(nodeId: string, versionId: string, renditionId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/' + nodeId + '/versions/' + versionId + '/renditions/' + renditionId) .reply(200, { entry: { @@ -115,7 +114,7 @@ export class VersionMock extends BaseMock { } create200VersionRendition(nodeId: string, versionId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/' + nodeId + '/versions/' + versionId + '/renditions', { id: 'pdf' }) .reply(202, ''); } diff --git a/lib/js-api/test/mockObjects/content-services/webscript.mock.ts b/lib/js-api/test/mockObjects/content-services/webscript.mock.ts index 4646d2ba7c..9662e2dec7 100644 --- a/lib/js-api/test/mockObjects/content-services/webscript.mock.ts +++ b/lib/js-api/test/mockObjects/content-services/webscript.mock.ts @@ -15,7 +15,6 @@ * limitations under the License. */ -import nock from 'nock'; import { BaseMock } from '../base.mock'; export class WebScriptMock extends BaseMock { @@ -34,7 +33,7 @@ export class WebScriptMock extends BaseMock { } get404Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get(this.scriptSlug) .reply(404, { error: { @@ -48,7 +47,7 @@ export class WebScriptMock extends BaseMock { } get200Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get(this.scriptSlug) .reply(200, { randomStructure: { @@ -59,17 +58,15 @@ export class WebScriptMock extends BaseMock { } get200ResponseHTMLFormat(): void { - nock(this.host, { encodedQueryParams: true }) - .get('/alfresco/service/sample/folder/Company%20Home') - .reply( - 200, - // eslint-disable-next-line max-len - '\n \n /Company Home\n \n \n Folder: /Company Home\n
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
>Data Dictionary\n
>Guest Home\n
>User Homes\n
>Shared\n
>Imap Attachments\n
>IMAP Home\n
>Sites\n
>x\n
testFile.txt\n
>newFolder\n
>newFolder-1\n
testFile-1.txt\n
testFile-2.txt\n
testFile-3.txt\n
\n \n\n\n' - ); // jshint ignore:line + this.createNockWithCors().get('/alfresco/service/sample/folder/Company%20Home').reply( + 200, + // eslint-disable-next-line max-len + '\n \n /Company Home\n \n \n Folder: /Company Home\n
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
>Data Dictionary\n
>Guest Home\n
>User Homes\n
>Shared\n
>Imap Attachments\n
>IMAP Home\n
>Sites\n
>x\n
testFile.txt\n
>newFolder\n
>newFolder-1\n
testFile-1.txt\n
testFile-2.txt\n
testFile-3.txt\n
\n \n\n\n' + ); // jshint ignore:line } get401Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get(this.scriptSlug) .reply(401, { error: { diff --git a/lib/js-api/test/mockObjects/goverance-services/authority-clearance.mock.ts b/lib/js-api/test/mockObjects/goverance-services/authority-clearance.mock.ts index 589f6232f5..f0abc9a2b8 100644 --- a/lib/js-api/test/mockObjects/goverance-services/authority-clearance.mock.ts +++ b/lib/js-api/test/mockObjects/goverance-services/authority-clearance.mock.ts @@ -16,11 +16,10 @@ */ import { BaseMock } from '../base.mock'; -import nock from 'nock'; export class AuthorityClearanceMock extends BaseMock { get200AuthorityClearanceForAuthority(authorityId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/gs/versions/1/cleared-authorities/' + authorityId + '/clearing-marks?skipCount=0&maxItems=100') .reply(200, { list: { @@ -94,7 +93,7 @@ export class AuthorityClearanceMock extends BaseMock { } post200AuthorityClearanceWithSingleItem(authorityId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/gs/versions/1/cleared-authorities/' + authorityId + '/clearing-marks') .reply(200, { entry: { @@ -106,7 +105,7 @@ export class AuthorityClearanceMock extends BaseMock { } post200AuthorityClearanceWithList(authorityId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/gs/versions/1/cleared-authorities/' + authorityId + '/clearing-marks') .reply(200, { list: { diff --git a/lib/js-api/test/mockObjects/goverance-services/file-plans.mock.ts b/lib/js-api/test/mockObjects/goverance-services/file-plans.mock.ts index 64e4997b93..098405a735 100644 --- a/lib/js-api/test/mockObjects/goverance-services/file-plans.mock.ts +++ b/lib/js-api/test/mockObjects/goverance-services/file-plans.mock.ts @@ -49,7 +49,7 @@ export class FilePlansMock extends BaseMock { } private nock200FilePlanRoles(filePlanId: string): nock.Interceptor { - return nock(this.host, { encodedQueryParams: true }).get(`/alfresco/api/-default-/public/gs/versions/1/file-plans/${filePlanId}/roles`); + return this.createNockWithCors().get(`/alfresco/api/-default-/public/gs/versions/1/file-plans/${filePlanId}/roles`); } private mockFilePlanRolePaging(): FilePlanRolePaging { diff --git a/lib/js-api/test/mockObjects/goverance-services/gs-sites.mock.ts b/lib/js-api/test/mockObjects/goverance-services/gs-sites.mock.ts index 36501176b3..13d98ead35 100644 --- a/lib/js-api/test/mockObjects/goverance-services/gs-sites.mock.ts +++ b/lib/js-api/test/mockObjects/goverance-services/gs-sites.mock.ts @@ -15,12 +15,11 @@ * limitations under the License. */ -import nock from 'nock'; import { BaseMock } from '../base.mock'; export class GsSitesApiMock extends BaseMock { get200Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/gs/versions/1/gs-sites/rm') .reply(200, { entry: { diff --git a/lib/js-api/test/mockObjects/goverance-services/node-security-marks.mock.ts b/lib/js-api/test/mockObjects/goverance-services/node-security-marks.mock.ts index 6f551d3efa..40fc20858c 100644 --- a/lib/js-api/test/mockObjects/goverance-services/node-security-marks.mock.ts +++ b/lib/js-api/test/mockObjects/goverance-services/node-security-marks.mock.ts @@ -15,12 +15,11 @@ * limitations under the License. */ -import nock from 'nock'; import { BaseMock } from '../base.mock'; export class NodeSecurityMarksApiMock extends BaseMock { post200manageSecurityMarkOnNode(nodeId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/gs/versions/1/secured-nodes/' + nodeId + '/securing-marks') .reply(200, { list: { @@ -52,7 +51,7 @@ export class NodeSecurityMarksApiMock extends BaseMock { } get200SecurityMarkOnNode(nodeId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/gs/versions/1/secured-nodes/' + nodeId + '/securing-marks') .reply(200, { list: { diff --git a/lib/js-api/test/mockObjects/goverance-services/security-groups.mock.ts b/lib/js-api/test/mockObjects/goverance-services/security-groups.mock.ts index 95bb7afa37..aa2671914d 100644 --- a/lib/js-api/test/mockObjects/goverance-services/security-groups.mock.ts +++ b/lib/js-api/test/mockObjects/goverance-services/security-groups.mock.ts @@ -15,12 +15,11 @@ * limitations under the License. */ -import nock from 'nock'; import { BaseMock } from '../base.mock'; export class SecurityGroupApiMock extends BaseMock { createSecurityGroup200Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/gs/versions/1/security-groups') .reply(200, { entry: { @@ -32,7 +31,7 @@ export class SecurityGroupApiMock extends BaseMock { } getSecurityGroups200Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/gs/versions/1/security-groups') .reply(200, { list: { @@ -64,7 +63,7 @@ export class SecurityGroupApiMock extends BaseMock { } getSecurityGroupInfo200Response(securityGroupId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/gs/versions/1/security-groups/' + securityGroupId) .reply(200, { entry: { @@ -76,7 +75,7 @@ export class SecurityGroupApiMock extends BaseMock { } updateSecurityGroup200Response(securityGroupId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .put('/alfresco/api/-default-/public/gs/versions/1/security-groups/' + securityGroupId) .reply(200, { entry: { @@ -88,7 +87,7 @@ export class SecurityGroupApiMock extends BaseMock { } deleteSecurityGroup200Response(securityGroupId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .delete('/alfresco/api/-default-/public/alfresco/versions/1/security-groups/' + securityGroupId) .reply(200); } diff --git a/lib/js-api/test/mockObjects/goverance-services/security-marks.mock.ts b/lib/js-api/test/mockObjects/goverance-services/security-marks.mock.ts index af7afc9ceb..3f439f74e8 100644 --- a/lib/js-api/test/mockObjects/goverance-services/security-marks.mock.ts +++ b/lib/js-api/test/mockObjects/goverance-services/security-marks.mock.ts @@ -15,12 +15,11 @@ * limitations under the License. */ -import nock from 'nock'; import { BaseMock } from '../base.mock'; export class SecurityMarkApiMock extends BaseMock { get200GetSecurityMark(securityGroupId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/gs/versions/1/security-groups/' + securityGroupId + '/security-marks') .reply(200, { list: { @@ -45,7 +44,7 @@ export class SecurityMarkApiMock extends BaseMock { } createSecurityMark200Response(securityGroupId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/gs/versions/1/security-groups/' + securityGroupId + '/security-marks') .reply(200, { entry: { @@ -56,7 +55,7 @@ export class SecurityMarkApiMock extends BaseMock { }); } createSecurityMarks200Response(securityGroupId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/alfresco/api/-default-/public/gs/versions/1/security-groups/' + securityGroupId + '/security-marks') .reply(200, { list: { @@ -87,7 +86,7 @@ export class SecurityMarkApiMock extends BaseMock { }); } get200GetSingleSecurityMark(securityGroupId: string, securityMarkId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/gs/versions/1/security-groups/' + securityGroupId + '/security-marks/' + securityMarkId) .reply(200, { entry: { @@ -98,7 +97,7 @@ export class SecurityMarkApiMock extends BaseMock { }); } put200UpdateSecurityMarkResponse(securityGroupId: string, securityMarkId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .put('/alfresco/api/-default-/public/gs/versions/1/security-groups/' + securityGroupId + '/security-marks/' + securityMarkId) .reply(200, { entry: { @@ -109,12 +108,12 @@ export class SecurityMarkApiMock extends BaseMock { }); } getDeleteSecurityMarkSuccessfulResponse(securityGroupId: string, securityMarkId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .delete('/alfresco/api/-default-/public/gs/versions/1/security-groups/' + securityGroupId + '/security-marks/' + securityMarkId) .reply(200); } get401Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/alfresco/api/-default-/public/gs/versions/1/security-groups/') .reply(401, { error: { diff --git a/lib/js-api/test/mockObjects/oauth2/oauth.mock.ts b/lib/js-api/test/mockObjects/oauth2/oauth.mock.ts index 1171e04f29..6fd746dc65 100644 --- a/lib/js-api/test/mockObjects/oauth2/oauth.mock.ts +++ b/lib/js-api/test/mockObjects/oauth2/oauth.mock.ts @@ -29,13 +29,7 @@ export class OAuthMock extends BaseMock { } get200Response(mockToken?: string): void { - nock(this.host).options('/auth/realms/springboot/protocol/openid-connect/token').reply(200, '', { - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', - 'Access-Control-Allow-Headers': 'Content-Type, Authorization', - 'Access-Control-Max-Age': '86400' - }); - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/auth/realms/springboot/protocol/openid-connect/token') .reply( 200, diff --git a/lib/js-api/test/mockObjects/process-services/bpm-auth.mock.ts b/lib/js-api/test/mockObjects/process-services/bpm-auth.mock.ts index aae55fd881..afd67bf2d6 100644 --- a/lib/js-api/test/mockObjects/process-services/bpm-auth.mock.ts +++ b/lib/js-api/test/mockObjects/process-services/bpm-auth.mock.ts @@ -29,7 +29,15 @@ export class BpmAuthMock extends BaseMock { } get200Response(): void { + this.addCorsSupport(); nock(this.host, { encodedQueryParams: true }) + .defaultReplyHeaders({ + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type, Authorization, Content-Length, X-Requested-With, Cache-Control, X-CSRF-TOKEN', + 'Access-Control-Allow-Credentials': 'true', + 'Set-Cookie': 'ACTIVITI_REMEMBER_ME=NjdOdGwvcUtFTkVEczQyMGh4WFp5QT09OmpUL1UwdFVBTC94QTJMTFFUVFgvdFE9PQ; Path=/; HttpOnly' + }) .post( '/activiti-app/app/authentication', 'j_username=' + this.username + '&j_password=' + this.password + '&_spring_security_remember_me=true&submit=Login' @@ -38,11 +46,11 @@ export class BpmAuthMock extends BaseMock { } get200ResponseLogout(): void { - nock(this.host, { encodedQueryParams: true }).get('/activiti-app/app/logout', {}).reply(200); + this.createNockWithCors().get('/activiti-app/app/logout').reply(200); } get401Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/activiti-app/app/authentication', 'j_username=wrong&j_password=name&_spring_security_remember_me=true&submit=Login') .reply(401, { error: { @@ -53,7 +61,7 @@ export class BpmAuthMock extends BaseMock { } get403Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/activiti-app/app/authentication', 'j_username=wrong&j_password=name&_spring_security_remember_me=true&submit=Login') .reply(403, { error: { diff --git a/lib/js-api/test/mockObjects/process-services/model-json.mock.ts b/lib/js-api/test/mockObjects/process-services/model-json.mock.ts index c2924acd52..bd752f0f50 100644 --- a/lib/js-api/test/mockObjects/process-services/model-json.mock.ts +++ b/lib/js-api/test/mockObjects/process-services/model-json.mock.ts @@ -15,12 +15,11 @@ * limitations under the License. */ -import nock from 'nock'; import { BaseMock } from '../base.mock'; export class ModelJsonBpmMock extends BaseMock { get200EditorDisplayJsonClient(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/activiti-app/app/rest/models/1/model-json') .reply(200, { elements: [ @@ -87,7 +86,7 @@ export class ModelJsonBpmMock extends BaseMock { } get200HistoricEditorDisplayJsonClient(): void { - nock('https://127.0.0.1:9999', { encodedQueryParams: true }) + this.createNockWithCors() .get('/activiti-app/app/rest/models/1/history/1/model-json') .reply(200, { elements: [ diff --git a/lib/js-api/test/mockObjects/process-services/models.mock.ts b/lib/js-api/test/mockObjects/process-services/models.mock.ts index 63d4261b63..5ca2438e0b 100644 --- a/lib/js-api/test/mockObjects/process-services/models.mock.ts +++ b/lib/js-api/test/mockObjects/process-services/models.mock.ts @@ -15,12 +15,11 @@ * limitations under the License. */ -import nock from 'nock'; import { BaseMock } from '../base.mock'; export class ModelsMock extends BaseMock { get200getModels(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/activiti-app/api/enterprise/models') .query({ filter: 'myReusableForms', modelType: '2' }) .reply(200, { diff --git a/lib/js-api/test/mockObjects/process-services/process-instance-variables.mock.ts b/lib/js-api/test/mockObjects/process-services/process-instance-variables.mock.ts index e1dc6d5efe..364e05ed6b 100644 --- a/lib/js-api/test/mockObjects/process-services/process-instance-variables.mock.ts +++ b/lib/js-api/test/mockObjects/process-services/process-instance-variables.mock.ts @@ -34,13 +34,13 @@ const fakeVariablesList = [fakeVariable1, fakeVariable2]; export class ProcessInstanceVariablesMock extends BaseMock { addListProcessInstanceVariables200Response(processInstanceId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables') .reply(200, fakeVariablesList); } addListProcessInstanceVariables500Response(processInstanceId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables') .reply(500, { messageKey: 'UNKNOWN', @@ -49,13 +49,13 @@ export class ProcessInstanceVariablesMock extends BaseMock { } addPutProcessInstanceVariables200Response(processInstanceId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .put('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables') .reply(200, fakeVariablesList); } addPutProcessInstanceVariables500Response(processInstanceId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .put('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables') .reply(500, { messageKey: 'UNKNOWN', @@ -64,13 +64,13 @@ export class ProcessInstanceVariablesMock extends BaseMock { } addGetProcessInstanceVariable200Response(processInstanceId: string, variableName: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables/' + variableName) .reply(200, fakeVariable1); } addGetProcessInstanceVariable500Response(processInstanceId: string, variableName: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables/' + variableName) .reply(500, { messageKey: 'UNKNOWN', @@ -79,13 +79,13 @@ export class ProcessInstanceVariablesMock extends BaseMock { } addUpdateProcessInstanceVariable200Response(processInstanceId: string, variableName: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .put('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables/' + variableName) .reply(200, fakeVariable1); } addUpdateProcessInstanceVariable500Response(processInstanceId: string, variableName: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .put('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables/' + variableName) .reply(500, { messageKey: 'UNKNOWN', @@ -94,13 +94,13 @@ export class ProcessInstanceVariablesMock extends BaseMock { } addDeleteProcessInstanceVariable200Response(processInstanceId: string, variableName: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .delete('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables/' + variableName) .reply(200); } addDeleteProcessInstanceVariable500Response(processInstanceId: string, variableName: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .delete('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables/' + variableName) .reply(500, { messageKey: 'UNKNOWN', diff --git a/lib/js-api/test/mockObjects/process-services/process.mock.ts b/lib/js-api/test/mockObjects/process-services/process.mock.ts index 2206373db7..92663ba382 100644 --- a/lib/js-api/test/mockObjects/process-services/process.mock.ts +++ b/lib/js-api/test/mockObjects/process-services/process.mock.ts @@ -15,12 +15,11 @@ * limitations under the License. */ -import nock from 'nock'; import { BaseMock } from '../base.mock'; export class ProcessMock extends BaseMock { get200Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/activiti-app/api/enterprise/process-instances/query') .reply(200, { size: 2, @@ -82,7 +81,7 @@ export class ProcessMock extends BaseMock { } get200getProcessDefinitionStartForm(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/activiti-app/api/enterprise/process-definitions/testProcess%3A1%3A7504/start-form') .reply(200, { id: 2002, diff --git a/lib/js-api/test/mockObjects/process-services/profile.mock.ts b/lib/js-api/test/mockObjects/process-services/profile.mock.ts index bf5c65b2dc..f4330ee065 100644 --- a/lib/js-api/test/mockObjects/process-services/profile.mock.ts +++ b/lib/js-api/test/mockObjects/process-services/profile.mock.ts @@ -20,7 +20,7 @@ import { BaseMock } from '../base.mock'; export class ProfileMock extends BaseMock { get200getProfile(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/activiti-app/api/enterprise/profile') .reply(200, { id: 1, @@ -94,10 +94,10 @@ export class ProfileMock extends BaseMock { } get401getProfile(): void { - nock(this.host, { encodedQueryParams: true }).get('/activiti-app/api/enterprise/profile').reply(401); + this.createNockWithCors().get('/activiti-app/api/enterprise/profile').reply(401); } get200getProfilePicture(): void { - nock(this.host, { encodedQueryParams: true }).get('/activiti-app/api/enterprise/profile-picture').reply(200, 'BUFFERSIZE'); + this.createNockWithCors().get('/activiti-app/api/enterprise/profile-picture').reply(200, 'BUFFERSIZE'); } } diff --git a/lib/js-api/test/mockObjects/process-services/reports.mock.ts b/lib/js-api/test/mockObjects/process-services/reports.mock.ts index 31fe986ae3..c8c93f4d83 100644 --- a/lib/js-api/test/mockObjects/process-services/reports.mock.ts +++ b/lib/js-api/test/mockObjects/process-services/reports.mock.ts @@ -15,7 +15,6 @@ * limitations under the License. */ -import nock from 'nock'; import { BaseMock } from '../base.mock'; const fakeReportList = [ @@ -154,58 +153,56 @@ const fakeProcessDefinitionsNoApp: any[] = [ export class ReportsMock extends BaseMock { get200ResponseCreateDefaultReport(): void { - nock(this.host, { encodedQueryParams: true }).post('/activiti-app/app/rest/reporting/default-reports').reply(200); + this.createNockWithCors().post('/activiti-app/app/rest/reporting/default-reports').reply(200); } get200ResponseTasksByProcessDefinitionId(reportId: string, processDefinitionId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/activiti-app/app/rest/reporting/report-params/' + reportId + '/tasks') .query({ processDefinitionId }) .reply(200, ['Fake Task 1', 'Fake Task 2', 'Fake Task 3']); } get200ResponseReportList(): void { - nock(this.host, { encodedQueryParams: true }).get('/activiti-app/app/rest/reporting/reports').reply(200, fakeReportList); + this.createNockWithCors().get('/activiti-app/app/rest/reporting/reports').reply(200, fakeReportList); } get200ResponseReportParams(reportId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/activiti-app/app/rest/reporting/report-params/' + reportId) .reply(200, fakeReportParams); } get200ResponseReportsByParams(reportId: string, paramsQuery: { status: string }): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/activiti-app/app/rest/reporting/report-params/' + reportId, paramsQuery) .reply(200, fakeChartReports); } get200ResponseProcessDefinitions(): void { - nock(this.host, { encodedQueryParams: true }) - .get('/activiti-app/app/rest/reporting/process-definitions') - .reply(200, fakeProcessDefinitionsNoApp); + this.createNockWithCors().get('/activiti-app/app/rest/reporting/process-definitions').reply(200, fakeProcessDefinitionsNoApp); } get200ResponseUpdateReport(reportId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .put('/activiti-app/app/rest/reporting/reports/' + reportId) .reply(200); } get200ResponseExportReport(reportId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/activiti-app/app/rest/reporting/reports/' + reportId + '/export-to-csv') .reply(200, 'CSV'); } get200ResponseSaveReport(reportId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/activiti-app/app/rest/reporting/reports/' + reportId) .reply(200); } get200ResponseDeleteReport(reportId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .delete('/activiti-app/app/rest/reporting/reports/' + reportId) .reply(200); } diff --git a/lib/js-api/test/mockObjects/process-services/task-form.mock.ts b/lib/js-api/test/mockObjects/process-services/task-form.mock.ts index 097802630a..d563221aed 100644 --- a/lib/js-api/test/mockObjects/process-services/task-form.mock.ts +++ b/lib/js-api/test/mockObjects/process-services/task-form.mock.ts @@ -15,12 +15,11 @@ * limitations under the License. */ -import nock from 'nock'; import { BaseMock } from '../base.mock'; export class TaskFormMock extends BaseMock { get200getTaskFormVariables(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/activiti-app/api/enterprise/task-forms/5028/variables') .reply( 200, diff --git a/lib/js-api/test/mockObjects/process-services/tasks.mock.ts b/lib/js-api/test/mockObjects/process-services/tasks.mock.ts index dcb332fc06..57f1691182 100644 --- a/lib/js-api/test/mockObjects/process-services/tasks.mock.ts +++ b/lib/js-api/test/mockObjects/process-services/tasks.mock.ts @@ -15,7 +15,6 @@ * limitations under the License. */ -import nock from 'nock'; import { BaseMock } from '../base.mock'; const formValues = [ @@ -42,7 +41,7 @@ const formValues = [ export class TasksMock extends BaseMock { get200Response(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/activiti-app/api/enterprise/tasks/query', {}) .reply(200, { size: 2, @@ -128,7 +127,7 @@ export class TasksMock extends BaseMock { } get200ResponseGetTask(taskId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/activiti-app/api/enterprise/tasks/' + taskId) .reply(200, { id: '10', @@ -166,14 +165,14 @@ export class TasksMock extends BaseMock { } get400TaskFilter(): void { - nock(this.host, { encodedQueryParams: true }).post('/activiti-app/api/enterprise/tasks/filter', {}).reply(400, { + this.createNockWithCors().post('/activiti-app/api/enterprise/tasks/filter', {}).reply(400, { message: 'A valid filterId or filter params must be provided', messageKey: 'GENERAL.ERROR.BAD-REQUEST' }); } get200TaskFilter(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .post('/activiti-app/api/enterprise/tasks/filter', { appDefinitionId: 1 }) .reply(200, { size: 2, @@ -249,7 +248,7 @@ export class TasksMock extends BaseMock { } get404CompleteTask(taskId: string): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .put('/activiti-app/api/enterprise/tasks/' + taskId + '/action/complete') .reply(404, { message: 'Task with id: ' + taskId + ' does not exist', @@ -258,7 +257,7 @@ export class TasksMock extends BaseMock { } get200CreateTask(name: string): void { - nock(this.host, { encodedQueryParams: true }).post('/activiti-app/api/enterprise/tasks', { name }).reply(200, { + this.createNockWithCors().post('/activiti-app/api/enterprise/tasks', { name }).reply(200, { id: '10001', name: 'test-name', description: null, @@ -293,7 +292,7 @@ export class TasksMock extends BaseMock { } get200getTaskForm(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/activiti-app/api/enterprise/task-forms/2518') .reply(200, { id: 1, @@ -1033,14 +1032,10 @@ export class TasksMock extends BaseMock { } get200getRestFieldValuesColumn(): void { - nock(this.host, { encodedQueryParams: true }) - .get('/activiti-app/api/enterprise/task-forms/1/form-values/label/user') - .reply(200, formValues); + this.createNockWithCors().get('/activiti-app/api/enterprise/task-forms/1/form-values/label/user').reply(200, formValues); } get200getRestFieldValues(): void { - nock(this.host, { encodedQueryParams: true }) - .get('/activiti-app/api/enterprise/task-forms/2/form-values/label') - .reply(200, formValues); + this.createNockWithCors().get('/activiti-app/api/enterprise/task-forms/2/form-values/label').reply(200, formValues); } } diff --git a/lib/js-api/test/mockObjects/process-services/user-filters.mock.ts b/lib/js-api/test/mockObjects/process-services/user-filters.mock.ts index 9f4d0f5d57..a7a78e7cde 100644 --- a/lib/js-api/test/mockObjects/process-services/user-filters.mock.ts +++ b/lib/js-api/test/mockObjects/process-services/user-filters.mock.ts @@ -15,12 +15,11 @@ * limitations under the License. */ -import nock from 'nock'; import { BaseMock } from '../base.mock'; export class UserFiltersMock extends BaseMock { get200getUserTaskFilters(): void { - nock(this.host, { encodedQueryParams: true }) + this.createNockWithCors() .get('/activiti-app/api/enterprise/filters/tasks') .query({ appId: '1' }) .reply(200, { diff --git a/lib/js-api/test/process-services/modelApi.spec.ts b/lib/js-api/test/process-services/modelApi.spec.ts index 8a4f902b5a..e21a025840 100644 --- a/lib/js-api/test/process-services/modelApi.spec.ts +++ b/lib/js-api/test/process-services/modelApi.spec.ts @@ -18,6 +18,7 @@ import assert from 'assert'; import { AlfrescoApi, ModelsApi } from '../../src'; import { BpmAuthMock, ModelsMock } from '../mockObjects'; +import nock from 'nock'; describe('Activiti Models Api', () => { let authResponseBpmMock: BpmAuthMock; @@ -25,6 +26,7 @@ describe('Activiti Models Api', () => { let modelsApi: ModelsApi; beforeEach(async () => { + nock.cleanAll(); const hostBpm = 'https://127.0.0.1:9999'; authResponseBpmMock = new BpmAuthMock(hostBpm); diff --git a/lib/js-api/test/upload.spec.ts b/lib/js-api/test/upload.spec.ts index 36d8c3e649..0cda65dd06 100644 --- a/lib/js-api/test/upload.spec.ts +++ b/lib/js-api/test/upload.spec.ts @@ -56,15 +56,16 @@ describe('Upload', () => { assert.equal(data.entry.name, 'testFile.txt'); }); - it('upload file should get 409 if new name clashes with an existing file in the current parent folder', (done) => { + it('upload file should get 409 if new name clashes with an existing file in the current parent folder', async () => { uploadMock.get409CreationFileNewNameClashes(); const file = createTestFileStream('testFile.txt'); - - uploadApi.uploadFile(file).catch((error: any) => { + try { + await uploadApi.uploadFile(file); + assert.fail('Expected an error to be thrown'); + } catch (error) { assert.equal(error.status, 409); - done(); - }); + } }); it('upload file should get 200 and rename if the new name clashes with an existing file in the current parent folder and autorename is true', async () => {