|
15 | 15 | */ |
16 | 16 | import * as os from 'node:os'; |
17 | 17 | import { ConfigAggregator, Logger } from '@salesforce/core'; |
| 18 | +import { O11yService } from '@salesforce/o11y-reporter'; |
18 | 19 | import got from 'got'; |
19 | 20 | import { expect } from 'chai'; |
20 | 21 | import * as sinon from 'sinon'; |
21 | 22 | import { AppInsights } from '../../src/appInsights'; |
| 23 | +import { O11yReporter } from '../../src/o11yReporter'; |
22 | 24 | import { TelemetryReporter } from '../../src/telemetryReporter'; |
| 25 | +import type { PdpEvent } from '../../src/types'; |
23 | 26 | import * as enabledStubs from '../../src/enabledCheck'; |
24 | 27 |
|
25 | 28 | describe('TelemetryReporter', () => { |
@@ -48,6 +51,43 @@ describe('TelemetryReporter', () => { |
48 | 51 | expect(sendStub.calledOnce).to.be.true; |
49 | 52 | }); |
50 | 53 |
|
| 54 | + it('should send PDPEvent', async () => { |
| 55 | + sandbox.stub(ConfigAggregator.prototype, 'getPropertyValue').returns('false'); |
| 56 | + |
| 57 | + const mockO11yService = { |
| 58 | + initialize: sandbox.stub().resolves(), |
| 59 | + logEvent: sandbox.stub(), |
| 60 | + logEventWithSchema: sandbox.stub(), |
| 61 | + forceFlush: sandbox.stub().resolves(), |
| 62 | + enableAutoBatching: sandbox.stub().returns(() => {}), |
| 63 | + }; |
| 64 | + sandbox.stub(O11yService, 'getInstance').returns(mockO11yService as unknown as O11yService); |
| 65 | + |
| 66 | + const sendPdpEventStub = sandbox.stub(O11yReporter.prototype, 'sendPdpEvent').resolves(); |
| 67 | + |
| 68 | + const reporter = await TelemetryReporter.create({ |
| 69 | + project: 'salesforce-cli', |
| 70 | + key: 'not-used', |
| 71 | + userId: 'test-user-id-for-pft-testing', |
| 72 | + waitForConnection: true, |
| 73 | + enableO11y: true, |
| 74 | + enableAppInsights: false, |
| 75 | + o11yUploadEndpoint: 'https://794testsite.my.site.com/byolwr/webruntime/log/metrics', |
| 76 | + }); |
| 77 | + |
| 78 | + const pdpEvent: PdpEvent = { |
| 79 | + eventName: 'salesforceCli.executed', |
| 80 | + productFeatureId: 'aJCEE0000000mHP4AY', |
| 81 | + componentId: '@salesforce/plugin-auth.org:web:login', |
| 82 | + contextName: 'orgId::devhubId', |
| 83 | + contextValue: '00Ded000000VsTxEAK::00D460000019MkyEAE', |
| 84 | + }; |
| 85 | + reporter.sendPdpEvent(pdpEvent); |
| 86 | + |
| 87 | + expect(sendPdpEventStub.calledOnce).to.be.true; |
| 88 | + expect(sendPdpEventStub.firstCall.args[0]).to.deep.equal(pdpEvent); |
| 89 | + }); |
| 90 | + |
51 | 91 | it('should send a telemetry exception', async () => { |
52 | 92 | const options = { project, key }; |
53 | 93 | sandbox.stub(ConfigAggregator.prototype, 'getPropertyValue').returns('false'); |
|
0 commit comments