From fdebc53a48cb5259917e9f793afbe66a42018f21 Mon Sep 17 00:00:00 2001 From: Arun Ganeshan Date: Wed, 17 Apr 2024 12:59:05 -0400 Subject: [PATCH] fix: add server for mocha test (#3) --- .../integration/spec/services/services.js | 61 ++++++++++--------- .../test/integration/spec/webex-core.js | 6 +- packages/legacy/tools/src/utils/index.ts | 2 +- .../legacy/tools/src/utils/karma/karma.ts | 2 +- .../legacy/tools/src/utils/mocha/mocha.ts | 5 +- .../tools/src/utils/{karma => }/server.ts | 0 6 files changed, 40 insertions(+), 36 deletions(-) rename packages/legacy/tools/src/utils/{karma => }/server.ts (100%) diff --git a/packages/@webex/webex-core/test/integration/spec/services/services.js b/packages/@webex/webex-core/test/integration/spec/services/services.js index dda3e7ced70..1e653d8fe52 100644 --- a/packages/@webex/webex-core/test/integration/spec/services/services.js +++ b/packages/@webex/webex-core/test/integration/spec/services/services.js @@ -42,21 +42,22 @@ describe('webex-core', () => { }) ); - beforeEach('create webex instance', async () => { + beforeEach('create webex instance', () => { webex = new WebexCore({credentials: {supertoken: webexUser.token}}); webexEU = new WebexCore({credentials: {supertoken: webexUserEU.token}}); services = webex.internal.services; servicesEU = webexEU.internal.services; catalog = services._getCatalog(); - await Promise.all([ + return Promise.all([ services.waitForCatalog('postauth', 10), servicesEU.waitForCatalog('postauth', 10), - ]); - await services.updateServices({ - from: 'limited', - query: {userId: webexUser.id}, - }) + ]).then(() => + services.updateServices({ + from: 'limited', + query: {userId: webexUser.id}, + }) + ); }); describe('#_getCatalog()', () => { @@ -86,14 +87,14 @@ describe('webex-core', () => { let testUrlTemplate; let testUrl; - beforeEach('load test url', async () => { + beforeEach('load test url', () => { testUrlTemplate = { defaultUrl: 'https://www.example.com/api/v1', hosts: [], name: 'exampleValid', }; testUrl = new ServiceUrl(testUrlTemplate); - await catalog._loadServiceUrls('preauth', [testUrl]); + catalog._loadServiceUrls('preauth', [testUrl]); }); afterEach('unload test url', () => { @@ -531,7 +532,7 @@ describe('webex-core', () => { let testUrl; let testUrlTemplate; - beforeEach('load test url', async () => { + beforeEach('load test url', () => { testUrlTemplate = { defaultUrl: 'https://www.example.com/api/v1', hosts: [ @@ -552,7 +553,7 @@ describe('webex-core', () => { name: 'exampleValid', }; testUrl = new ServiceUrl(testUrlTemplate); - await catalog._loadServiceUrls('preauth', [testUrl]); + catalog._loadServiceUrls('preauth', [testUrl]); }); it('converts the url to a priority host url', () => { @@ -733,15 +734,18 @@ describe('webex-core', () => { done(); }); }); - it('updates the limited catalog when query param mode is provided', async () => { + it('updates the limited catalog when query param mode is provided', (done) => { catalog.serviceGroups.preauth = []; - await services + services .updateServices({ from: 'limited', query: {mode: 'DEFAULT_BY_PROXIMITY'}, + }) + .then(() => { + assert.isAbove(catalog.serviceGroups.preauth.length, 0); + done(); }); - assert.isAbove(catalog.serviceGroups.preauth.length, 0); }); it('does not update the limited catalog when nothing is provided', () => { catalog.serviceGroups.preauth = []; @@ -789,12 +793,11 @@ describe('webex-core', () => { }); describe('#fetchClientRegionInfo()', () => { - it('returns client region info', async () => { + it('returns client region info', () => services.fetchClientRegionInfo().then((r) => { assert.isDefined(r.countryCode); assert.isDefined(r.timezone); - }) - }); + })); }); describe('#validateUser()', () => { @@ -867,21 +870,21 @@ describe('webex-core', () => { assert.equal(Object.keys(unauthServices.list(false, 'postauth')).length, 0); })); - it('validates new user with activationOptions suppressEmail false', async () => { - const r = await unauthServices + it('validates new user with activationOptions suppressEmail false', () => + unauthServices .validateUser({ email: `Collabctg+webex-js-sdk-${uuid.v4()}@gmail.com`, activationOptions: {suppressEmail: false}, - }); - - assert.hasAllKeys(r, ['activated', 'exists', 'user', 'details']); - assert.equal(r.activated, false); - assert.equal(r.exists, false); - assert.equal(r.user.verificationEmailTriggered, true); - assert.isAbove(Object.keys(unauthServices.list(false, 'preauth')).length, 0); - assert.equal(Object.keys(unauthServices.list(false, 'signin')).length, 0); - assert.equal(Object.keys(unauthServices.list(false, 'postauth')).length, 0); - }); + }) + .then((r) => { + assert.hasAllKeys(r, ['activated', 'exists', 'user', 'details']); + assert.equal(r.activated, false); + assert.equal(r.exists, false); + assert.equal(r.user.verificationEmailTriggered, true); + assert.isAbove(Object.keys(unauthServices.list(false, 'preauth')).length, 0); + assert.equal(Object.keys(unauthServices.list(false, 'signin')).length, 0); + assert.equal(Object.keys(unauthServices.list(false, 'postauth')).length, 0); + })); it('validates new user with activationOptions suppressEmail true', () => unauthServices diff --git a/packages/@webex/webex-core/test/integration/spec/webex-core.js b/packages/@webex/webex-core/test/integration/spec/webex-core.js index ce8f5350874..fe53651b10b 100644 --- a/packages/@webex/webex-core/test/integration/spec/webex-core.js +++ b/packages/@webex/webex-core/test/integration/spec/webex-core.js @@ -17,7 +17,7 @@ describe('webex-core', function () { webex = new WebexCore(); }); - it.skip('adds a tracking id to each request', () => + it('adds a tracking id to each request', () => webex .request({ uri: makeLocalUrl('/'), @@ -35,7 +35,7 @@ describe('webex-core', function () { ); })); - it.skip('adds a spark-user-agent id to each request', () => + it('adds a spark-user-agent id to each request', () => webex .request({ uri: makeLocalUrl('/'), @@ -47,7 +47,7 @@ describe('webex-core', function () { assert.property(res.options.headers, 'spark-user-agent'); })); - it.skip('fails with a WebexHttpError', () => + it('fails with a WebexHttpError', () => assert .isRejected( webex.request({ diff --git a/packages/legacy/tools/src/utils/index.ts b/packages/legacy/tools/src/utils/index.ts index d6935459381..50af41f511d 100644 --- a/packages/legacy/tools/src/utils/index.ts +++ b/packages/legacy/tools/src/utils/index.ts @@ -3,7 +3,7 @@ import Karma from './karma'; import { startServer, stopServer, -} from './karma/server'; +} from './server'; import Mocha from './mocha'; export { diff --git a/packages/legacy/tools/src/utils/karma/karma.ts b/packages/legacy/tools/src/utils/karma/karma.ts index 7411db851ca..e703a19d6a7 100644 --- a/packages/legacy/tools/src/utils/karma/karma.ts +++ b/packages/legacy/tools/src/utils/karma/karma.ts @@ -2,7 +2,7 @@ import '@babel/register'; import '@webex/env-config-legacy'; import KarmaRunner from 'karma'; -import { startServer, stopServer } from './server'; +import { startServer, stopServer } from '../server'; import Browsers from './browsers'; diff --git a/packages/legacy/tools/src/utils/mocha/mocha.ts b/packages/legacy/tools/src/utils/mocha/mocha.ts index c17c2bc7732..b09e79bc130 100644 --- a/packages/legacy/tools/src/utils/mocha/mocha.ts +++ b/packages/legacy/tools/src/utils/mocha/mocha.ts @@ -1,7 +1,7 @@ import Babel from '@babel/register'; import '@webex/env-config-legacy'; - import MochaRunner from 'mocha'; +import { startServer, stopServer } from '../server'; import CONSTANTS from './mocha.constants'; @@ -31,11 +31,12 @@ class Mocha { files.forEach((file) => mochaRunner.addFile(file)); return new Promise((resolve) => { + startServer(); mochaRunner.run((failures) => { if (failures !== 0) { process.exit(1); } - + stopServer(); resolve(undefined); }); }); diff --git a/packages/legacy/tools/src/utils/karma/server.ts b/packages/legacy/tools/src/utils/server.ts similarity index 100% rename from packages/legacy/tools/src/utils/karma/server.ts rename to packages/legacy/tools/src/utils/server.ts