From 7c6e9ab831686cecbfa48fa90395c737f89d105f Mon Sep 17 00:00:00 2001 From: VitoAlbano Date: Thu, 14 Nov 2024 23:34:18 +0000 Subject: [PATCH] [MIGRATION] - Fixing failing migrated tests --- lib/js-api/test/auth.spec.ts | 32 ++++++-------- lib/js-api/test/bpmAuth.spec.ts | 8 ++-- .../test/content-services/tagApi.spec.ts | 2 +- lib/js-api/tsconfig.spec.json | 2 +- package-lock.json | 43 +++++++++++++++++++ package.json | 1 + 6 files changed, 61 insertions(+), 27 deletions(-) diff --git a/lib/js-api/test/auth.spec.ts b/lib/js-api/test/auth.spec.ts index fdf5f7a7be..ef833d5f75 100644 --- a/lib/js-api/test/auth.spec.ts +++ b/lib/js-api/test/auth.spec.ts @@ -52,46 +52,38 @@ describe('Auth', () => { }); describe('login', () => { - it('should return the Ticket if all is ok', (done) => { + it('should return the Ticket if all is ok', async () => { authResponseEcmMock.get201Response(); - alfrescoJsApi.login('admin', 'admin').then((data: string) => { - assert.equal(data, 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'); - done(); - }); + const data = await alfrescoJsApi.login('admin', 'admin'); + 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) => { - assert.equal(error.status, 403); - done(); - }); + const error = await alfrescoJsApi.login('wrong', 'name'); + assert.equal(error.status, 403); }); }); describe('isLoggedIn', () => { - it('should return true if the api is logged in', (done) => { + it('should return true if the api is logged in', async () => { authResponseEcmMock.get201Response(); - alfrescoJsApi.login('admin', 'admin').then(() => { - assert.equal(alfrescoJsApi.isLoggedIn(), true); - done(); - }); + 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 () => { authResponseEcmMock.get201Response(); alfrescoJsApi.login('admin', 'admin').catch(NOOP); authResponseEcmMock.get204ResponseLogout(); - alfrescoJsApi.logout().then(() => { - assert.equal(alfrescoJsApi.isLoggedIn(), false); - done(); - }); + await alfrescoJsApi.logout(); + assert.equal(alfrescoJsApi.isLoggedIn(), false); }); }); diff --git a/lib/js-api/test/bpmAuth.spec.ts b/lib/js-api/test/bpmAuth.spec.ts index d8aa5e2a99..a4f6196cb2 100644 --- a/lib/js-api/test/bpmAuth.spec.ts +++ b/lib/js-api/test/bpmAuth.spec.ts @@ -55,7 +55,7 @@ describe('Bpm Auth test', () => { }); describe('With Authentication', () => { - it('login should return the Ticket if all is ok', (done) => { + it('login should return the Ticket if all is ok', async () => { authBpmMock.get200Response(); const processAuth = new ProcessAuth({ @@ -63,10 +63,8 @@ describe('Bpm Auth test', () => { contextRootBpm: 'activiti-app' }); - processAuth.login('admin', 'admin').then((data) => { - assert.equal(data, 'Basic YWRtaW46YWRtaW4='); - done(); - }); + const data = await processAuth.login('admin', 'admin'); + assert.equal(data, 'Basic YWRtaW46YWRtaW4='); }); it('login password should be removed after login', (done) => { diff --git a/lib/js-api/test/content-services/tagApi.spec.ts b/lib/js-api/test/content-services/tagApi.spec.ts index 84adbf2cf5..3d4fe9a98d 100644 --- a/lib/js-api/test/content-services/tagApi.spec.ts +++ b/lib/js-api/test/content-services/tagApi.spec.ts @@ -103,7 +103,7 @@ describe('Tags', () => { }); describe('createTags', () => { - it('should return created tags', (done: Mocha.Done) => { + it('should return created tags', (done) => { tagMock.createTags201Response(); tagsApi.createTags([new TagBody(), new TagBody()]).then((tags) => { assert.equal(tags.length, 2); diff --git a/lib/js-api/tsconfig.spec.json b/lib/js-api/tsconfig.spec.json index 1bd94344e0..81c8fb16bd 100644 --- a/lib/js-api/tsconfig.spec.json +++ b/lib/js-api/tsconfig.spec.json @@ -8,7 +8,7 @@ "isolatedModules": true, "allowSyntheticDefaultImports": true, "lib": ["ESNext", "dom"], - "types": ["mocha"] + "types": ["jest", "node"] }, "exclude": [], "include": ["**/*"] diff --git a/package-lock.json b/package-lock.json index 59c70b5194..2bd9345a7c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -87,6 +87,7 @@ "@types/event-emitter": "^0.3.3", "@types/jasmine": "4.0.3", "@types/jasminewd2": "~2.0.2", + "@types/jest": "^29.5.14", "@types/jsdom": "^21.1.5", "@types/minimatch": "^3.0.3", "@types/mocha": "^10.0.6", @@ -17394,6 +17395,48 @@ "@types/jasmine": "*" } }, + "node_modules/@types/jest": { + "version": "29.5.14", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.14.tgz", + "integrity": "sha512-ZN+4sdnLUbo8EVvVc2ao0GFW6oVrQRPn4K2lglySj7APvSrgzxHiNNK99us4WDMi57xxA2yggblIAMNhXOotLQ==", + "dev": true, + "dependencies": { + "expect": "^29.0.0", + "pretty-format": "^29.0.0" + } + }, + "node_modules/@types/jest/node_modules/ansi-styles": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz", + "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/@types/jest/node_modules/pretty-format": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", + "integrity": "sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==", + "dev": true, + "dependencies": { + "@jest/schemas": "^29.6.3", + "ansi-styles": "^5.0.0", + "react-is": "^18.0.0" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/@types/jest/node_modules/react-is": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz", + "integrity": "sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==", + "dev": true + }, "node_modules/@types/jsdom": { "version": "21.1.7", "dev": true, diff --git a/package.json b/package.json index c4fd080338..502a07675d 100644 --- a/package.json +++ b/package.json @@ -107,6 +107,7 @@ "@types/event-emitter": "^0.3.3", "@types/jasmine": "4.0.3", "@types/jasminewd2": "~2.0.2", + "@types/jest": "^29.5.14", "@types/jsdom": "^21.1.5", "@types/minimatch": "^3.0.3", "@types/mocha": "^10.0.6",