Skip to content

Commit

Permalink
fix: add server for mocha test (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
arun3528 authored and sreenara committed Apr 18, 2024
1 parent 96b207c commit fdebc53
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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: [
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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()', () => {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('/'),
Expand All @@ -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('/'),
Expand All @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion packages/legacy/tools/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Karma from './karma';
import {
startServer,
stopServer,
} from './karma/server';
} from './server';
import Mocha from './mocha';

export {
Expand Down
2 changes: 1 addition & 1 deletion packages/legacy/tools/src/utils/karma/karma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
5 changes: 3 additions & 2 deletions packages/legacy/tools/src/utils/mocha/mocha.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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);
});
});
Expand Down
File renamed without changes.

0 comments on commit fdebc53

Please sign in to comment.