Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(metrics): revert jest changes for metrics and mercury plugins #3547

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -745,99 +745,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 @@ -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
Copy link
Contributor Author

@Shreyas281299 Shreyas281299 Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed it.

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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ describe.skip('presence-worker', () => {
const id = '1234';

beforeEach(() => {
console.log(process.env.WEBEX_CLIENT_ID);
webex = new MockWebex({
children: {
mercury: Mercury,
Expand All @@ -28,10 +27,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
Loading