Skip to content

Commit

Permalink
fix: revert-changes-made-for-jest-and-comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ShreyasSharma28 committed Apr 19, 2024
1 parent 5d9ed69 commit d763cb2
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 153 deletions.
48 changes: 0 additions & 48 deletions packages/@webex/helper-image/src/orient.js

This file was deleted.

99 changes: 8 additions & 91 deletions packages/@webex/internal-plugin-mercury/test/unit/spec/mercury.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ describe('plugin-mercury', () => {
});

describe('when `maxRetries` is set', () => {

const check = () => {
socketOpenStub.restore();
socketOpenStub = sinon.stub(Socket.prototype, 'open');
Expand Down Expand Up @@ -745,99 +744,17 @@ describe('plugin-mercury', () => {
.then((wsUrl) => assert.match(wsUrl, /multipleConnections/)));
});
});
});
describe('ping pong latency event is forwarded', () => {
let clock, mercury, mockWebSocket, socketOpenStub, webex;

const statusStartTypingMessage = JSON.stringify({
id: uuid.v4(),
data: {
eventType: 'status.start_typing',
actor: {
id: 'actorId',
},
conversationId: uuid.v4(),
},
timestamp: Date.now(),
trackingId: `suffix_${uuid.v4()}_${Date.now()}`,
});

beforeEach(() => {
clock = FakeTimers.install({now: Date.now()});
});

afterEach(() => {
clock.uninstall();
});

beforeEach(() => {
webex = new MockWebex({
children: {
mercury: Mercury,
},
});
webex.credentials = {
refresh: sinon.stub().returns(Promise.resolve()),
getUserToken: sinon.stub().returns(
Promise.resolve({
toString() {
return 'Bearer FAKE';
},
})
),
};
webex.internal.device = {
register: sinon.stub().returns(Promise.resolve()),
refresh: sinon.stub().returns(Promise.resolve()),
webSocketUrl: 'ws://example.com',
getWebSocketUrl: sinon.stub().returns(Promise.resolve('ws://example-2.com')),
useServiceCatalogUrl: sinon
.stub()
.returns(Promise.resolve('https://service-catalog-url.com')),
};
webex.internal.services = {
convertUrlToPriorityHostUrl: sinon.stub().returns(Promise.resolve('ws://example-2.com')),
markFailedUrl: sinon.stub().returns(Promise.resolve()),
};
webex.internal.metrics.submitClientMetrics = sinon.stub();
webex.trackingId = 'fakeTrackingId';
webex.config.mercury = mercuryConfig.mercury;

webex.logger = console;

mockWebSocket = new MockWebSocket();
sinon.stub(Socket, 'getWebSocketConstructor').returns(() => mockWebSocket);

const origOpen = Socket.prototype.open;

socketOpenStub = sinon.stub(Socket.prototype, 'open').callsFake(function (...args) {
const promise = Reflect.apply(origOpen, this, args);

process.nextTick(() => mockWebSocket.open());

return promise;
});

mercury = webex.internal.mercury;
});

afterEach(() => {
if (socketOpenStub) {
socketOpenStub.restore();
}

if (Socket.getWebSocketConstructor.restore) {
Socket.getWebSocketConstructor.restore();
}
});
it('should forward ping pong latency event', () => {
const spy = sinon.spy();
describe('ping pong latency event is forwarded', () => {
it('should forward ping pong latency event', () => {
const spy = sinon.spy();

mercury.on('ping-pong-latency', spy);
mercury.on('ping-pong-latency', spy);

return mercury.connect().then(() => {
assert.calledWith(spy, 0);
assert.calledOnce(spy);
return mercury.connect().then(() => {
assert.calledWith(spy, 0);
assert.calledOnce(spy);
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ export default class CallDiagnosticMetrics extends StatelessWebexPlugin {
return this.getErrorPayloadForClientErrorCode({
clientErrorCode: UNKNOWN_ERROR,
serviceErrorCode: UNKNOWN_ERROR,
payloadOverrides: rawError.payloadOverrides,
rawErrorMessage,
httpStatusCode,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,9 @@ describe('plugin-metrics', () => {
});
});

//TODO: The following two skipped tests needs investigation: https://jira-eng-gpk2.cisco.com/jira/browse/SPARK-485382
//TODO: The following two skipped tests are failling when run using jest, needs investigation: https://jira-eng-gpk2.cisco.com/jira/browse/SPARK-485382
describe('when the request fails', () => {
it.skip('does not clear the queue', async () => {
it('does not clear the queue', async () => {
// avoid setting .sent timestamp
webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.prepareRequest =
(q) => Promise.resolve(q);
Expand Down Expand Up @@ -410,7 +410,7 @@ describe('plugin-metrics', () => {
});

describe('prepareItem', () => {
it.skip('calls prepareDiagnosticMetricItem correctly', async () => {
it('calls prepareDiagnosticMetricItem correctly', async () => {
// avoid setting .sent timestamp
webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.prepareRequest =
(q) => Promise.resolve(q);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ describe('internal-plugin-metrics', () => {
]);
});

it('should submit client event successfully with correlationId, webexConferenceIdStr and globalMeetingId', async () => {
it('should submit client event successfully with correlationId, webexConferenceIdStr and globalMeetingId', () => {
const prepareDiagnosticEventSpy = sinon.spy(cd, 'prepareDiagnosticEvent');
const submitToCallDiagnosticsSpy = sinon.spy(cd, 'submitToCallDiagnostics');
const generateClientEventErrorPayloadSpy = sinon.spy(cd, 'generateClientEventErrorPayload');
Expand Down Expand Up @@ -1807,6 +1807,27 @@ describe('internal-plugin-metrics', () => {
});
});

it('should override custom properties for an unknown error', () => {
const error = new Error('bad times');

(error as any).payloadOverrides = {
shownToUser: true,
category: 'expected',
};

const res = cd.generateClientEventErrorPayload(error);
assert.deepEqual(res, {
category: 'expected',
errorDescription: 'UnknownError',
fatal: true,
name: 'other',
shownToUser: true,
serviceErrorCode: 9999,
errorCode: 9999,
rawErrorMessage: 'bad times',
});
});

it('should override custom properties for a NetworkOrCORSError', () => {
const error = new WebexHttpError.NetworkOrCORSError({
url: 'https://example.com',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import PresenceWorker from '../../../src/presence-worker';

const round = (time) => Math.floor(time / 1000);

// Skipping as we have registered it as public plugin and MockWebex will create presence under webex object directly instead of webex.internal
describe.skip('presence-worker', () => {
describe('presence-worker', () => {
describe('PresenceWorker', () => {
let webex;
let worker;
const id = '1234';

beforeEach(() => {
console.log(process.env.WEBEX_CLIENT_ID);
webex = new MockWebex({
children: {
mercury: Mercury,
Expand All @@ -28,10 +26,31 @@ describe.skip('presence-worker', () => {
});

describe('#initialize()', () => {
it('requires webex', () =>
expect(() => worker.initialize()).toThrow(/Must initialize Presence Worker with webex!/));
it('requires webex internal', () =>
expect(() => worker.initialize({})).toThrow(/Must initialize Presence Worker with webex!/));
it('requires webex', () =>{
let err=null
try{
worker.initialize()
}
catch(e){
err=e
}
assert.equal(err?.message, 'Must initialize Presence Worker with webex!');

});


it('requires webex internal', () =>{
let err=null
try{
worker.initialize({})
}
catch(e){
err=e
}
assert.equal(err?.message, 'Must initialize Presence Worker with webex!');

});

});

// This selection of tests fail due to `webex-core`'s batcher config being missing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import sinon from 'sinon';
import Presence from '@webex/internal-plugin-presence';
import MockWebex from '@webex/test-helper-mock-webex';

// Skipping as we have registered it as public plugin and MockWebex will create presence under webex object directly instead of webex.internal
describe.skip('plugin-presence', () => {
describe('plugin-presence', () => {
describe('Presence', () => {
let webex;

Expand Down
1 change: 0 additions & 1 deletion packages/@webex/test-helper-mock-webex/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const nonInternalPlugins = [
'teams',
'teamMemberships',
'webhooks',
'presence',
];

/**
Expand Down

0 comments on commit d763cb2

Please sign in to comment.